Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
reiserfs: fix extended attributes on the root directory
Browse files Browse the repository at this point in the history
commit 60e4cf67a582d64f07713eda5fcc8ccdaf7833e6 upstream.

Since commit d0a5b99 (vfs: Add IOP_XATTR inode operations flag)
extended attributes haven't worked on the root directory in reiserfs.

This is due to reiserfs conditionally setting the sb->s_xattrs handler
array depending on whether it located or create the internal privroot
directory.  It necessarily does this after the root inode is already
read in.  The IOP_XATTR flag is set during inode initialization, so
it never gets set on the root directory.

This commit unconditionally assigns sb->s_xattrs and clears IOP_XATTR on
internal inodes.  The old return values due to the conditional assignment
are handled via open_xa_root, which now returns EOPNOTSUPP as the VFS
would have done.

Link: https://lore.kernel.org/r/20191024143127.17509-1-jeffm@suse.com
CC: stable@vger.kernel.org
Fixes: d0a5b99 ("vfs: Add IOP_XATTR inode operations flag")
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
jeffmahoney authored and isjerryxiao committed Dec 17, 2019
1 parent bb5f465 commit f7caaf0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
12 changes: 10 additions & 2 deletions fs/reiserfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,15 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
goto out_inserted_sd;
}

/*
* Mark it private if we're creating the privroot
* or something under it.
*/
if (IS_PRIVATE(dir) || dentry == REISERFS_SB(sb)->priv_root) {
inode->i_flags |= S_PRIVATE;
inode->i_opflags &= ~IOP_XATTR;
}

if (reiserfs_posixacl(inode->i_sb)) {
reiserfs_write_unlock(inode->i_sb);
retval = reiserfs_inherit_default_acl(th, dir, dentry, inode);
Expand All @@ -2111,8 +2120,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
reiserfs_warning(inode->i_sb, "jdm-13090",
"ACLs aren't enabled in the fs, "
"but vfs thinks they are!");
} else if (IS_PRIVATE(dir))
inode->i_flags |= S_PRIVATE;
}

if (security->name) {
reiserfs_write_unlock(inode->i_sb);
Expand Down
7 changes: 5 additions & 2 deletions fs/reiserfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,13 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,

/*
* Propagate the private flag so we know we're
* in the priv tree
* in the priv tree. Also clear IOP_XATTR
* since we don't have xattrs on xattr files.
*/
if (IS_PRIVATE(dir))
if (IS_PRIVATE(dir)) {
inode->i_flags |= S_PRIVATE;
inode->i_opflags &= ~IOP_XATTR;
}
}
reiserfs_write_unlock(dir->i_sb);
if (retval == IO_ERROR) {
Expand Down
2 changes: 2 additions & 0 deletions fs/reiserfs/reiserfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ static inline int bmap_would_wrap(unsigned bmap_nr)
return bmap_nr > ((1LL << 16) - 1);
}

extern const struct xattr_handler *reiserfs_xattr_handlers[];

/*
* this says about version of key of all items (but stat data) the
* object consists of
Expand Down
2 changes: 2 additions & 0 deletions fs/reiserfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
if (replay_only(s))
goto error_unlocked;

s->s_xattr = reiserfs_xattr_handlers;

if (bdev_read_only(s->s_bdev) && !sb_rdonly(s)) {
SWARN(silent, s, "clm-7000",
"Detected readonly device, marking FS readonly");
Expand Down
19 changes: 12 additions & 7 deletions fs/reiserfs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags)
struct dentry *xaroot;

if (d_really_is_negative(privroot))
return ERR_PTR(-ENODATA);
return ERR_PTR(-EOPNOTSUPP);

inode_lock_nested(d_inode(privroot), I_MUTEX_XATTR);

xaroot = dget(REISERFS_SB(sb)->xattr_root);
if (!xaroot)
xaroot = ERR_PTR(-ENODATA);
xaroot = ERR_PTR(-EOPNOTSUPP);
else if (d_really_is_negative(xaroot)) {
int err = -ENODATA;

Expand Down Expand Up @@ -610,6 +610,10 @@ int reiserfs_xattr_set(struct inode *inode, const char *name,
int error, error2;
size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size);

/* Check before we start a transaction and then do nothing. */
if (!d_really_is_positive(REISERFS_SB(inode->i_sb)->priv_root))
return -EOPNOTSUPP;

if (!(flags & XATTR_REPLACE))
jbegin_count += reiserfs_xattr_jcreate_nblocks(inode);

Expand Down Expand Up @@ -832,8 +836,7 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
if (d_really_is_negative(dentry))
return -EINVAL;

if (!dentry->d_sb->s_xattr ||
get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
if (get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
return -EOPNOTSUPP;

dir = open_xa_dir(d_inode(dentry), XATTR_REPLACE);
Expand Down Expand Up @@ -873,6 +876,7 @@ static int create_privroot(struct dentry *dentry)
}

d_inode(dentry)->i_flags |= S_PRIVATE;
d_inode(dentry)->i_opflags &= ~IOP_XATTR;
reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr "
"storage.\n", PRIVROOT_NAME);

Expand All @@ -886,7 +890,7 @@ static int create_privroot(struct dentry *dentry) { return 0; }
#endif

/* Actual operations that are exported to VFS-land */
static const struct xattr_handler *reiserfs_xattr_handlers[] = {
const struct xattr_handler *reiserfs_xattr_handlers[] = {
#ifdef CONFIG_REISERFS_FS_XATTR
&reiserfs_xattr_user_handler,
&reiserfs_xattr_trusted_handler,
Expand Down Expand Up @@ -957,8 +961,10 @@ int reiserfs_lookup_privroot(struct super_block *s)
if (!IS_ERR(dentry)) {
REISERFS_SB(s)->priv_root = dentry;
d_set_d_op(dentry, &xattr_lookup_poison_ops);
if (d_really_is_positive(dentry))
if (d_really_is_positive(dentry)) {
d_inode(dentry)->i_flags |= S_PRIVATE;
d_inode(dentry)->i_opflags &= ~IOP_XATTR;
}
} else
err = PTR_ERR(dentry);
inode_unlock(d_inode(s->s_root));
Expand Down Expand Up @@ -987,7 +993,6 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
}

if (d_really_is_positive(privroot)) {
s->s_xattr = reiserfs_xattr_handlers;
inode_lock(d_inode(privroot));
if (!REISERFS_SB(s)->xattr_root) {
struct dentry *dentry;
Expand Down
4 changes: 1 addition & 3 deletions fs/reiserfs/xattr_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,8 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
* would be useless since permissions are ignored, and a pain because
* it introduces locking cycles
*/
if (IS_PRIVATE(dir)) {
inode->i_flags |= S_PRIVATE;
if (IS_PRIVATE(inode))
goto apply_umask;
}

err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
if (err)
Expand Down

0 comments on commit f7caaf0

Please sign in to comment.