diff options
author | Jens Axboe <axboe@kernel.dk> | 2019-10-28 11:15:33 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-10-28 11:15:33 -0400 |
commit | 044c1ab399afbe9f2ebef49a3204ef1509826dc7 (patch) | |
tree | 25b1ccdca5d8d48a99f2370144f797f56754866a /fs/io_uring.c | |
parent | 7b20238d28da46f394d37d4d51cc420e1ff9414a (diff) |
io_uring: don't touch ctx in setup after ring fd install
syzkaller reported an issue where it looks like a malicious app can
trigger a use-after-free of reading the ctx ->sq_array and ->rings
value right after having installed the ring fd in the process file
table.
Defer ring fd installation until after we're done reading those
values.
Fixes: 75b28affdd6a ("io_uring: allocate the two rings together")
Reported-by: syzbot+6f03d895a6cd0d06187f@syzkaller.appspotmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r-- | fs/io_uring.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c index ba1431046c98..c11c4157a4c2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c | |||
@@ -3829,10 +3829,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p) | |||
3829 | if (ret) | 3829 | if (ret) |
3830 | goto err; | 3830 | goto err; |
3831 | 3831 | ||
3832 | ret = io_uring_get_fd(ctx); | ||
3833 | if (ret < 0) | ||
3834 | goto err; | ||
3835 | |||
3836 | memset(&p->sq_off, 0, sizeof(p->sq_off)); | 3832 | memset(&p->sq_off, 0, sizeof(p->sq_off)); |
3837 | p->sq_off.head = offsetof(struct io_rings, sq.head); | 3833 | p->sq_off.head = offsetof(struct io_rings, sq.head); |
3838 | p->sq_off.tail = offsetof(struct io_rings, sq.tail); | 3834 | p->sq_off.tail = offsetof(struct io_rings, sq.tail); |
@@ -3850,6 +3846,14 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p) | |||
3850 | p->cq_off.overflow = offsetof(struct io_rings, cq_overflow); | 3846 | p->cq_off.overflow = offsetof(struct io_rings, cq_overflow); |
3851 | p->cq_off.cqes = offsetof(struct io_rings, cqes); | 3847 | p->cq_off.cqes = offsetof(struct io_rings, cqes); |
3852 | 3848 | ||
3849 | /* | ||
3850 | * Install ring fd as the very last thing, so we don't risk someone | ||
3851 | * having closed it before we finish setup | ||
3852 | */ | ||
3853 | ret = io_uring_get_fd(ctx); | ||
3854 | if (ret < 0) | ||
3855 | goto err; | ||
3856 | |||
3853 | p->features = IORING_FEAT_SINGLE_MMAP; | 3857 | p->features = IORING_FEAT_SINGLE_MMAP; |
3854 | return ret; | 3858 | return ret; |
3855 | err: | 3859 | err: |