All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return()
@ 2021-05-19 16:06 schumaker.anna
  2021-05-19 16:42 ` Trond Myklebust
  0 siblings, 1 reply; 3+ messages in thread
From: schumaker.anna @ 2021-05-19 16:06 UTC (permalink / raw)
  To: Trond.Myklebust, linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

Commit de144ff4234f changes _pnfs_return_layout() to call
pnfs_mark_matching_lsegs_return() passing NULL as the struct
pnfs_layout_range argument. Unfortunately,
pnfs_mark_matching_lsegs_return() doesn't check if we have a value here
before dereferencing it, causing an oops.

I'm able to hit this crash consistently when running connectathon basic
tests on NFS v4.1/v4.2 against Ontap.

Fixes: de144ff4234f ("NFSv4: Don't discard segments marked for return in _pnfs_return_layout()")
Cc: stable@vger.kernel.org
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 fs/nfs/pnfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 03e0b34c4a64..6d720afb7b70 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -2484,12 +2484,12 @@ pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo,
 			set_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags);
 		}
 
-	if (remaining) {
+	if (remaining && return_range) {
 		pnfs_set_plh_return_info(lo, return_range->iomode, seq);
 		return -EBUSY;
 	}
 
-	if (!list_empty(&lo->plh_return_segs)) {
+	if (return_range && !list_empty(&lo->plh_return_segs)) {
 		pnfs_set_plh_return_info(lo, return_range->iomode, seq);
 		return 0;
 	}
-- 
2.29.2


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

* Re: [PATCH] NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return()
  2021-05-19 16:06 [PATCH] NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return() schumaker.anna
@ 2021-05-19 16:42 ` Trond Myklebust
  2021-05-19 16:47   ` Anna Schumaker
  0 siblings, 1 reply; 3+ messages in thread
From: Trond Myklebust @ 2021-05-19 16:42 UTC (permalink / raw)
  To: linux-nfs, schumaker.anna; +Cc: Anna.Schumaker

On Wed, 2021-05-19 at 12:06 -0400, schumaker.anna@gmail.com wrote:
> From: Anna Schumaker <Anna.Schumaker@Netapp.com>
> 
> Commit de144ff4234f changes _pnfs_return_layout() to call
> pnfs_mark_matching_lsegs_return() passing NULL as the struct
> pnfs_layout_range argument. Unfortunately,
> pnfs_mark_matching_lsegs_return() doesn't check if we have a value
> here
> before dereferencing it, causing an oops.
> 
> I'm able to hit this crash consistently when running connectathon
> basic
> tests on NFS v4.1/v4.2 against Ontap.
> 
> Fixes: de144ff4234f ("NFSv4: Don't discard segments marked for return
> in _pnfs_return_layout()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
> ---
>  fs/nfs/pnfs.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> index 03e0b34c4a64..6d720afb7b70 100644
> --- a/fs/nfs/pnfs.c
> +++ b/fs/nfs/pnfs.c
> @@ -2484,12 +2484,12 @@ pnfs_mark_matching_lsegs_return(struct
> pnfs_layout_hdr *lo,
>                         set_bit(NFS_LSEG_LAYOUTRETURN, &lseg-
> >pls_flags);
>                 }
>  
> -       if (remaining) {
> +       if (remaining && return_range) {
>                 pnfs_set_plh_return_info(lo, return_range->iomode,
> seq);
>                 return -EBUSY;
>         }
>  
> -       if (!list_empty(&lo->plh_return_segs)) {
> +       if (return_range && !list_empty(&lo->plh_return_segs)) {
>                 pnfs_set_plh_return_info(lo, return_range->iomode,
> seq);
>                 return 0;

This patch would mean we fail to mark the layout for return in
situations where we clearly should be doing so. The lack of a
return_range doesn't indicate that we don't want to return any layouts,
but rather that we want to return all layouts.

I suggest rather changing the caller, _pnfs_return_layout() to move
that declaration of 'struct pnfs_layout_range range' out of the if
statement so that it can be passed as an argument instead of NULL.

>         }

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



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

* Re: [PATCH] NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return()
  2021-05-19 16:42 ` Trond Myklebust
@ 2021-05-19 16:47   ` Anna Schumaker
  0 siblings, 0 replies; 3+ messages in thread
From: Anna Schumaker @ 2021-05-19 16:47 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: linux-nfs

On Wed, May 19, 2021 at 12:43 PM Trond Myklebust
<trondmy@hammerspace.com> wrote:
>
> On Wed, 2021-05-19 at 12:06 -0400, schumaker.anna@gmail.com wrote:
> > From: Anna Schumaker <Anna.Schumaker@Netapp.com>
> >
> > Commit de144ff4234f changes _pnfs_return_layout() to call
> > pnfs_mark_matching_lsegs_return() passing NULL as the struct
> > pnfs_layout_range argument. Unfortunately,
> > pnfs_mark_matching_lsegs_return() doesn't check if we have a value
> > here
> > before dereferencing it, causing an oops.
> >
> > I'm able to hit this crash consistently when running connectathon
> > basic
> > tests on NFS v4.1/v4.2 against Ontap.
> >
> > Fixes: de144ff4234f ("NFSv4: Don't discard segments marked for return
> > in _pnfs_return_layout()")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
> > ---
> >  fs/nfs/pnfs.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> > index 03e0b34c4a64..6d720afb7b70 100644
> > --- a/fs/nfs/pnfs.c
> > +++ b/fs/nfs/pnfs.c
> > @@ -2484,12 +2484,12 @@ pnfs_mark_matching_lsegs_return(struct
> > pnfs_layout_hdr *lo,
> >                         set_bit(NFS_LSEG_LAYOUTRETURN, &lseg-
> > >pls_flags);
> >                 }
> >
> > -       if (remaining) {
> > +       if (remaining && return_range) {
> >                 pnfs_set_plh_return_info(lo, return_range->iomode,
> > seq);
> >                 return -EBUSY;
> >         }
> >
> > -       if (!list_empty(&lo->plh_return_segs)) {
> > +       if (return_range && !list_empty(&lo->plh_return_segs)) {
> >                 pnfs_set_plh_return_info(lo, return_range->iomode,
> > seq);
> >                 return 0;
>
> This patch would mean we fail to mark the layout for return in
> situations where we clearly should be doing so. The lack of a
> return_range doesn't indicate that we don't want to return any layouts,
> but rather that we want to return all layouts.
>
> I suggest rather changing the caller, _pnfs_return_layout() to move
> that declaration of 'struct pnfs_layout_range range' out of the if
> statement so that it can be passed as an argument instead of NULL.

Sure, I'll try that now.

Thanks!
Anna

>
> >         }
>
> --
> Trond Myklebust
> Linux NFS client maintainer, Hammerspace
> trond.myklebust@hammerspace.com
>
>

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

end of thread, other threads:[~2021-05-19 16:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 16:06 [PATCH] NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return() schumaker.anna
2021-05-19 16:42 ` Trond Myklebust
2021-05-19 16:47   ` Anna Schumaker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.