From: Muhammad Usama Anjum <musamaanjum@gmail.com>
To: Jens Axboe <axboe@kernel.dk>,
Pavel Begunkov <asml.silence@gmail.com>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
colin.king@canonical.com, dan.carpenter@oracle.com
Cc: musamaanjum@gmail.com
Subject: [PATCH] io_uring: Initialize variable before use
Date: Mon, 22 Mar 2021 23:41:58 +0500 [thread overview]
Message-ID: <20210322184158.GA2095479@LEGION> (raw)
1) Initialize the struct msghdr msg in the start of the function
2) Uninitialized variable msg.msg_flags can get used if branch happens to
out_free before initialization.
So initialize variable in question in the start of the function for
simplicity in logic and use.
Addresses-Coverity: ("Uninitialized variable")
Addresses-Coverity: ("Uninitialized variable read")
Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
---
fs/io_uring.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index bba74631954b..d5f83326abff 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4677,7 +4677,8 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_buffer *kbuf;
struct io_sr_msg *sr = &req->sr_msg;
- struct msghdr msg;
+ struct msghdr msg = {.msg_name = NULL, .msg_control = NULL, .msg_controllen = 0,
+ .msg_namelen = 0, .msg_iocb = NULL, .msg_flags = 0};
void __user *buf = sr->buf;
struct socket *sock;
struct iovec iov;
@@ -4701,13 +4702,6 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(ret))
goto out_free;
- msg.msg_name = NULL;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- msg.msg_namelen = 0;
- msg.msg_iocb = NULL;
- msg.msg_flags = 0;
-
flags = req->sr_msg.msg_flags | MSG_NOSIGNAL;
if (flags & MSG_DONTWAIT)
req->flags |= REQ_F_NOWAIT;
--
2.25.1
next reply other threads:[~2021-03-22 18:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 18:41 Muhammad Usama Anjum [this message]
2021-03-31 8:25 ` [PATCH] io_uring: Initialize variable before use Muhammad Usama Anjum
2021-03-31 8:48 ` Dan Carpenter
2021-03-31 9:57 ` Muhammad Usama Anjum
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 \
--in-reply-to=20210322184158.GA2095479@LEGION \
--to=musamaanjum@gmail.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=colin.king@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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