diff options
| author | Stefan Bühler <source@stbuehler.de> | 2019-04-19 05:57:44 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2019-04-22 13:00:55 -0400 |
| commit | e523a29c4f2703bdb98f68ce1bb256e259fd8d5f (patch) | |
| tree | 0ba64403279546f48c7a7839c935ddbc110fa7df | |
| parent | 35fa71a030caa50458a043560d4814ea9bcd639f (diff) | |
io_uring: fix race condition reading SQ entries
A read memory barrier is required between reading SQ tail and reading
the actual data belonging to the SQ entry.
Userspace needs a matching write barrier between writing SQ entries and
updating SQ tail (using smp_store_release to update tail will do).
Signed-off-by: Stefan Bühler <source@stbuehler.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
| -rw-r--r-- | fs/io_uring.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c index a2f39faed6a7..41e3a6f6a096 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c | |||
| @@ -1739,7 +1739,8 @@ static bool io_get_sqring(struct io_ring_ctx *ctx, struct sqe_submit *s) | |||
| 1739 | head = ctx->cached_sq_head; | 1739 | head = ctx->cached_sq_head; |
| 1740 | /* See comment at the top of this file */ | 1740 | /* See comment at the top of this file */ |
| 1741 | smp_rmb(); | 1741 | smp_rmb(); |
| 1742 | if (head == READ_ONCE(ring->r.tail)) | 1742 | /* make sure SQ entry isn't read before tail */ |
| 1743 | if (head == smp_load_acquire(&ring->r.tail)) | ||
| 1743 | return false; | 1744 | return false; |
| 1744 | 1745 | ||
| 1745 | head = READ_ONCE(ring->array[head & ctx->sq_mask]); | 1746 | head = READ_ONCE(ring->array[head & ctx->sq_mask]); |
