* [PATCH] io_uring/kbuf: fix missing check for return value of io_buffer_get_list()
@ 2023-06-14 15:12 Chenyuan Mi
2023-06-14 16:14 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Chenyuan Mi @ 2023-06-14 15:12 UTC (permalink / raw)
To: axboe; +Cc: asml.silence, io-uring, linux-kernel, Chenyuan Mi
The io_buffer_get_list() function may return NULL, which may
cause null pointer deference, and other callsites of
io_buffer_get_list() all do Null check. Add Null check for
return value of io_buffer_get_list().
Found by our static analysis tool.
Signed-off-by: Chenyuan Mi <[email protected]>
---
io_uring/kbuf.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 2f0181521c98..d209a0a9e337 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -66,9 +66,11 @@ void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
buf = req->kbuf;
bl = io_buffer_get_list(ctx, buf->bgid);
- list_add(&buf->list, &bl->buf_list);
- req->flags &= ~REQ_F_BUFFER_SELECTED;
- req->buf_index = buf->bgid;
+ if (likely(bl)) {
+ list_add(&buf->list, &bl->buf_list);
+ req->flags &= ~REQ_F_BUFFER_SELECTED;
+ req->buf_index = buf->bgid;
+ }
io_ring_submit_unlock(ctx, issue_flags);
return;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring/kbuf: fix missing check for return value of io_buffer_get_list()
2023-06-14 15:12 [PATCH] io_uring/kbuf: fix missing check for return value of io_buffer_get_list() Chenyuan Mi
@ 2023-06-14 16:14 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2023-06-14 16:14 UTC (permalink / raw)
To: Chenyuan Mi; +Cc: asml.silence, io-uring, linux-kernel
On 6/14/23 9:12?AM, Chenyuan Mi wrote:
> The io_buffer_get_list() function may return NULL, which may
> cause null pointer deference, and other callsites of
> io_buffer_get_list() all do Null check. Add Null check for
> return value of io_buffer_get_list().
>
> Found by our static analysis tool.
Ah, was going to ask about a test case, but I guess it doesn't exist.
I don't think this can happen, as the legacy buffer groups can only ever
get added, and only get removed when the ring goes away.
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-14 16:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 15:12 [PATCH] io_uring/kbuf: fix missing check for return value of io_buffer_get_list() Chenyuan Mi
2023-06-14 16:14 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox