[PATCH openEuler-1.0-LTS] NFS: Fix filehandle bounds checking in nfs_fh_to_dentry()

From: Trond Myklebust <trond.myklebust@hammerspace.com> mainline inclusion from mainline-v6.7-rc1 commit ef93a685e01a281b5e2a25ce4e3428cf9371a205 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/ICWRHG CVE: CVE-2025-39730 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- The function needs to check the minimal filehandle length before it can access the embedded filehandle. Reported-by: zhangjian <zhangjian496@huawei.com> Fixes: 20fa19027286 ("nfs: add export operations") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Conflicts: fs/nfs/export.c [The current branch has not introduced the mainline patch 2ef61e0eaa33 ("NFS: Remove the nfs4_label from the nfs4_getattr_res").] Signed-off-by: Wang Zhaolong <wangzhaolong@huaweicloud.com> --- fs/nfs/export.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/nfs/export.c b/fs/nfs/export.c index deecb67638aa..97b6fa0adb57 100644 --- a/fs/nfs/export.c +++ b/fs/nfs/export.c @@ -65,18 +65,25 @@ nfs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { struct nfs4_label *label = NULL; struct nfs_fattr *fattr = NULL; struct nfs_fh *server_fh = nfs_exp_embedfh(fid->raw); - size_t fh_size = offsetof(struct nfs_fh, data) + server_fh->size; + size_t fh_size = offsetof(struct nfs_fh, data); const struct nfs_rpc_ops *rpc_ops; struct dentry *dentry; struct inode *inode; - int len = EMBED_FH_OFF + XDR_QUADLEN(fh_size); + int len = EMBED_FH_OFF; u32 *p = fid->raw; int ret; + /* Initial check of bounds */ + if (fh_len < len + XDR_QUADLEN(fh_size) || + fh_len > XDR_QUADLEN(NFS_MAXFHSIZE)) + return NULL; + /* Calculate embedded filehandle size */ + fh_size += server_fh->size; + len += XDR_QUADLEN(fh_size); /* NULL translates to ESTALE */ if (fh_len < len || fh_type != len) return NULL; fattr = nfs_alloc_fattr(); -- 2.34.3

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17943 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/ZSG... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17943 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/ZSG...
participants (2)
-
patchwork bot
-
Wang Zhaolong