From: Stefan Bühler source@stbuehler.de
mainline inclusion from mainline-5.1-rc7 commit e523a29c4f2703bdb98f68ce1bb256e259fd8d5f category: feature bugzilla: https://bugzilla.openeuler.org/show_bug.cgi?id=27 CVE: NA ---------------------------
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 Signed-off-by: Zhihao Cheng chengzhihao1@huawei.com Signed-off-by: yangerkun yangerkun@huawei.com Reviewed-by: zhangyi (F) yi.zhang@huawei.com Signed-off-by: Cheng Jian cj.chengjian@huawei.com --- fs/io_uring.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c index 6b13efe414bc..9507ef2b399e 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1736,7 +1736,8 @@ static bool io_get_sqring(struct io_ring_ctx *ctx, struct sqe_submit *s) head = ctx->cached_sq_head; /* See comment at the top of this file */ smp_rmb(); - if (head == READ_ONCE(ring->r.tail)) + /* make sure SQ entry isn't read before tail */ + if (head == smp_load_acquire(&ring->r.tail)) return false;
head = READ_ONCE(ring->array[head & ctx->sq_mask]);