summaryrefslogtreecommitdiff
path: root/io_uring
diff options
context:
space:
mode:
authorFedor Pchelkin <pchelkin@ispras.ru>2023-03-16 21:56:16 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-03-22 13:30:05 +0100
commit84e2e393bf9fa47d134eddaeb8319c755e646f30 (patch)
tree27559e5d43b2136f8a7658b0b7088659d82f6eb8 /io_uring
parent5e784a7d07af42057c0576fb647b482f4cb0dc2c (diff)
downloadlinux-84e2e393bf9fa47d134eddaeb8319c755e646f30.tar.gz
linux-84e2e393bf9fa47d134eddaeb8319c755e646f30.tar.bz2
linux-84e2e393bf9fa47d134eddaeb8319c755e646f30.zip
io_uring: avoid null-ptr-deref in io_arm_poll_handler
No upstream commit exists for this commit. The issue was introduced with backporting upstream commit c16bda37594f ("io_uring/poll: allow some retries for poll triggering spuriously"). Memory allocation can possibly fail causing invalid pointer be dereferenced just before comparing it to NULL value. Move the pointer check in proper place (upstream has the similar location of the check). In case the request has REQ_F_POLLED flag up, apoll can't be NULL so no need to check there. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/io_uring.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 445afda927f4..fd799567fc23 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -5792,10 +5792,10 @@ static int io_arm_poll_handler(struct io_kiocb *req)
}
} else {
apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC);
+ if (unlikely(!apoll))
+ return IO_APOLL_ABORTED;
apoll->poll.retries = APOLL_MAX_RETRY;
}
- if (unlikely(!apoll))
- return IO_APOLL_ABORTED;
apoll->double_poll = NULL;
req->apoll = apoll;
req->flags |= REQ_F_POLLED;