apparmor/kernel-patches/for-mainline/vfs_symlink-args.diff

163 lines
5.4 KiB
Diff

From: Andreas Gruenbacher <agruen@suse.de>
Subject: Pass nameidata2 to vfs_symlink()
Instead of passing independent dentry and vfsmount parameters, use a
nameidata2.
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
fs/ecryptfs/inode.c | 16 +++++++---------
fs/namei.c | 10 +++++-----
fs/nfsd/vfs.c | 18 +++++++++---------
include/linux/fs.h | 2 +-
4 files changed, 22 insertions(+), 24 deletions(-)
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -474,10 +474,9 @@ out_unlock:
static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
const char *symname)
{
+ struct nameidata2 nd = {};
int rc;
struct dentry *lower_dentry;
- struct vfsmount *lower_mnt;
- struct dentry *lower_dir_dentry;
umode_t mode;
char *encoded_symname;
unsigned int encoded_symlen;
@@ -485,8 +484,8 @@ static int ecryptfs_symlink(struct inode
lower_dentry = ecryptfs_dentry_to_lower(dentry);
dget(lower_dentry);
- lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
- lower_dir_dentry = lock_parent(lower_dentry);
+ nd.mnt = ecryptfs_dentry_to_lower_mnt(dentry);
+ nd.dentry = lock_parent(lower_dentry);
mode = S_IALLUGO;
encoded_symlen = ecryptfs_encode_filename(crypt_stat, symname,
strlen(symname),
@@ -495,18 +494,17 @@ static int ecryptfs_symlink(struct inode
rc = encoded_symlen;
goto out_lock;
}
- rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry, lower_mnt,
- encoded_symname, mode);
+ rc = vfs_symlink(&nd, lower_dentry, encoded_symname, mode);
kfree(encoded_symname);
if (rc || !lower_dentry->d_inode)
goto out_lock;
rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
if (rc)
goto out_lock;
- fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
- fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
+ fsstack_copy_attr_times(dir, nd.dentry->d_inode);
+ fsstack_copy_inode_size(dir, nd.dentry->d_inode);
out_lock:
- unlock_dir(lower_dir_dentry);
+ unlock_dir(nd.dentry);
dput(lower_dentry);
if (!dentry->d_inode)
d_drop(dentry);
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2228,10 +2228,11 @@ asmlinkage long sys_unlink(const char __
return do_unlinkat(AT_FDCWD, pathname);
}
-int vfs_symlink(struct inode *dir, struct dentry *dentry, struct vfsmount *mnt,
+int vfs_symlink(struct nameidata2 *nd, struct dentry *dentry,
const char *oldname, int mode)
{
- int error = may_create(dir, dentry, NULL);
+ struct inode *dir = nd->dentry->d_inode;
+ int error = may_create(dir, dentry, nd);
if (error)
return error;
@@ -2239,7 +2240,7 @@ int vfs_symlink(struct inode *dir, struc
if (!dir->i_op || !dir->i_op->symlink)
return -EPERM;
- error = security_inode_symlink(dir, dentry, mnt, oldname);
+ error = security_inode_symlink(dir, dentry, nd->mnt, oldname);
if (error)
return error;
@@ -2275,8 +2276,7 @@ asmlinkage long sys_symlinkat(const char
if (IS_ERR(dentry))
goto out_unlock;
- error = vfs_symlink(nd.dentry->d_inode, dentry, nd.mnt, from,
- S_IALLUGO);
+ error = vfs_symlink(ND2(&nd), dentry, from, S_IALLUGO);
dput(dentry);
out_unlock:
mutex_unlock(&nd.dentry->d_inode->i_mutex);
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1447,7 +1447,8 @@ nfsd_symlink(struct svc_rqst *rqstp, str
struct svc_fh *resfhp,
struct iattr *iap)
{
- struct dentry *dentry, *dnew;
+ struct nameidata2 nd = {};
+ struct dentry *dnew;
struct svc_export *exp;
__be32 err, cerr;
int host_err;
@@ -1464,8 +1465,10 @@ nfsd_symlink(struct svc_rqst *rqstp, str
if (err)
goto out;
fh_lock(fhp);
- dentry = fhp->fh_dentry;
- dnew = lookup_one_len(fname, dentry, flen);
+ nd.dentry = fhp->fh_dentry;
+ exp = fhp->fh_export;
+ nd.mnt = exp->ex_mnt;
+ dnew = lookup_one_len(fname, nd.dentry, flen);
host_err = PTR_ERR(dnew);
if (IS_ERR(dnew))
goto out_nfserr;
@@ -1475,7 +1478,6 @@ nfsd_symlink(struct svc_rqst *rqstp, str
if (iap && (iap->ia_valid & ATTR_MODE))
mode = iap->ia_mode & S_IALLUGO;
- exp = fhp->fh_export;
if (unlikely(path[plen] != 0)) {
char *path_alloced = kmalloc(plen+1, GFP_KERNEL);
if (path_alloced == NULL)
@@ -1483,17 +1485,15 @@ nfsd_symlink(struct svc_rqst *rqstp, str
else {
strncpy(path_alloced, path, plen);
path_alloced[plen] = 0;
- host_err = vfs_symlink(dentry->d_inode, dnew,
- exp->ex_mnt, path_alloced, mode);
+ host_err = vfs_symlink(&nd, dnew, path_alloced, mode);
kfree(path_alloced);
}
} else
- host_err = vfs_symlink(dentry->d_inode, dnew, exp->ex_mnt, path,
- mode);
+ host_err = vfs_symlink(&nd, dnew, path, mode);
if (!host_err) {
if (EX_ISSYNC(exp))
- host_err = nfsd_sync_dir(dentry);
+ host_err = nfsd_sync_dir(nd.dentry);
}
err = nfserrno(host_err);
fh_unlock(fhp);
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -991,7 +991,7 @@ extern int vfs_permission(struct nameida
extern int vfs_create(struct nameidata2 *, struct dentry *, int);
extern int vfs_mkdir(struct nameidata2 *, struct dentry *, int);
extern int vfs_mknod(struct nameidata2 *, struct dentry *, int, dev_t);
-extern int vfs_symlink(struct inode *, struct dentry *, struct vfsmount *, const char *, int);
+extern int vfs_symlink(struct nameidata2 *, struct dentry *, const char *, int);
extern int vfs_link(struct dentry *, struct vfsmount *, struct inode *, struct dentry *, struct vfsmount *);
extern int vfs_rmdir(struct inode *, struct dentry *, struct vfsmount *);
extern int vfs_unlink(struct inode *, struct dentry *, struct vfsmount *);