linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cifs: remove initialization value
@ 2022-10-04  6:23 Muhammad Usama Anjum
  2022-10-04  6:23 ` [PATCH 2/2] cifs: check returned value for error Muhammad Usama Anjum
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Muhammad Usama Anjum @ 2022-10-04  6:23 UTC (permalink / raw)
  To: Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N,
	Tom Talpey
  Cc: Muhammad Usama Anjum, kernel, kernel-janitors, linux-cifs,
	samba-technical, linux-kernel

Don't initialize the rc as its value is being overwritten before its
use.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 fs/cifs/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 0600f0a07628..2bf43c892ae6 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -879,7 +879,7 @@ SMB2_negotiate(const unsigned int xid,
 	struct smb2_negotiate_rsp *rsp;
 	struct kvec iov[1];
 	struct kvec rsp_iov;
-	int rc = 0;
+	int rc;
 	int resp_buftype;
 	int blob_offset, blob_length;
 	char *security_blob;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] cifs: check returned value for error
  2022-10-04  6:23 [PATCH 1/2] cifs: remove initialization value Muhammad Usama Anjum
@ 2022-10-04  6:23 ` Muhammad Usama Anjum
  2022-10-04 19:01   ` Paulo Alcantara
  2022-10-04 14:23 ` [PATCH 1/2] cifs: remove initialization value Enzo Matsumiya
  2022-10-04 18:59 ` Paulo Alcantara
  2 siblings, 1 reply; 10+ messages in thread
From: Muhammad Usama Anjum @ 2022-10-04  6:23 UTC (permalink / raw)
  To: Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N,
	Tom Talpey
  Cc: Muhammad Usama Anjum, kernel, kernel-janitors, linux-cifs,
	samba-technical, linux-kernel

smb311_decode_neg_context() can return error. Its return value should be
checked for errors.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 fs/cifs/smb2pdu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 2bf43c892ae6..c6e37352dbe1 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -1089,11 +1089,14 @@ SMB2_negotiate(const unsigned int xid,
 		server->signing_algorithm = SIGNING_ALG_AES_CMAC;
 		server->signing_negotiated = false;
 
-		if (rsp->NegotiateContextCount)
+		if (rsp->NegotiateContextCount) {
 			rc = smb311_decode_neg_context(rsp, server,
 						       rsp_iov.iov_len);
-		else
+			if (rc)
+				goto neg_exit;
+		} else {
 			cifs_server_dbg(VFS, "Missing expected negotiate contexts\n");
+		}
 
 		/*
 		 * Some servers will not send a SMB2_SIGNING_CAPABILITIES context response (*),
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] cifs: remove initialization value
  2022-10-04  6:23 [PATCH 1/2] cifs: remove initialization value Muhammad Usama Anjum
  2022-10-04  6:23 ` [PATCH 2/2] cifs: check returned value for error Muhammad Usama Anjum
@ 2022-10-04 14:23 ` Enzo Matsumiya
  2022-10-05 14:13   ` David Laight
  2022-10-05 14:58   ` Dan Carpenter
  2022-10-04 18:59 ` Paulo Alcantara
  2 siblings, 2 replies; 10+ messages in thread
From: Enzo Matsumiya @ 2022-10-04 14:23 UTC (permalink / raw)
  To: Muhammad Usama Anjum
  Cc: Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N,
	Tom Talpey, kernel, kernel-janitors, linux-cifs, samba-technical,
	linux-kernel

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.

>Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>---
> fs/cifs/smb2pdu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
>index 0600f0a07628..2bf43c892ae6 100644
>--- a/fs/cifs/smb2pdu.c
>+++ b/fs/cifs/smb2pdu.c
>@@ -879,7 +879,7 @@ SMB2_negotiate(const unsigned int xid,
> 	struct smb2_negotiate_rsp *rsp;
> 	struct kvec iov[1];
> 	struct kvec rsp_iov;
>-	int rc = 0;
>+	int rc;
> 	int resp_buftype;
> 	int blob_offset, blob_length;
> 	char *security_blob;
>-- 
>2.30.2

Cheers,

Enzo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] cifs: remove initialization value
  2022-10-04  6:23 [PATCH 1/2] cifs: remove initialization value Muhammad Usama Anjum
  2022-10-04  6:23 ` [PATCH 2/2] cifs: check returned value for error Muhammad Usama Anjum
  2022-10-04 14:23 ` [PATCH 1/2] cifs: remove initialization value Enzo Matsumiya
