linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [cifs:for-next 24/31] fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045)
@ 2019-09-13 13:46 Dan Carpenter
  2019-09-13 17:08 ` Pavel Shilovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-09-13 13:46 UTC (permalink / raw)
  To: kbuild, Steve French
  Cc: kbuild-all, linux-cifs, samba-technical, Ronnie Sahlberg

tree:   git://git.samba.org/sfrench/cifs-2.6.git for-next
head:   5fc321fb644fc787710353be11129edadd313f3a
commit: a091c5f67c994d154e8faf95ab774644be2f4dd7 [24/31] smb3: allow parallelizing decryption of reads

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045)

git remote add cifs git://git.samba.org/sfrench/cifs-2.6.git
git remote update cifs
git checkout a091c5f67c994d154e8faf95ab774644be2f4dd7
vim +/mid +4056 fs/cifs/smb2ops.c

a091c5f67c994d Steve French 2019-09-07  4030  static void smb2_decrypt_offload(struct work_struct *work)
a091c5f67c994d Steve French 2019-09-07  4031  {
a091c5f67c994d Steve French 2019-09-07  4032  	struct smb2_decrypt_work *dw = container_of(work,
a091c5f67c994d Steve French 2019-09-07  4033  				struct smb2_decrypt_work, decrypt);
a091c5f67c994d Steve French 2019-09-07  4034  	int i, rc;
a091c5f67c994d Steve French 2019-09-07  4035  	struct mid_q_entry *mid;
a091c5f67c994d Steve French 2019-09-07  4036  
a091c5f67c994d Steve French 2019-09-07  4037  	rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
a091c5f67c994d Steve French 2019-09-07  4038  			      dw->ppages, dw->npages, dw->len);
a091c5f67c994d Steve French 2019-09-07  4039  	if (rc) {
a091c5f67c994d Steve French 2019-09-07  4040  		cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
a091c5f67c994d Steve French 2019-09-07  4041  		goto free_pages;
a091c5f67c994d Steve French 2019-09-07  4042  	}
a091c5f67c994d Steve French 2019-09-07  4043  
a091c5f67c994d Steve French 2019-09-07  4044  	mid = smb2_find_mid(dw->server, dw->buf);
a091c5f67c994d Steve French 2019-09-07 @4045  	if (mid == NULL)
a091c5f67c994d Steve French 2019-09-07  4046  		cifs_dbg(FYI, "mid not found\n");

Return here?

a091c5f67c994d Steve French 2019-09-07  4047  	else {
a091c5f67c994d Steve French 2019-09-07  4048  		mid->decrypted = true;
a091c5f67c994d Steve French 2019-09-07  4049  		rc = handle_read_data(dw->server, mid, dw->buf,
a091c5f67c994d Steve French 2019-09-07  4050  				      dw->server->vals->read_rsp_size,
a091c5f67c994d Steve French 2019-09-07  4051  				      dw->ppages, dw->npages, dw->len);
a091c5f67c994d Steve French 2019-09-07  4052  	}
a091c5f67c994d Steve French 2019-09-07  4053  
a091c5f67c994d Steve French 2019-09-07  4054  	dw->server->lstrp = jiffies;
a091c5f67c994d Steve French 2019-09-07  4055  
a091c5f67c994d Steve French 2019-09-07 @4056  	mid->callback(mid);
                                                ^^^^^^^^^^^^^
Potential NULL derference.

a091c5f67c994d Steve French 2019-09-07  4057  
a091c5f67c994d Steve French 2019-09-07  4058  	cifs_mid_q_entry_release(mid);
a091c5f67c994d Steve French 2019-09-07  4059  
a091c5f67c994d Steve French 2019-09-07  4060  free_pages:
a091c5f67c994d Steve French 2019-09-07  4061  	for (i = dw->npages-1; i >= 0; i--)
a091c5f67c994d Steve French 2019-09-07  4062  		put_page(dw->ppages[i]);
a091c5f67c994d Steve French 2019-09-07  4063  
a091c5f67c994d Steve French 2019-09-07  4064  	kfree(dw->ppages);
a091c5f67c994d Steve French 2019-09-07  4065  	cifs_small_buf_release(dw->buf);
a091c5f67c994d Steve French 2019-09-07  4066  }

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

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

* Re: [cifs:for-next 24/31] fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045)
  2019-09-13 13:46 [cifs:for-next 24/31] fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045) Dan Carpenter
@ 2019-09-13 17:08 ` Pavel Shilovsky
  2019-09-13 21:52   ` Steve French
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Shilovsky @ 2019-09-13 17:08 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: kbuild, Steve French, kbuild-all, linux-cifs, samba-technical,
	Ronnie Sahlberg

Yes, this is a bug.

Steve, let's move

+       mid->callback(mid);
+
+       cifs_mid_q_entry_release(mid);

under ELSE {} block above.

We should probably move

+       dw->server->lstrp = jiffies;

before we looking for a mid.

--
Best regards,
Pavel Shilovsky

пт, 13 сент. 2019 г. в 06:47, Dan Carpenter <dan.carpenter@oracle.com>:
>
> tree:   git://git.samba.org/sfrench/cifs-2.6.git for-next
> head:   5fc321fb644fc787710353be11129edadd313f3a
> commit: a091c5f67c994d154e8faf95ab774644be2f4dd7 [24/31] smb3: allow parallelizing decryption of reads
>
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> New smatch warnings:
> fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045)
>
> git remote add cifs git://git.samba.org/sfrench/cifs-2.6.git
> git remote update cifs
> git checkout a091c5f67c994d154e8faf95ab774644be2f4dd7
> vim +/mid +4056 fs/cifs/smb2ops.c
>
> a091c5f67c994d Steve French 2019-09-07  4030  static void smb2_decrypt_offload(struct work_struct *work)
> a091c5f67c994d Steve French 2019-09-07  4031  {
> a091c5f67c994d Steve French 2019-09-07  4032    struct smb2_decrypt_work *dw = container_of(work,
> a091c5f67c994d Steve French 2019-09-07  4033                            struct smb2_decrypt_work, decrypt);
> a091c5f67c994d Steve French 2019-09-07  4034    int i, rc;
> a091c5f67c994d Steve French 2019-09-07  4035    struct mid_q_entry *mid;
> a091c5f67c994d Steve French 2019-09-07  4036
> a091c5f67c994d Steve French 2019-09-07  4037    rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
> a091c5f67c994d Steve French 2019-09-07  4038                          dw->ppages, dw->npages, dw->len);
> a091c5f67c994d Steve French 2019-09-07  4039    if (rc) {
> a091c5f67c994d Steve French 2019-09-07  4040            cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
> a091c5f67c994d Steve French 2019-09-07  4041            goto free_pages;
> a091c5f67c994d Steve French 2019-09-07  4042    }
> a091c5f67c994d Steve French 2019-09-07  4043
> a091c5f67c994d Steve French 2019-09-07  4044    mid = smb2_find_mid(dw->server, dw->buf);
> a091c5f67c994d Steve French 2019-09-07 @4045    if (mid == NULL)
> a091c5f67c994d Steve French 2019-09-07  4046            cifs_dbg(FYI, "mid not found\n");
>
> Return here?
>
> a091c5f67c994d Steve French 2019-09-07  4047    else {
> a091c5f67c994d Steve French 2019-09-07  4048            mid->decrypted = true;
> a091c5f67c994d Steve French 2019-09-07  4049            rc = handle_read_data(dw->server, mid, dw->buf,
> a091c5f67c994d Steve French 2019-09-07  4050                                  dw->server->vals->read_rsp_size,
> a091c5f67c994d Steve French 2019-09-07  4051                                  dw->ppages, dw->npages, dw->len);
> a091c5f67c994d Steve French 2019-09-07  4052    }
> a091c5f67c994d Steve French 2019-09-07  4053
> a091c5f67c994d Steve French 2019-09-07  4054    dw->server->lstrp = jiffies;
> a091c5f67c994d Steve French 2019-09-07  4055
> a091c5f67c994d Steve French 2019-09-07 @4056    mid->callback(mid);
>                                                 ^^^^^^^^^^^^^
> Potential NULL derference.
>
> a091c5f67c994d Steve French 2019-09-07  4057
> a091c5f67c994d Steve French 2019-09-07  4058    cifs_mid_q_entry_release(mid);
> a091c5f67c994d Steve French 2019-09-07  4059
> a091c5f67c994d Steve French 2019-09-07  4060  free_pages:
> a091c5f67c994d Steve French 2019-09-07  4061    for (i = dw->npages-1; i >= 0; i--)
> a091c5f67c994d Steve French 2019-09-07  4062            put_page(dw->ppages[i]);
> a091c5f67c994d Steve French 2019-09-07  4063
> a091c5f67c994d Steve French 2019-09-07  4064    kfree(dw->ppages);
> a091c5f67c994d Steve French 2019-09-07  4065    cifs_small_buf_release(dw->buf);
> a091c5f67c994d Steve French 2019-09-07  4066  }
>
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

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

* Re: [cifs:for-next 24/31] fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045)
  2019-09-13 17:08 ` Pavel Shilovsky
