LAYOUTGET expects the current filehandle to identify a regular file, but nfsd4_layoutget() passes a zero type to fh_verify(). A client can obtain a directory delegation via GET_DIR_DELEGATION and use its stateid with the matching directory filehandle. This passes the filehandle match in nfsd4_preprocess_layout_stateid(), allowing an RW block layout for the 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. Fixes: 8b99f6a8c116 ("nfsd: wire up GET_DIR_DELEGATION handling") Link: https://lore.kernel.org/r/dded948f-dfdb-4919-aae1-bf84147bcd72@slotpi15m67/ Cc: stable@vger.kernel.org Signed-off-by: Jiwoong Wi --- Changes since v1: - Explain the GET_DIR_DELEGATION prerequisite. - Correct the Fixes tag. - Add a separate LAYOUTCOMMIT fix as patch 2/2. v1: https://lore.kernel.org/r/20261130070511.65684-1-dwdnlzj@gmail.com/ 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: 3c6328ce32970f15f882ff3c6ab1b1648723b000 -- 2.50.1 (Apple Git-155)