@ 2022-10-04 18:59 ` Paulo Alcantara
  2022-10-05  7:05   ` Steve French
  2 siblings, 1 reply; 10+ messages in thread
From: Paulo Alcantara @ 2022-10-04 18:59 UTC (permalink / raw)
  To: Muhammad Usama Anjum, Steve French, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey
  Cc: Muhammad Usama Anjum, kernel, kernel-janitors, linux-cifs,
	samba-technical, linux-kernel

Muhammad Usama Anjum <usama.anjum@collabora.com> writes:

> Don't initialize the rc as its value is being overwritten before its
> use.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>  fs/cifs/smb2pdu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] cifs: check returned value for error
  2022-10-04  6:23 ` [PATCH 2/2] cifs: check returned value for error Muhammad Usama Anjum
@ 2022-10-04 19:01   ` Paulo Alcantara
  2022-10-05  5:17     ` Muhammad Usama Anjum
  0 siblings, 1 reply; 10+ messages in thread
From: Paulo Alcantara @ 2022-10-04 19:01 UTC (permalink / raw)
  To: Muhammad Usama Anjum, Steve French, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey
  Cc: Muhammad Usama Anjum, kernel, kernel-janitors, linux-cifs,
	samba-technical, linux-kernel

Muhammad Usama Anjum <usama.anjum@collabora.com> writes:

> smb311_decode_neg_context() can return error. Its return value should be
> checked for errors.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>  fs/cifs/smb2pdu.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 2bf43c892ae6..c6e37352dbe1 100644

This patch doesn't apply in Steve's for-next branch[1].  If it still
makes sense, please rebase and resend.

[1] git://git.samba.org/sfrench/cifs-2.6.git

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] cifs: check returned value for error
  2022-10-04 19:01   ` Paulo Alcantara
@ 2022-10-05  5:17     ` Muhammad Usama Anjum
  0 siblings, 0 replies; 10+ messages in thread
From: Muhammad Usama Anjum @ 2022-10-05  5:17 UTC (permalink / raw)
  To: Paulo Alcantara, Steve French, Ronnie Sahlberg, Shyam Prasad N,
	Tom Talpey
  Cc: kernel, kernel-janitors, linux-cifs, samba-technical, linux-kernel

On 10/5/22 12:01 AM, Paulo Alcantara wrote:
> Muhammad Usama Anjum <usama.anjum@collabora.com> writes:
> 
>> smb311_decode_neg_context() can return error. Its return value should be
>> checked for errors.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>>   fs/cifs/smb2pdu.c | 7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
>> index 2bf43c892ae6..c6e37352dbe1 100644
> 
> This patch doesn't apply in Steve's for-next branch[1].  If it still
> makes sense, please rebase and resend.
> 
> [1] git://git.samba.org/sfrench/cifs-2.6.git
I've just applied on the latest next next-20221004 tag. This patch 
doesn't apply. It seems some other patch has merged and this patch isn't 
needed.

Can you apply only the first patch "[PATCH 1/2] cifs: remove 
initialization value" from this series? Or should I send that only as v2?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] cifs: remove initialization value
  2022-10-04 18:59 ` Paulo Alcantara
@ 2022-10-05  7:05   ` Steve French
  0 siblings, 0 replies; 10+ messages in thread
From: Steve French @ 2022-10-05  7:05 UTC (permalink / raw)
  To: Paulo Alcantara
  Cc: Muhammad Usama Anjum, Steve French, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, kernel, kernel-janitors, linux-cifs,
	samba-technical, linux-kernel

merged into cifs-2.6.git for-next

On Tue, Oct 4, 2022 at 2:09 PM Paulo Alcantara <pc@cjr.nz> wrote:
>
> Muhammad Usama Anjum <usama.anjum@collabora.com> writes:
>
> > Don't initialize the rc as its value is being overwritten before its
> > use.
> >
> > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> > ---
> >  fs/cifs/smb2pdu.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 1/2] cifs: remove initialization value
  2022-10-04 14:23 ` [PATCH 1/2] cifs: remove initialization value Enzo Matsumiya
