Skip to content

Commit ef93a68

Browse files
author
Trond Myklebust
committed
NFS: Fix filehandle bounds checking in nfs_fh_to_dentry()
The function needs to check the minimal filehandle length before it can access the embedded filehandle. Reported-by: zhangjian <[email protected]> Fixes: 20fa190 ("nfs: add export operations") Signed-off-by: Trond Myklebust <[email protected]>
1 parent f66e6bf commit ef93a68

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/nfs/export.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@ nfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
6666
{
6767
struct nfs_fattr *fattr = NULL;
6868
struct nfs_fh *server_fh = nfs_exp_embedfh(fid->raw);
69-
size_t fh_size = offsetof(struct nfs_fh, data) + server_fh->size;
69+
size_t fh_size = offsetof(struct nfs_fh, data);
7070
const struct nfs_rpc_ops *rpc_ops;
7171
struct dentry *dentry;
7272
struct inode *inode;
73-
int len = EMBED_FH_OFF + XDR_QUADLEN(fh_size);
73+
int len = EMBED_FH_OFF;
7474
u32 *p = fid->raw;
7575
int ret;
7676

77+
/* Initial check of bounds */
78+
if (fh_len < len + XDR_QUADLEN(fh_size) ||
79+
fh_len > XDR_QUADLEN(NFS_MAXFHSIZE))
80+
return NULL;
81+
/* Calculate embedded filehandle size */
82+
fh_size += server_fh->size;
83+
len += XDR_QUADLEN(fh_size);
7784
/* NULL translates to ESTALE */
7885
if (fh_len < len || fh_type != len)
7986
return NULL;

0 commit comments

Comments
 (0)