io_uring: Fix build error potential reading uninitialized value
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 io_uring: Fix build error potential reading uninitialized value
From: Alviro Iskandar Setiawan <[email protected]>
In io_recv() if import_single_range() fails, the @flags variable is uninitialized, then it will goto out_free.
After the goto, the compiler doesn't know that (ret < min_ret) is always true, so it thinks the "if ((flags & MSG_WAITALL) ..." path could be taken.
The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0:
``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ```
Fix this by bypassing the @ret and @flags check when import_single_range() fails.
Reasons:
1. import_single_range() only returns -EFAULT when it fails.
2. At that point @flags is uninitialized and shouldn't be read.
--- fs/io_uring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/io_uring.c +1 -2
@@ -5228,7 +5228,6 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) min_ret =iov_iter_count (&msg.msg_iter); ret =sock_recvmsg (sock, &msg, flags); -out_free:if (ret < min_ret) {if (ret == -EAGAIN && force_nonblock)return -EAGAIN ;
@@ -5236,9 +5235,9 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) ret = -EINTR ;req_set_fail (req); }else if ((flags &MSG_WAITALL ) && (msg.msg_flags & (MSG_TRUNC |MSG_CTRUNC ))) { +out_free:req_set_fail (req); } -__io_req_complete (req, issue_flags, ret,io_put_kbuf (req));return 0 ; }
base-commit: f6133fbd373811066c8441737e65f384c8f31974
Signature · 1 line
2.32.0
Jens Axboe
maintainerQuoted 9 lines · Ammar Faizi
From: Alviro Iskandar Setiawan <[email protected]>
In
io_recv()ifimport_single_range()fails, the @flags variable is uninitialized, then it will gotoout_free.After the goto, the compiler doesn't know that (ret <
min_ret) is always true, so it thinks the "if ((flags &MSG_WAITALL) ..." path could be taken.
Quoted 6 lines
The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0:
``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ```Fix this by bypassing the @ret and @flags check when
import_single_range()fails.
The compiler should be able to deduce this, and I guess newer compilers do which is why we haven't seen this warning before. I'm fine with doing this as a cleanup, but I think the commit title should be modified a bit. It sounds like there might be an issue reading uninitialized data, which isn't actually true.
Signature · 1 line
Jens Axboe
PATCH v2 1/1 io_uring: Clean up a false-positive warning from GCC 9.3.0
From: Alviro Iskandar Setiawan <[email protected]>
In io_recv(), if import_single_range() fails, the @flags variable is uninitialized, then it will goto out_free.
After the goto, the compiler doesn't know that (ret < min_ret) is always true, so it thinks the "if ((flags & MSG_WAITALL) ..." path could be taken.
The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0:
``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ```
Fix this by bypassing the @ret and @flags check when import_single_range() fails.
Reasons:
1. import_single_range() only returns -EFAULT when it fails.
2. At that point, @flags is uninitialized and shouldn't be read.
---
v2:
- Update the subject line
fs/io_uring.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/io_uring.c +1 -2
@@ -5228,7 +5228,6 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) min_ret =iov_iter_count (&msg.msg_iter); ret =sock_recvmsg (sock, &msg, flags); -out_free:if (ret < min_ret) {if (ret == -EAGAIN && force_nonblock)return -EAGAIN ;
@@ -5236,9 +5235,9 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) ret = -EINTR ;req_set_fail (req); }else if ((flags &MSG_WAITALL ) && (msg.msg_flags & (MSG_TRUNC |MSG_CTRUNC ))) { +out_free:req_set_fail (req); } -__io_req_complete (req, issue_flags, ret,io_put_kbuf (req));return 0 ; }
base-commit: f6133fbd373811066c8441737e65f384c8f31974
Signature · 1 line
2.32.0
Re: [PATCH io_uring-5.17 v2] io_uring: Clean up a false-positive warning from GCC 9.3.0
Quoted 10 lines · Ammar Faizi
From: Alviro Iskandar Setiawan <[email protected]>
In
io_recv(), ifimport_single_range()fails, the @flags variable is uninitialized, then it will gotoout_free.After the goto, the compiler doesn't know that (ret <
min_ret) is always true, so it thinks the "if ((flags &MSG_WAITALL) ..." path could be taken.[...]
Applied, thanks!
[1/1] io_uring: Clean up a false-positive warning from GCC 9.3.0
commit: 0d7c1153d9291197c1dc473cfaade77acb874b4b
Best regards,
Signature · 1 line
Jens Axboe
Quoted 17 lines · Jens Axboe
Quoted 9 lines · Ammar Faizi
From: Alviro Iskandar Setiawan <[email protected]>
In
io_recv()ifimport_single_range()fails, the @flags variable is uninitialized, then it will gotoout_free.After the goto, the compiler doesn't know that (ret <
min_ret) is always true, so it thinks the "if ((flags &MSG_WAITALL) ..." path could be taken.Quoted 6 lines
The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0:
``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ```Fix this by bypassing the @ret and @flags check when
import_single_range()fails.
Quoted 2 lines
The compiler should be able to deduce this, and I guess newer compilers do which is why we haven't seen this warning before.
No, we disabled GCC's uninitialized variable checking a couple years back. Linus got sick of the false positives. You can still see it if you enable W=2
fs/io_uring.c: In function ‘io_recv’:fs/io_uring.c:5252:20: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]
} else if ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) {
~~~~~~~^~~~~~~~~~~~~~If you introduce an uninitialized variable bug then likelyhood is the kbuild-bot will send you a Clang warning or a Smatch warning or both. I don't think anyone looks at GCC W=2 warnings.
regards,
dan carpenter
Quoted 18 lines · Dan Carpenter
Quoted 17 lines · Jens Axboe
Quoted 15 lines · Ammar Faizi
From: Alviro Iskandar Setiawan <[email protected]>
In
io_recv()ifimport_single_range()fails, the @flags variable is uninitialized, then it will gotoout_free.After the goto, the compiler doesn't know that (ret <
min_ret) is always true, so it thinks the "if ((flags &MSG_WAITALL) ..." path could be taken.The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0:
``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ```Fix this by bypassing the @ret and @flags check when
import_single_range()fails.
Quoted 2 lines
Quoted 2 lines
The compiler should be able to deduce this, and I guess newer compilers do which is why we haven't seen this warning before.
The compiler can't deduce this because the import_single_range() is located in a different translation unit (different C file), so it can't prove that (ret < min_ret) is always true as it can't see the function definition (in reality, it is always true because it only returns either 0 or -EFAULT).
Quoted 5 lines
No, we disabled GCC's uninitialized variable checking a couple years back. Linus got sick of the false positives. You can still see it if you enable W=2
Quoted 9 lines
fs/io_uring.c: In function ‘io_recv’:fs/io_uring.c:5252:20: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]} else if ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { ~~~~~~~^~~~~~~~~~~~~~If you introduce an uninitialized variable bug then likelyhood is the kbuild-bot will send you a Clang warning or a Smatch warning or both. I don't think anyone looks at GCC W=2 warnings.
This warning is valid, and the compiler should really warn that. But again, in reality, this is still a false-positive warning, because that "else if" will never be taken from the "goto out_free" path.
-- Viro
Jens Axboe
maintainerQuoted 19 lines · Alviro Iskandar Setiawan
Quoted 18 lines · Dan Carpenter
Quoted 17 lines · Jens Axboe
Quoted 15 lines · Ammar Faizi
From: Alviro Iskandar Setiawan <[email protected]>
In
io_recv()ifimport_single_range()fails, the @flags variable is uninitialized, then it will gotoout_free.After the goto, the compiler doesn't know that (ret <
min_ret) is always true, so it thinks the "if ((flags &MSG_WAITALL) ..." path could be taken.The complaint comes from gcc-9 (Debian 9.3.0-22) 9.3.0:
``` fs/io_uring.c:5238 io_recvfrom() error: uninitialized symbol 'flags' ```Fix this by bypassing the @ret and @flags check when
import_single_range()fails.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
The compiler should be able to deduce this, and I guess newer compilers do which is why we haven't seen this warning before.
The compiler can't deduce this because the
import_single_range()is located in a different translation unit (different C file), so it can't prove that (ret <min_ret) is always true as it can't see the function definition (in reality, it is always true because it only returns either 0 or-EFAULT).
Yes you are right, I forgot this is the generic helper, and not our internal one.
Quoted 9 lines
Quoted 9 lines
No, we disabled GCC's uninitialized variable checking a couple years back. Linus got sick of the false positives. You can still see it if you enable W=2
fs/io_uring.c: In function ‘io_recv’:fs/io_uring.c:5252:20: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]} else if ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { ~~~~~~~^~~~~~~~~~~~~~
Quoted 8 lines
Quoted 4 lines
If you introduce an uninitialized variable bug then likelyhood is the kbuild-bot will send you a Clang warning or a Smatch warning or both. I don't think anyone looks at GCC W=2 warnings.
This warning is valid, and the compiler should really warn that. But again, in reality, this is still a false-positive warning, because that "else if" will never be taken from the "goto
out_free" path.
Right, as mentioned in my email, there is no bug there. But I do like the patch as it cleans it up too, the error-out path should not include non-cleanup items.
Signature · 1 line
Jens Axboe