LAYOUTGET expects the current filehandle to identify a file, but nfsd4_layoutget() passes a zero type to fh_verify(). An authenticated NFSv4.1 client can therefore request an RW block layout for a directory. With a nonzero minimum length, the block layout provider asks the filesystem to allocate the requested range. On XFS this can create noncontiguous directory data blocks. A later CREATE can then index beyond the leaf directory bests table and cause a two-byte heap out-of-bounds write. Check the dentry type after fh_verify() so its security and access checks retain their existing order. Return NFS4ERR_WRONG_TYPE for non-regular files before any layout provider or filesystem callback is invoked. Validation used an arm64 kernel with 64 KiB pages, Generic KASAN, and lockdep. The full kernel built with GCC 13.3 and CONFIG_WERROR=y; the changed object also built with W=1. The unpatched three-block directory layout trigger reproduced the out-of-bounds write twice. With this change, directory and symlink LAYOUTGET requests returned NFS4ERR_WRONG_TYPE, while a regular-file LAYOUTGET succeeded. The CREATE following the directory request and NFSv4.1 mount, write/readback, and unmount tests completed without a KASAN, Oops, or panic report. The patched behavior was confirmed on the nfsd-testing base shown below. Fixes: 9cf514ccfacb ("nfsd: implement pNFS operations") Cc: stable@vger.kernel.org Signed-off-by: Jiwoong Wi --- fs/nfsd/nfs4proc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index bb149a3e9a..92a92b3e6d 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -3082,6 +3082,10 @@ nfsd4_layoutget(struct svc_rqst *rqstp, nfserr = fh_verify(rqstp, current_fh, 0, accmode); if (nfserr) goto out; + if (!d_is_reg(current_fh->fh_dentry)) { + nfserr = nfserr_wrong_type; + goto out; + } nfserr = nfserr_layoutunavailable; ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); base-commit: 36fd4049e3c2bb901118e11be63bf7a7922bea8c -- 2.50.1 (Apple Git-155)