NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return()
Subsystems (2)
PATCH 1/1 NFSv4: Fix a NULL pointer dereference in pnfs_mark_matching_lsegs_return()
From: Anna Schumaker <[email protected]>
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.
--- fs/nfs/pnfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/pnfs.c +2 -2
@@ -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 ; }
Signature · 1 line
2.29.2
Quoted 29 lines · On Wed, 2021-05-19 at 12:06 -0400, [email protected] wrote:
From: Anna Schumaker <[email protected]>
Commit
de144ff4234fchanges_pnfs_return_layout()to callpnfs_mark_matching_lsegs_return()passing NULL as the structpnfs_layout_rangeargument. 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 returnin
_pnfs_return_layout()")Signed-off-by Anna Schumaker <[email protected]>---
fs/nfs/pnfs.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)fs/nfs/pnfs.c +0
-0@@ -2484,12 +2484,12 @@ pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo,set_bit(NFS_LSEG_LAYOUTRETURN, &lseg-
Quoted 1 line
pls_flags);
Quoted 14 lines
}
- 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.
Quoted 1 line
}
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 46 lines · Trond Myklebust
Quoted 40 lines · On Wed, 2021-05-19 at 12:06 -0400, [email protected] wrote:
From: Anna Schumaker <[email protected]>
Commit
de144ff4234fchanges_pnfs_return_layout()to callpnfs_mark_matching_lsegs_return()passing NULL as the structpnfs_layout_rangeargument. 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 returnin
_pnfs_return_layout()")Signed-off-by Anna Schumaker <[email protected]>--- fs/nfs/pnfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/nfs/pnfs.c +2
-2@@ -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)) {Quoted 3 lines
pnfs_set_plh_return_info(lo, return_range->iomode, seq); return 0;
Quoted 8 lines
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_rangedoesn'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 'structpnfs_layout_rangerange' 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
Quoted 9 lines
Quoted 2 lines
}--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]