mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
261 lines
9.3 KiB
Diff
261 lines
9.3 KiB
Diff
From: Andreas Gruenbacher <agruen@suse.de>
|
|
Subject: Pass nameidata2 to vfs_rename()
|
|
|
|
Instead of passing independent dentry and vfsmount parameters, use a
|
|
nameidata2.
|
|
|
|
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
|
|
|
|
---
|
|
fs/ecryptfs/inode.c | 26 +++++++++++---------------
|
|
fs/namei.c | 45 ++++++++++++++++++++++++---------------------
|
|
fs/nfsd/vfs.c | 31 +++++++++++++++++--------------
|
|
include/linux/fs.h | 2 +-
|
|
4 files changed, 53 insertions(+), 51 deletions(-)
|
|
|
|
--- a/fs/ecryptfs/inode.c
|
|
+++ b/fs/ecryptfs/inode.c
|
|
@@ -586,33 +586,29 @@ static int
|
|
ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
{
|
|
+ struct nameidata2 old_nd = {};
|
|
+ struct nameidata2 new_nd = {};
|
|
int rc;
|
|
struct dentry *lower_old_dentry;
|
|
- struct vfsmount *lower_old_mnt;
|
|
struct dentry *lower_new_dentry;
|
|
- struct vfsmount *lower_new_mnt;
|
|
- struct dentry *lower_old_dir_dentry;
|
|
- struct dentry *lower_new_dir_dentry;
|
|
|
|
lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
|
|
- lower_old_mnt = ecryptfs_dentry_to_lower_mnt(old_dentry);
|
|
lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
|
|
- lower_new_mnt = ecryptfs_dentry_to_lower_mnt(new_dentry);
|
|
dget(lower_old_dentry);
|
|
dget(lower_new_dentry);
|
|
- lower_old_dir_dentry = dget_parent(lower_old_dentry);
|
|
- lower_new_dir_dentry = dget_parent(lower_new_dentry);
|
|
- lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
|
|
- rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
|
|
- lower_old_mnt, lower_new_dir_dentry->d_inode,
|
|
- lower_new_dentry, lower_new_mnt);
|
|
+ old_nd.dentry = dget_parent(lower_old_dentry);
|
|
+ old_nd.mnt = ecryptfs_dentry_to_lower_mnt(old_dentry);
|
|
+ new_nd.dentry = dget_parent(lower_new_dentry);
|
|
+ new_nd.mnt = ecryptfs_dentry_to_lower_mnt(new_dentry);
|
|
+ lock_rename(old_nd.dentry, new_nd.dentry);
|
|
+ rc = vfs_rename(&old_nd, lower_old_dentry, &new_nd, lower_new_dentry);
|
|
if (rc)
|
|
goto out_lock;
|
|
- fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL);
|
|
+ fsstack_copy_attr_all(new_dir, new_nd.dentry->d_inode, NULL);
|
|
if (new_dir != old_dir)
|
|
- fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL);
|
|
+ fsstack_copy_attr_all(old_dir, old_nd.dentry->d_inode, NULL);
|
|
out_lock:
|
|
- unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
|
|
+ unlock_rename(old_nd.dentry, new_nd.dentry);
|
|
dput(lower_new_dentry->d_parent);
|
|
dput(lower_old_dentry->d_parent);
|
|
dput(lower_new_dentry);
|
|
--- a/fs/namei.c
|
|
+++ b/fs/namei.c
|
|
@@ -2426,10 +2426,11 @@ asmlinkage long sys_link(const char __us
|
|
* ->i_mutex on parents, which works but leads to some truely excessive
|
|
* locking].
|
|
*/
|
|
-static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
|
|
- struct vfsmount *old_mnt, struct inode *new_dir,
|
|
- struct dentry *new_dentry, struct vfsmount *new_mnt)
|
|
+static int vfs_rename_dir(struct nameidata2 *old_nd, struct dentry *old_dentry,
|
|
+ struct nameidata2 *new_nd, struct dentry *new_dentry)
|
|
{
|
|
+ struct inode *old_dir = old_nd->dentry->d_inode;
|
|
+ struct inode *new_dir = new_nd->dentry->d_inode;
|
|
int error = 0;
|
|
struct inode *target;
|
|
|
|
@@ -2438,13 +2439,13 @@ static int vfs_rename_dir(struct inode *
|
|
* we'll need to flip '..'.
|
|
*/
|
|
if (new_dir != old_dir) {
|
|
- error = permission(old_dentry->d_inode, MAY_WRITE, NULL);
|
|
+ error = permission(old_dentry->d_inode, MAY_WRITE, old_nd);
|
|
if (error)
|
|
return error;
|
|
}
|
|
|
|
- error = security_inode_rename(old_dir, old_dentry, old_mnt,
|
|
- new_dir, new_dentry, new_mnt);
|
|
+ error = security_inode_rename(old_dir, old_dentry, old_nd->mnt,
|
|
+ new_dir, new_dentry, new_nd->mnt);
|
|
if (error)
|
|
return error;
|
|
|
|
@@ -2471,15 +2472,18 @@ static int vfs_rename_dir(struct inode *
|
|
return error;
|
|
}
|
|
|
|
-static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
|
|
- struct vfsmount *old_mnt, struct inode *new_dir,
|
|
- struct dentry *new_dentry, struct vfsmount *new_mnt)
|
|
+static int vfs_rename_other(struct nameidata2 *old_nd,
|
|
+ struct dentry *old_dentry,
|
|
+ struct nameidata2 *new_nd,
|
|
+ struct dentry *new_dentry)
|
|
{
|
|
+ struct inode *old_dir = old_nd->dentry->d_inode;
|
|
+ struct inode *new_dir = new_nd->dentry->d_inode;
|
|
struct inode *target;
|
|
int error;
|
|
|
|
- error = security_inode_rename(old_dir, old_dentry, old_mnt,
|
|
- new_dir, new_dentry, new_mnt);
|
|
+ error = security_inode_rename(old_dir, old_dentry, old_nd->mnt,
|
|
+ new_dir, new_dentry, new_nd->mnt);
|
|
if (error)
|
|
return error;
|
|
|
|
@@ -2501,10 +2505,11 @@ static int vfs_rename_other(struct inode
|
|
return error;
|
|
}
|
|
|
|
-int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
- struct vfsmount *old_mnt, struct inode *new_dir,
|
|
- struct dentry *new_dentry, struct vfsmount *new_mnt)
|
|
+int vfs_rename(struct nameidata2 *old_nd, struct dentry *old_dentry,
|
|
+ struct nameidata2 *new_nd, struct dentry *new_dentry)
|
|
{
|
|
+ struct inode *old_dir = old_nd->dentry->d_inode;
|
|
+ struct inode *new_dir = new_nd->dentry->d_inode;
|
|
int error;
|
|
int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
|
|
const char *old_name;
|
|
@@ -2517,7 +2522,7 @@ int vfs_rename(struct inode *old_dir, st
|
|
return error;
|
|
|
|
if (!new_dentry->d_inode)
|
|
- error = may_create(new_dir, new_dentry, NULL);
|
|
+ error = may_create(new_dir, new_dentry, new_nd);
|
|
else
|
|
error = may_delete(new_dir, new_dentry, is_dir);
|
|
if (error)
|
|
@@ -2532,11 +2537,10 @@ int vfs_rename(struct inode *old_dir, st
|
|
old_name = fsnotify_oldname_init(old_dentry->d_name.name);
|
|
|
|
if (is_dir)
|
|
- error = vfs_rename_dir(old_dir, old_dentry, old_mnt,
|
|
- new_dir, new_dentry, new_mnt);
|
|
+ error = vfs_rename_dir(old_nd, old_dentry, new_nd, new_dentry);
|
|
else
|
|
- error = vfs_rename_other(old_dir, old_dentry, old_mnt,
|
|
- new_dir, new_dentry, new_mnt);
|
|
+ error = vfs_rename_other(old_nd, old_dentry, new_nd,
|
|
+ new_dentry);
|
|
if (!error) {
|
|
const char *new_name = old_dentry->d_name.name;
|
|
fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
|
|
@@ -2608,8 +2612,7 @@ static int do_rename(int olddfd, const c
|
|
if (new_dentry == trap)
|
|
goto exit5;
|
|
|
|
- error = vfs_rename(old_dir->d_inode, old_dentry, oldnd.mnt,
|
|
- new_dir->d_inode, new_dentry, newnd.mnt);
|
|
+ error = vfs_rename(ND2(&oldnd), old_dentry, ND2(&newnd), new_dentry);
|
|
exit5:
|
|
dput(new_dentry);
|
|
exit4:
|
|
--- a/fs/nfsd/vfs.c
|
|
+++ b/fs/nfsd/vfs.c
|
|
@@ -1584,7 +1584,9 @@ __be32
|
|
nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
|
|
struct svc_fh *tfhp, char *tname, int tlen)
|
|
{
|
|
- struct dentry *fdentry, *tdentry, *odentry, *ndentry, *trap;
|
|
+ struct nameidata2 old_nd = {};
|
|
+ struct nameidata2 new_nd = {};
|
|
+ struct dentry *odentry, *ndentry, *trap;
|
|
struct inode *fdir, *tdir;
|
|
__be32 err;
|
|
int host_err;
|
|
@@ -1596,11 +1598,13 @@ nfsd_rename(struct svc_rqst *rqstp, stru
|
|
if (err)
|
|
goto out;
|
|
|
|
- fdentry = ffhp->fh_dentry;
|
|
- fdir = fdentry->d_inode;
|
|
-
|
|
- tdentry = tfhp->fh_dentry;
|
|
- tdir = tdentry->d_inode;
|
|
+ old_nd.dentry = ffhp->fh_dentry;
|
|
+ old_nd.mnt = ffhp->fh_export->ex_mnt;
|
|
+ fdir = old_nd.dentry->d_inode;
|
|
+
|
|
+ new_nd.dentry = tfhp->fh_dentry;
|
|
+ new_nd.mnt = tfhp->fh_export->ex_mnt;
|
|
+ tdir = new_nd.dentry->d_inode;
|
|
|
|
err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
|
|
if (ffhp->fh_export != tfhp->fh_export)
|
|
@@ -1612,12 +1616,12 @@ nfsd_rename(struct svc_rqst *rqstp, stru
|
|
|
|
/* cannot use fh_lock as we need deadlock protective ordering
|
|
* so do it by hand */
|
|
- trap = lock_rename(tdentry, fdentry);
|
|
+ trap = lock_rename(new_nd.dentry, old_nd.dentry);
|
|
ffhp->fh_locked = tfhp->fh_locked = 1;
|
|
fill_pre_wcc(ffhp);
|
|
fill_pre_wcc(tfhp);
|
|
|
|
- odentry = lookup_one_len(fname, fdentry, flen);
|
|
+ odentry = lookup_one_len(fname, old_nd.dentry, flen);
|
|
host_err = PTR_ERR(odentry);
|
|
if (IS_ERR(odentry))
|
|
goto out_nfserr;
|
|
@@ -1629,7 +1633,7 @@ nfsd_rename(struct svc_rqst *rqstp, stru
|
|
if (odentry == trap)
|
|
goto out_dput_old;
|
|
|
|
- ndentry = lookup_one_len(tname, tdentry, tlen);
|
|
+ ndentry = lookup_one_len(tname, new_nd.dentry, tlen);
|
|
host_err = PTR_ERR(ndentry);
|
|
if (IS_ERR(ndentry))
|
|
goto out_dput_old;
|
|
@@ -1644,12 +1648,11 @@ nfsd_rename(struct svc_rqst *rqstp, stru
|
|
host_err = -EPERM;
|
|
} else
|
|
#endif
|
|
- host_err = vfs_rename(fdir, odentry, ffhp->fh_export->ex_mnt,
|
|
- tdir, ndentry, tfhp->fh_export->ex_mnt);
|
|
+ host_err = vfs_rename(&old_nd, odentry, &new_nd, ndentry);
|
|
if (!host_err && EX_ISSYNC(tfhp->fh_export)) {
|
|
- host_err = nfsd_sync_dir(tdentry);
|
|
+ host_err = nfsd_sync_dir(new_nd.dentry);
|
|
if (!host_err)
|
|
- host_err = nfsd_sync_dir(fdentry);
|
|
+ host_err = nfsd_sync_dir(old_nd.dentry);
|
|
}
|
|
|
|
out_dput_new:
|
|
@@ -1665,7 +1668,7 @@ nfsd_rename(struct svc_rqst *rqstp, stru
|
|
*/
|
|
fill_post_wcc(ffhp);
|
|
fill_post_wcc(tfhp);
|
|
- unlock_rename(tdentry, fdentry);
|
|
+ unlock_rename(new_nd.dentry, old_nd.dentry);
|
|
ffhp->fh_locked = tfhp->fh_locked = 0;
|
|
|
|
out:
|
|
--- a/include/linux/fs.h
|
|
+++ b/include/linux/fs.h
|
|
@@ -995,7 +995,7 @@ extern int vfs_symlink(struct nameidata2
|
|
extern int vfs_link(struct nameidata2 *, struct dentry *, struct nameidata2 *);
|
|
extern int vfs_rmdir(struct inode *, struct dentry *, struct vfsmount *);
|
|
extern int vfs_unlink(struct inode *, struct dentry *, struct vfsmount *);
|
|
-extern int vfs_rename(struct inode *, struct dentry *, struct vfsmount *, struct inode *, struct dentry *, struct vfsmount *);
|
|
+extern int vfs_rename(struct nameidata2 *, struct dentry *, struct nameidata2 *, struct dentry *);
|
|
|
|
/*
|
|
* VFS dentry helper functions.
|