[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Yz2bhrotBMO6JwPw@kadam>
Date: Wed, 5 Oct 2022 17:58:14 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: Enzo Matsumiya <ematsumiya@...e.de>
Cc: Muhammad Usama Anjum <usama.anjum@...labora.com>,
Steve French <sfrench@...ba.org>, Paulo Alcantara <pc@....nz>,
Ronnie Sahlberg <lsahlber@...hat.com>,
Shyam Prasad N <sprasad@...rosoft.com>,
Tom Talpey <tom@...pey.com>, kernel@...labora.com,
kernel-janitors@...r.kernel.org, linux-cifs@...r.kernel.org,
samba-technical@...ts.samba.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] cifs: remove initialization value
On Tue, Oct 04, 2022 at 11:23:06AM -0300, Enzo Matsumiya wrote:
> Hi Usama,
>
> On 10/04, Muhammad Usama Anjum wrote:
> > Don't initialize the rc as its value is being overwritten before its
> > use.
>
> Being bitten by an unitialized variable bug as recent as 2 days ago, I'd
> say this is a step backwards from the "best practices" POV.
Zero is a random bogus value.
How likely is it that zero is the correct value or a negative error code
is correct? There are probably a four to one ratio of error paths to
success paths in the kernel (100% made up statistic). But mostly
success paths end in "return 0;". So when you see a "return rc;" there
is probably less than one in ten chance that rc is potentially zero. So
there is an over 90% chance that zero is the wrong initializer to use.
Meanwhile what initializing things to bogus values does is it disables
static analysis checking for uninitialized value bugs. So it hides bugs
until the user hits them.
Disabling static analysis can make sense for a very complicated function
but it's not best practice in general.
On the other hand uninitialized memory is a source of security bugs.
There are two ways to prevent this: 1) Use static analysis. Currently
the GCC uninitialized variable warning is disabled because it is kind
of rubbish but there are other static analysis tools out there. 2) Use
the GCC extension to automatically initialize stack data to zero.
regards,
dan carpenter
Powered by blists - more mailing lists