public inbox for [email protected]
 help / color / mirror / Atom feed
From: Chenyuan Mi <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
	[email protected], Chenyuan Mi <[email protected]>
Subject: [PATCH] io_uring/kbuf: fix missing check for return value of io_buffer_get_list()
Date: Wed, 14 Jun 2023 08:12:46 -0700	[thread overview]
Message-ID: <[email protected]> (raw)

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


             reply	other threads:[~2023-06-14 15:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14 15:12 Chenyuan Mi [this message]
2023-06-14 16:14 ` [PATCH] io_uring/kbuf: fix missing check for return value of io_buffer_get_list() Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox