[PATCH] r/o bind mounts: get callers of vfs_mknod/create/mkdir()
This takes care of all of the direct callers of vfs_mknod(). Since a few of these cases also handle normal file creation as well, this also covers some calls to vfs_create(). So that we don't have to make three mnt_want/drop_write() calls inside of the switch statement, we move some of its logic outside of the switch and into a helper function suggested by Christoph. This also encapsulates a fix for mknod(S_IFREG) that Miklos found. [AV: merged mkdir handling, added missing nfsd pieces] Acked-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
0622753b80
commit
463c319726
4 changed files with 68 additions and 14 deletions
48
fs/namei.c
48
fs/namei.c
|
@ -1984,6 +1984,23 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int may_mknod(mode_t mode)
|
||||||
|
{
|
||||||
|
switch (mode & S_IFMT) {
|
||||||
|
case S_IFREG:
|
||||||
|
case S_IFCHR:
|
||||||
|
case S_IFBLK:
|
||||||
|
case S_IFIFO:
|
||||||
|
case S_IFSOCK:
|
||||||
|
case 0: /* zero mode translates to S_IFREG */
|
||||||
|
return 0;
|
||||||
|
case S_IFDIR:
|
||||||
|
return -EPERM;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
|
asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
|
||||||
unsigned dev)
|
unsigned dev)
|
||||||
{
|
{
|
||||||
|
@ -2002,12 +2019,19 @@ asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
dentry = lookup_create(&nd, 0);
|
dentry = lookup_create(&nd, 0);
|
||||||
error = PTR_ERR(dentry);
|
if (IS_ERR(dentry)) {
|
||||||
|
error = PTR_ERR(dentry);
|
||||||
|
goto out_unlock;
|
||||||
|
}
|
||||||
if (!IS_POSIXACL(nd.path.dentry->d_inode))
|
if (!IS_POSIXACL(nd.path.dentry->d_inode))
|
||||||
mode &= ~current->fs->umask;
|
mode &= ~current->fs->umask;
|
||||||
if (!IS_ERR(dentry)) {
|
error = may_mknod(mode);
|
||||||
switch (mode & S_IFMT) {
|
if (error)
|
||||||
|
goto out_dput;
|
||||||
|
error = mnt_want_write(nd.path.mnt);
|
||||||
|
if (error)
|
||||||
|
goto out_dput;
|
||||||
|
switch (mode & S_IFMT) {
|
||||||
case 0: case S_IFREG:
|
case 0: case S_IFREG:
|
||||||
error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
|
error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
|
||||||
break;
|
break;
|
||||||
|
@ -2018,14 +2042,11 @@ asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
|
||||||
case S_IFIFO: case S_IFSOCK:
|
case S_IFIFO: case S_IFSOCK:
|
||||||
error = vfs_mknod(nd.path.dentry->d_inode,dentry,mode,0);
|
error = vfs_mknod(nd.path.dentry->d_inode,dentry,mode,0);
|
||||||
break;
|
break;
|
||||||
case S_IFDIR:
|
|
||||||
error = -EPERM;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error = -EINVAL;
|
|
||||||
}
|
|
||||||
dput(dentry);
|
|
||||||
}
|
}
|
||||||
|
mnt_drop_write(nd.path.mnt);
|
||||||
|
out_dput:
|
||||||
|
dput(dentry);
|
||||||
|
out_unlock:
|
||||||
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
|
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
|
||||||
path_put(&nd.path);
|
path_put(&nd.path);
|
||||||
out:
|
out:
|
||||||
|
@ -2083,7 +2104,12 @@ asmlinkage long sys_mkdirat(int dfd, const char __user *pathname, int mode)
|
||||||
|
|
||||||
if (!IS_POSIXACL(nd.path.dentry->d_inode))
|
if (!IS_POSIXACL(nd.path.dentry->d_inode))
|
||||||
mode &= ~current->fs->umask;
|
mode &= ~current->fs->umask;
|
||||||
|
error = mnt_want_write(nd.path.mnt);
|
||||||
|
if (error)
|
||||||
|
goto out_dput;
|
||||||
error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
|
error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
|
||||||
|
mnt_drop_write(nd.path.mnt);
|
||||||
|
out_dput:
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
|
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
|
||||||
|
|
|
@ -155,7 +155,11 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
|
||||||
dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
|
dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
|
||||||
goto out_put;
|
goto out_put;
|
||||||
}
|
}
|
||||||
|
status = mnt_want_write(rec_dir.path.mnt);
|
||||||
|
if (status)
|
||||||
|
goto out_put;
|
||||||
status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU);
|
status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU);
|
||||||
|
mnt_drop_write(rec_dir.path.mnt);
|
||||||
out_put:
|
out_put:
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
out_unlock:
|
out_unlock:
|
||||||
|
|
|
@ -1255,23 +1255,35 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
err = 0;
|
err = 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
|
host_err = mnt_want_write(fhp->fh_export->ex_path.mnt);
|
||||||
|
if (host_err)
|
||||||
|
goto out_nfserr;
|
||||||
host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
|
host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
|
||||||
break;
|
break;
|
||||||
case S_IFDIR:
|
case S_IFDIR:
|
||||||
|
host_err = mnt_want_write(fhp->fh_export->ex_path.mnt);
|
||||||
|
if (host_err)
|
||||||
|
goto out_nfserr;
|
||||||
host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
|
host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
|
||||||
break;
|
break;
|
||||||
case S_IFCHR:
|
case S_IFCHR:
|
||||||
case S_IFBLK:
|
case S_IFBLK:
|
||||||
case S_IFIFO:
|
case S_IFIFO:
|
||||||
case S_IFSOCK:
|
case S_IFSOCK:
|
||||||
|
host_err = mnt_want_write(fhp->fh_export->ex_path.mnt);
|
||||||
|
if (host_err)
|
||||||
|
goto out_nfserr;
|
||||||
host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
|
host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printk("nfsd: bad file type %o in nfsd_create\n", type);
|
printk("nfsd: bad file type %o in nfsd_create\n", type);
|
||||||
host_err = -EINVAL;
|
host_err = -EINVAL;
|
||||||
}
|
|
||||||
if (host_err < 0)
|
|
||||||
goto out_nfserr;
|
goto out_nfserr;
|
||||||
|
}
|
||||||
|
if (host_err < 0) {
|
||||||
|
mnt_drop_write(fhp->fh_export->ex_path.mnt);
|
||||||
|
goto out_nfserr;
|
||||||
|
}
|
||||||
|
|
||||||
if (EX_ISSYNC(fhp->fh_export)) {
|
if (EX_ISSYNC(fhp->fh_export)) {
|
||||||
err = nfserrno(nfsd_sync_dir(dentry));
|
err = nfserrno(nfsd_sync_dir(dentry));
|
||||||
|
@ -1282,6 +1294,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
err2 = nfsd_create_setattr(rqstp, resfhp, iap);
|
err2 = nfsd_create_setattr(rqstp, resfhp, iap);
|
||||||
if (err2)
|
if (err2)
|
||||||
err = err2;
|
err = err2;
|
||||||
|
mnt_drop_write(fhp->fh_export->ex_path.mnt);
|
||||||
/*
|
/*
|
||||||
* Update the file handle to get the new inode info.
|
* Update the file handle to get the new inode info.
|
||||||
*/
|
*/
|
||||||
|
@ -1359,6 +1372,9 @@ nfsd_create_v3(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
v_atime = verifier[1]&0x7fffffff;
|
v_atime = verifier[1]&0x7fffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host_err = mnt_want_write(fhp->fh_export->ex_path.mnt);
|
||||||
|
if (host_err)
|
||||||
|
goto out_nfserr;
|
||||||
if (dchild->d_inode) {
|
if (dchild->d_inode) {
|
||||||
err = 0;
|
err = 0;
|
||||||
|
|
||||||
|
@ -1390,12 +1406,15 @@ nfsd_create_v3(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
case NFS3_CREATE_GUARDED:
|
case NFS3_CREATE_GUARDED:
|
||||||
err = nfserr_exist;
|
err = nfserr_exist;
|
||||||
}
|
}
|
||||||
|
mnt_drop_write(fhp->fh_export->ex_path.mnt);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
|
host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
|
||||||
if (host_err < 0)
|
if (host_err < 0) {
|
||||||
|
mnt_drop_write(fhp->fh_export->ex_path.mnt);
|
||||||
goto out_nfserr;
|
goto out_nfserr;
|
||||||
|
}
|
||||||
if (created)
|
if (created)
|
||||||
*created = 1;
|
*created = 1;
|
||||||
|
|
||||||
|
@ -1420,6 +1439,7 @@ nfsd_create_v3(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
if (err2)
|
if (err2)
|
||||||
err = err2;
|
err = err2;
|
||||||
|
|
||||||
|
mnt_drop_write(fhp->fh_export->ex_path.mnt);
|
||||||
/*
|
/*
|
||||||
* Update the filehandle to get the new inode info.
|
* Update the filehandle to get the new inode info.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -819,7 +819,11 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
|
||||||
*/
|
*/
|
||||||
mode = S_IFSOCK |
|
mode = S_IFSOCK |
|
||||||
(SOCK_INODE(sock)->i_mode & ~current->fs->umask);
|
(SOCK_INODE(sock)->i_mode & ~current->fs->umask);
|
||||||
|
err = mnt_want_write(nd.path.mnt);
|
||||||
|
if (err)
|
||||||
|
goto out_mknod_dput;
|
||||||
err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
|
err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
|
||||||
|
mnt_drop_write(nd.path.mnt);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_mknod_dput;
|
goto out_mknod_dput;
|
||||||
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
|
mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
|
||||||
|
|
Loading…
Reference in a new issue