Skip to content

Commit a4c694b

Browse files
joannekoongaxboe
authored andcommitted
io_uring/kbuf: use WRITE_ONCE() for userspace-shared buffer ring fields
buf->addr and buf->len reside in memory shared with userspace. They should be written with WRITE_ONCE() to guarantee atomic stores and prevent tearing or other unsafe compiler optimizations. Signed-off-by: Joanne Koong <[email protected]> Cc: Caleb Sander Mateos <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 78385c7 commit a4c694b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

io_uring/kbuf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len)
4444
buf_len -= this_len;
4545
/* Stop looping for invalid buffer length of 0 */
4646
if (buf_len || !this_len) {
47-
buf->addr = READ_ONCE(buf->addr) + this_len;
48-
buf->len = buf_len;
47+
WRITE_ONCE(buf->addr, READ_ONCE(buf->addr) + this_len);
48+
WRITE_ONCE(buf->len, buf_len);
4949
return false;
5050
}
51-
buf->len = 0;
51+
WRITE_ONCE(buf->len, 0);
5252
bl->head++;
5353
len -= this_len;
5454
}
@@ -291,7 +291,7 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
291291
arg->partial_map = 1;
292292
if (iov != arg->iovs)
293293
break;
294-
buf->len = len;
294+
WRITE_ONCE(buf->len, len);
295295
}
296296
}
297297

0 commit comments

Comments
 (0)