diff mbox series

cifs: check ntwrk_buf_start for NULL before dereferencing it

Message ID 20181212220616.3918-1-lsahlber@redhat.com (mailing list archive)
State New, archived
Headers show
Series cifs: check ntwrk_buf_start for NULL before dereferencing it | expand

Commit Message

Ronnie Sahlberg Dec. 12, 2018, 10:06 p.m. UTC
RHBZ: 1021460

There is an issue where when multiple threads open/close the same directory
ntwrk_buf_start might end up being NULL, causing the call to smbCalcSize
later to ops with a NULL deref.

The real bug is why this happens and why this can become NULL for an
open cfile, which should not be allowed.
This patch tries to avoid a oops until the time when we fix the underlying
issue.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/readdir.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Steve French Dec. 13, 2018, 12:06 a.m. UTC | #1
merged into cifs-2.6.git for-next

On Wed, Dec 12, 2018 at 4:06 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> RHBZ: 1021460
>
> There is an issue where when multiple threads open/close the same directory
> ntwrk_buf_start might end up being NULL, causing the call to smbCalcSize
> later to ops with a NULL deref.
>
> The real bug is why this happens and why this can become NULL for an
> open cfile, which should not be allowed.
> This patch tries to avoid a oops until the time when we fix the underlying
> issue.
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/readdir.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
> index e169e1a5fd35..3925a7bfc74d 100644
> --- a/fs/cifs/readdir.c
> +++ b/fs/cifs/readdir.c
> @@ -655,7 +655,14 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
>                 /* scan and find it */
>                 int i;
>                 char *cur_ent;
> -               char *end_of_smb = cfile->srch_inf.ntwrk_buf_start +
> +               char *end_of_smb;
> +
> +               if (cfile->srch_inf.ntwrk_buf_start == NULL) {
> +                       cifs_dbg(VFS, "ntwrk_buf_start is NULL during readdir\n");
> +                       return -EIO;
> +               }
> +
> +               end_of_smb = cfile->srch_inf.ntwrk_buf_start +
>                         server->ops->calc_smb_size(
>                                         cfile->srch_inf.ntwrk_buf_start,
>                                         server);
> --
> 2.13.6
>
diff mbox series

Patch

diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index e169e1a5fd35..3925a7bfc74d 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -655,7 +655,14 @@  find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
 		/* scan and find it */
 		int i;
 		char *cur_ent;
-		char *end_of_smb = cfile->srch_inf.ntwrk_buf_start +
+		char *end_of_smb;
+
+		if (cfile->srch_inf.ntwrk_buf_start == NULL) {
+			cifs_dbg(VFS, "ntwrk_buf_start is NULL during readdir\n");
+			return -EIO;
+		}
+
+		end_of_smb = cfile->srch_inf.ntwrk_buf_start +
 			server->ops->calc_smb_size(
 					cfile->srch_inf.ntwrk_buf_start,
 					server);