Skip to content

Commit e1c6cfb

Browse files
Trond Myklebustamschuma-ntap
authored andcommitted
pNFS/flexfiles: Check the layout validity in ff_layout_mirror_prepare_stats
Ensure that we check the layout pointer and validity after dereferencing it in ff_layout_mirror_prepare_stats. Fixes: 08e2e5b ("pNFS/flexfiles: Clean up layoutstats") Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent f639557 commit e1c6cfb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,9 +2520,9 @@ ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,
25202520
return i;
25212521
}
25222522

2523-
static int
2524-
ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
2523+
static int ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
25252524
{
2525+
struct pnfs_layout_hdr *lo;
25262526
struct nfs4_flexfile_layout *ff_layout;
25272527
const int dev_count = PNFS_LAYOUTSTATS_MAXDEV;
25282528

@@ -2533,11 +2533,14 @@ ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
25332533
return -ENOMEM;
25342534

25352535
spin_lock(&args->inode->i_lock);
2536-
ff_layout = FF_LAYOUT_FROM_HDR(NFS_I(args->inode)->layout);
2537-
args->num_dev = ff_layout_mirror_prepare_stats(&ff_layout->generic_hdr,
2538-
&args->devinfo[0],
2539-
dev_count,
2540-
NFS4_FF_OP_LAYOUTSTATS);
2536+
lo = NFS_I(args->inode)->layout;
2537+
if (lo && pnfs_layout_is_valid(lo)) {
2538+
ff_layout = FF_LAYOUT_FROM_HDR(lo);
2539+
args->num_dev = ff_layout_mirror_prepare_stats(
2540+
&ff_layout->generic_hdr, &args->devinfo[0], dev_count,
2541+
NFS4_FF_OP_LAYOUTSTATS);
2542+
} else
2543+
args->num_dev = 0;
25412544
spin_unlock(&args->inode->i_lock);
25422545
if (!args->num_dev) {
25432546
kfree(args->devinfo);

0 commit comments

Comments
 (0)