[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAOG64qN1fQ_surhMJSuygyf_emSvFm3HKRgj_JAZteFVjaP3+A@mail.gmail.com>
Date: Mon, 7 Feb 2022 21:33:02 +0700
From: Alviro Iskandar Setiawan <alviro.iskandar@...il.com>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: Jens Axboe <axboe@...nel.dk>,
Ammar Faizi <ammarfaizi2@...weeb.org>,
"GNU/Weeb Mailing List" <gwml@...weeb.org>,
io-uring Mailing list <io-uring@...r.kernel.org>,
Tea Inside Mailing List <timl@...r.teainside.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
kernel test robot <lkp@...el.com>,
"Chen, Rong A" <rong.a.chen@...el.com>,
Pavel Begunkov <asml.silence@...il.com>
Subject: Re: [PATCH io_uring-5.17] io_uring: Fix build error potential reading
uninitialized value
On Mon, Feb 7, 2022 at 9:21 PM Dan Carpenter <dan.carpenter@...cle.com> wrote:
> On Mon, Feb 07, 2022 at 06:45:57AM -0700, Jens Axboe wrote:
> > On 2/7/22 4:43 AM, Ammar Faizi wrote:
> > > From: Alviro Iskandar Setiawan <alviro.iskandar@...il.com>
> > >
> > > 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.
> >
> > 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).
>
> 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.
>
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
Powered by blists - more mailing lists