@ 2019-09-13 21:52   ` Steve French
  0 siblings, 0 replies; 3+ messages in thread
From: Steve French @ 2019-09-13 21:52 UTC (permalink / raw)
  To: Pavel Shilovsky
  Cc: Dan Carpenter, linux-cifs, samba-technical, Ronnie Sahlberg,
	kbuild, kbuild-all, Steve French

[-- Attachment #1: Type: text/plain, Size: 4640 bytes --]

Fix attached.  Tentatively merged into cifs-2.6.git for-next pending
review and the usual "buildbot" automated regression testing

On Fri, Sep 13, 2019 at 12:09 PM Pavel Shilovsky via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> Yes, this is a bug.
>
> Steve, let's move
>
> +       mid->callback(mid);
> +
> +       cifs_mid_q_entry_release(mid);
>
> under ELSE {} block above.
>
> We should probably move
>
> +       dw->server->lstrp = jiffies;
>
> before we looking for a mid.
>
> --
> Best regards,
> Pavel Shilovsky
>
> пт, 13 сент. 2019 г. в 06:47, Dan Carpenter <dan.carpenter@oracle.com>:
> >
> > tree:   git://git.samba.org/sfrench/cifs-2.6.git for-next
> > head:   5fc321fb644fc787710353be11129edadd313f3a
> > commit: a091c5f67c994d154e8faf95ab774644be2f4dd7 [24/31] smb3: allow parallelizing decryption of reads
> >
> > If you fix the issue, kindly add following tag
> > Reported-by: kbuild test robot <lkp@intel.com>
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> >
> > New smatch warnings:
> > fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045)
> >
> > git remote add cifs git://git.samba.org/sfrench/cifs-2.6.git
> > git remote update cifs
> > git checkout a091c5f67c994d154e8faf95ab774644be2f4dd7
> > vim +/mid +4056 fs/cifs/smb2ops.c
> >
> > a091c5f67c994d Steve French 2019-09-07  4030  static void smb2_decrypt_offload(struct work_struct *work)
> > a091c5f67c994d Steve French 2019-09-07  4031  {
> > a091c5f67c994d Steve French 2019-09-07  4032    struct smb2_decrypt_work *dw = container_of(work,
> > a091c5f67c994d Steve French 2019-09-07  4033                            struct smb2_decrypt_work, decrypt);
> > a091c5f67c994d Steve French 2019-09-07  4034    int i, rc;
> > a091c5f67c994d Steve French 2019-09-07  4035    struct mid_q_entry *mid;
> > a091c5f67c994d Steve French 2019-09-07  4036
> > a091c5f67c994d Steve French 2019-09-07  4037    rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
> > a091c5f67c994d Steve French 2019-09-07  4038                          dw->ppages, dw->npages, dw->len);
> > a091c5f67c994d Steve French 2019-09-07  4039    if (rc) {
> > a091c5f67c994d Steve French 2019-09-07  4040            cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
> > a091c5f67c994d Steve French 2019-09-07  4041            goto free_pages;
> > a091c5f67c994d Steve French 2019-09-07  4042    }
> > a091c5f67c994d Steve French 2019-09-07  4043
> > a091c5f67c994d Steve French 2019-09-07  4044    mid = smb2_find_mid(dw->server, dw->buf);
> > a091c5f67c994d Steve French 2019-09-07 @4045    if (mid == NULL)
> > a091c5f67c994d Steve French 2019-09-07  4046            cifs_dbg(FYI, "mid not found\n");
> >
> > Return here?
> >
> > a091c5f67c994d Steve French 2019-09-07  4047    else {
> > a091c5f67c994d Steve French 2019-09-07  4048            mid->decrypted = true;
> > a091c5f67c994d Steve French 2019-09-07  4049            rc = handle_read_data(dw->server, mid, dw->buf,
> > a091c5f67c994d Steve French 2019-09-07  4050                                  dw->server->vals->read_rsp_size,
> > a091c5f67c994d Steve French 2019-09-07  4051                                  dw->ppages, dw->npages, dw->len);
> > a091c5f67c994d Steve French 2019-09-07  4052    }
> > a091c5f67c994d Steve French 2019-09-07  4053
> > a091c5f67c994d Steve French 2019-09-07  4054    dw->server->lstrp = jiffies;
> > a091c5f67c994d Steve French 2019-09-07  4055
> > a091c5f67c994d Steve French 2019-09-07 @4056    mid->callback(mid);
> >                                                 ^^^^^^^^^^^^^
> > Potential NULL derference.
> >
> > a091c5f67c994d Steve French 2019-09-07  4057
> > a091c5f67c994d Steve French 2019-09-07  4058    cifs_mid_q_entry_release(mid);
> > a091c5f67c994d Steve French 2019-09-07  4059
> > a091c5f67c994d Steve French 2019-09-07  4060  free_pages:
> > a091c5f67c994d Steve French 2019-09-07  4061    for (i = dw->npages-1; i >= 0; i--)
> > a091c5f67c994d Steve French 2019-09-07  4062            put_page(dw->ppages[i]);
> > a091c5f67c994d Steve French 2019-09-07  4063
> > a091c5f67c994d Steve French 2019-09-07  4064    kfree(dw->ppages);
> > a091c5f67c994d Steve French 2019-09-07  4065    cifs_small_buf_release(dw->buf);
> > a091c5f67c994d Steve French 2019-09-07  4066  }
> >
> > ---
> > 0-DAY kernel test infrastructure                Open Source Technology Center
> > https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
>


-- 
Thanks,

Steve

[-- Attachment #2: 0001-smb3-fix-potential-null-dereference-in-decrypt-offlo.patch --]
[-- Type: text/x-patch, Size: 1472 bytes --]

From 9b6ecf32499b32259ea306fc3e150ce2337a8b7b Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Fri, 13 Sep 2019 16:47:31 -0500
Subject: [PATCH] smb3: fix potential null dereference in decrypt offload

commit a091c5f67c99 ("smb3: allow parallelizing decryption of reads")
had a potential null dereference

Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Suggested-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/smb2ops.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 5776d7b0a97e..eaed18061314 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -4055,6 +4055,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
 		goto free_pages;
 	}
 
+	dw->server->lstrp = jiffies;
 	mid = smb2_find_mid(dw->server, dw->buf);
 	if (mid == NULL)
 		cifs_dbg(FYI, "mid not found\n");
@@ -4063,14 +4064,10 @@ static void smb2_decrypt_offload(struct work_struct *work)
 		rc = handle_read_data(dw->server, mid, dw->buf,
 				      dw->server->vals->read_rsp_size,
 				      dw->ppages, dw->npages, dw->len);
+		mid->callback(mid);
+		cifs_mid_q_entry_release(mid);
 	}
 
-	dw->server->lstrp = jiffies;
-
-	mid->callback(mid);
-
-	cifs_mid_q_entry_release(mid);
-
 free_pages:
 	for (i = dw->npages-1; i >= 0; i--)
 		put_page(dw->ppages[i]);
-- 
2.20.1


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

end of thread, other threads:[~2019-09-13 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-13 13:46 [cifs:for-next 24/31] fs/cifs/smb2ops.c:4056 smb2_decrypt_offload() error: we previously assumed 'mid' could be null (see line 4045) Dan Carpenter
2019-09-13 17:08 ` Pavel Shilovsky
2019-09-13 21:52   ` 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).