Skip to content

Commit dd862da

Browse files
neilbrownAnna Schumaker
authored andcommitted
nfs: fix incorrect handling of large-number NFS errors in nfs4_do_mkdir()
A recent commit introduced nfs4_do_mkdir() which reports an error from nfs4_call_sync() by returning it with ERR_PTR(). This is a problem as nfs4_call_sync() can return negative NFS-specific errors with values larger than MAX_ERRNO (4095). One example is NFS4ERR_DELAY which has value 10008. This "pointer" gets to PTR_ERR_OR_ZERO() in nfs4_proc_mkdir() which chooses ZERO because it isn't in the range of value errors. Ultimately the pointer is dereferenced. This patch changes nfs4_do_mkdir() to report the dentry pointer and status separately - pointer as a return value, status in an "int *" parameter. The same separation is used for _nfs4_proc_mkdir() and the two are combined only in nfs4_proc_mkdir() after the status has passed through nfs4_handle_exception(), which ensures the error code does not exceed MAX_ERRNO. It also fixes a problem in the even when nfs4_handle_exception() updated the error value, the original 'alias' was still returned. Reported-by: Anna Schumaker <[email protected]> Fixes: 8376583 ("nfs: change mkdir inode_operation to return alternate dentry if needed.") Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 80c4de6 commit dd862da

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

fs/nfs/nfs4proc.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,13 +5164,15 @@ static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_
51645164
}
51655165

51665166
static struct dentry *nfs4_do_mkdir(struct inode *dir, struct dentry *dentry,
5167-
struct nfs4_createdata *data)
5167+
struct nfs4_createdata *data, int *statusp)
51685168
{
5169-
int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
5169+
struct dentry *ret;
5170+
5171+
*statusp = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
51705172
&data->arg.seq_args, &data->res.seq_res, 1);
51715173

5172-
if (status)
5173-
return ERR_PTR(status);
5174+
if (*statusp)
5175+
return NULL;
51745176

51755177
spin_lock(&dir->i_lock);
51765178
/* Creating a directory bumps nlink in the parent */
@@ -5179,7 +5181,11 @@ static struct dentry *nfs4_do_mkdir(struct inode *dir, struct dentry *dentry,
51795181
data->res.fattr->time_start,
51805182
NFS_INO_INVALID_DATA);
51815183
spin_unlock(&dir->i_lock);
5182-
return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr);
5184+
ret = nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr);
5185+
if (!IS_ERR(ret))
5186+
return ret;
5187+
*statusp = PTR_ERR(ret);
5188+
return NULL;
51835189
}
51845190

51855191
static void nfs4_free_createdata(struct nfs4_createdata *data)
@@ -5240,17 +5246,18 @@ static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
52405246

52415247
static struct dentry *_nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
52425248
struct iattr *sattr,
5243-
struct nfs4_label *label)
5249+
struct nfs4_label *label, int *statusp)
52445250
{
52455251
struct nfs4_createdata *data;
5246-
struct dentry *ret = ERR_PTR(-ENOMEM);
5252+
struct dentry *ret = NULL;
52475253

5254+
*statusp = -ENOMEM;
52485255
data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
52495256
if (data == NULL)
52505257
goto out;
52515258

52525259
data->arg.label = label;
5253-
ret = nfs4_do_mkdir(dir, dentry, data);
5260+
ret = nfs4_do_mkdir(dir, dentry, data, statusp);
52545261

52555262
nfs4_free_createdata(data);
52565263
out:
@@ -5273,11 +5280,12 @@ static struct dentry *nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
52735280
if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
52745281
sattr->ia_mode &= ~current_umask();
52755282
do {
5276-
alias = _nfs4_proc_mkdir(dir, dentry, sattr, label);
5277-
err = PTR_ERR_OR_ZERO(alias);
5283+
alias = _nfs4_proc_mkdir(dir, dentry, sattr, label, &err);
52785284
trace_nfs4_mkdir(dir, &dentry->d_name, err);
5279-
err = nfs4_handle_exception(NFS_SERVER(dir), err,
5280-
&exception);
5285+
if (err)
5286+
alias = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
5287+
err,
5288+
&exception));
52815289
} while (exception.retry);
52825290
nfs4_label_release_security(label);
52835291

0 commit comments

Comments
 (0)