@ 2022-10-05 14:13   ` David Laight
  2022-10-07 19:22     ` 'Enzo Matsumiya'
  2022-10-05 14:58   ` Dan Carpenter
  1 sibling, 1 reply; 10+ messages in thread
From: David Laight @ 2022-10-05 14:13 UTC (permalink / raw)
  To: 'Enzo Matsumiya', Muhammad Usama Anjum
  Cc: Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N,
	Tom Talpey, kernel, kernel-janitors, linux-cifs, samba-technical,
	linux-kernel

From: Enzo Matsumiya
> Sent: 04 October 2022 15:23
> 
> 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.

Depends on your POV.

If you don't initialise locals there is a fair chance that the
compiler will detect buggy code.

If you initialise them you get well defined behaviour - but
the compiler won't find bugs for you.

Mostly the kernel is in the first camp.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] cifs: remove initialization value
  2022-10-04 14:23 ` [PATCH 1/2] cifs: remove initialization value Enzo Matsumiya
  2022-10-05 14:13   ` David Laight
@ 2022-10-05 14:58   ` Dan Carpenter
  1 sibling, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2022-10-05 14:58 UTC (permalink / raw)
  To: Enzo Matsumiya
  Cc: Muhammad Usama Anjum, Steve French, Paulo Alcantara,
	Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, kernel,
	kernel-janitors, linux-cifs, samba-technical, linux-kernel

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] cifs: remove initialization value
  2022-10-05 14:13   ` David Laight
@ 2022-10-07 19:22     ` 'Enzo Matsumiya'
  0 siblings, 0 replies; 10+ messages in thread
From: 'Enzo Matsumiya' @ 2022-10-07 19:22 UTC (permalink / raw)
  To: David Laight
  Cc: Muhammad Usama Anjum, Steve French, Paulo Alcantara,
	Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, kernel,
	kernel-janitors, linux-cifs, samba-technical, linux-kernel

On 10/05, David Laight wrote:
>From: Enzo Matsumiya
>> Sent: 04 October 2022 15:23
>>
>> 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.
>
>Depends on your POV.

My POV was, considering "unitialized variables" is a _whole_ class of
security bugs, a patch to specifically deinitialize a variable is pretty
much like saying "let's leave this to chance".

https://cwe.mitre.org/data/definitions/457.html

>If you don't initialise locals there is a fair chance that the
>compiler will detect buggy code.
>
>If you initialise them you get well defined behaviour - but
>the compiler won't find bugs for you.
>
>Mostly the kernel is in the first camp.

My money is on the smaller unfair chances that the compiler cannot catch
even the smallest bit of complexity of uninitialized use.

Also, initializing something to 0/NULL will, most of the time, if at all,
be "just" a bug, whereas an uninitialized variable bug might turn into a
security bug and even go unnoticed for years.

Anyway, this patch got merged and I seem to be alone with this
concern...


>	David

Cheers,

Enzo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-10-07 19:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04  6:23 [PATCH 1/2] cifs: remove initialization value Muhammad Usama Anjum
2022-10-04  6:23 ` [PATCH 2/2] cifs: check returned value for error Muhammad Usama Anjum
2022-10-04 19:01   ` Paulo Alcantara
2022-10-05  5:17     ` Muhammad Usama Anjum
2022-10-04 14:23 ` [PATCH 1/2] cifs: remove initialization value Enzo Matsumiya
2022-10-05 14:13   ` David Laight
2022-10-07 19:22     ` 'Enzo Matsumiya'
2022-10-05 14:58   ` Dan Carpenter
2022-10-04 18:59 ` Paulo Alcantara
2022-10-05  7:05   ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).