Skip to content

Commit

Permalink
aufs: bugfix, support for selinux
Browse files Browse the repository at this point in the history
SELinux's d_instantiate hook calls __vfs_getxattr() BEFORE d_inode is
set.  Aufs should not rely upon d_inode and should use the parameter
inode instead.

Reported-by: "jon bird" <news@onasticksoftware.co.uk>
Signed-off-by: J. R. Okajima <hooanon05g@gmail.com>
  • Loading branch information
sfjro committed May 13, 2020
1 parent 747a01e commit 5777718
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 9 additions & 5 deletions fs/aufs/i_op.c
Expand Up @@ -1183,15 +1183,14 @@ static void au_refresh_iattr(struct inode *inode, struct kstat *st,
* returns zero or negative (an error).
* @dentry will be read-locked in success.
*/
int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
int locked)
int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
struct path *h_path, int locked)
{
int err;
unsigned int mnt_flags, sigen;
unsigned char udba_none;
aufs_bindex_t bindex;
struct super_block *sb, *h_sb;
struct inode *inode;

h_path->mnt = NULL;
h_path->dentry = NULL;
Expand Down Expand Up @@ -1232,7 +1231,11 @@ int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
di_read_lock_child(dentry, AuLock_IR);

body:
inode = d_inode(dentry);
if (!inode) {
inode = d_inode(dentry);
if (unlikely(!inode))
goto out;
}
bindex = au_ibtop(inode);
h_path->mnt = au_sbr_mnt(sb, bindex);
h_sb = h_path->mnt->mnt_sb;
Expand Down Expand Up @@ -1272,7 +1275,8 @@ static int aufs_getattr(const struct path *path, struct kstat *st,
err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
if (unlikely(err))
goto out;
err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
/*locked*/0);
if (unlikely(err))
goto out_si;
if (unlikely(!h_path.dentry))
Expand Down
4 changes: 2 additions & 2 deletions fs/aufs/inode.h
Expand Up @@ -207,8 +207,8 @@ struct au_icpup_args {
int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
struct au_icpup_args *a);

int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
int locked);
int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
struct path *h_path, int locked);

/* i_op_add.c */
int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
Expand Down
14 changes: 7 additions & 7 deletions fs/aufs/xattr.c
Expand Up @@ -194,7 +194,7 @@ int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,

static int au_smack_reentering(struct super_block *sb)
{
#if IS_ENABLED(CONFIG_SECURITY_SMACK)
#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
/*
* as a part of lookup, smack_d_instantiate() is called, and it calls
* i_op->getxattr(). ouch.
Expand Down Expand Up @@ -225,7 +225,8 @@ struct au_lgxattr {
} u;
};

static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
struct au_lgxattr *arg)
{
ssize_t err;
int reenter;
Expand All @@ -239,7 +240,7 @@ static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
if (unlikely(err))
goto out;
}
err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
if (unlikely(err))
goto out_si;
if (unlikely(!h_path.dentry))
Expand Down Expand Up @@ -281,11 +282,10 @@ ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
},
};

return au_lgxattr(dentry, &arg);
return au_lgxattr(dentry, /*inode*/NULL, &arg);
}

static ssize_t au_getxattr(struct dentry *dentry,
struct inode *inode __maybe_unused,
static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
const char *name, void *value, size_t size)
{
struct au_lgxattr arg = {
Expand All @@ -297,7 +297,7 @@ static ssize_t au_getxattr(struct dentry *dentry,
},
};

return au_lgxattr(dentry, &arg);
return au_lgxattr(dentry, inode, &arg);
}

static int au_setxattr(struct dentry *dentry, struct inode *inode,
Expand Down

0 comments on commit 5777718

Please sign in to comment.