Skip to content

Commit d9bdbb1

Browse files
author
Herton R. Krzesinski
committed
Merge: xfs: add selinux labels to whiteout inodes
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1793 Bugzilla: http://bugzilla.redhat.com/2103234 Tested: xfstests generic/700 commit 70b589a Author: Eric Sandeen <sandeen@redhat.com> Date: Sat Jul 9 10:56:02 2022 -0700 xfs: add selinux labels to whiteout inodes We got a report that "renameat2() with flags=RENAME_WHITEOUT doesn't apply an SELinux label on xfs" as it does on other filesystems (for example, ext4 and tmpfs.) While I'm not quite sure how labels may interact w/ whiteout files, leaving them as unlabeled seems inconsistent at best. Now that xfs_init_security is not static, rename it to xfs_inode_init_security per dchinner's suggestion. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com> Approved-by: Brian Foster <bfoster@redhat.com> Approved-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 02c8994 + a7ffd13 commit d9bdbb1

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

fs/xfs/xfs_inode.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,17 +3053,28 @@ xfs_cross_rename(
30533053
static int
30543054
xfs_rename_alloc_whiteout(
30553055
struct user_namespace *mnt_userns,
3056+
struct xfs_name *src_name,
30563057
struct xfs_inode *dp,
30573058
struct xfs_inode **wip)
30583059
{
30593060
struct xfs_inode *tmpfile;
3061+
struct qstr name;
30603062
int error;
30613063

30623064
error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE,
30633065
&tmpfile);
30643066
if (error)
30653067
return error;
30663068

3069+
name.name = src_name->name;
3070+
name.len = src_name->len;
3071+
error = xfs_inode_init_security(VFS_I(tmpfile), VFS_I(dp), &name);
3072+
if (error) {
3073+
xfs_finish_inode_setup(tmpfile);
3074+
xfs_irele(tmpfile);
3075+
return error;
3076+
}
3077+
30673078
/*
30683079
* Prepare the tmpfile inode as if it were created through the VFS.
30693080
* Complete the inode setup and flag it as linkable. nlink is already
@@ -3113,7 +3124,8 @@ xfs_rename(
31133124
* appropriately.
31143125
*/
31153126
if (flags & RENAME_WHITEOUT) {
3116-
error = xfs_rename_alloc_whiteout(mnt_userns, target_dp, &wip);
3127+
error = xfs_rename_alloc_whiteout(mnt_userns, src_name,
3128+
target_dp, &wip);
31173129
if (error)
31183130
return error;
31193131

fs/xfs/xfs_iops.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ xfs_initxattrs(
7272
* these attrs can be journalled at inode creation time (along with the
7373
* inode, of course, such that log replay can't cause these to be lost).
7474
*/
75-
76-
STATIC int
77-
xfs_init_security(
75+
int
76+
xfs_inode_init_security(
7877
struct inode *inode,
7978
struct inode *dir,
8079
const struct qstr *qstr)
@@ -119,7 +118,7 @@ xfs_cleanup_inode(
119118

120119
/* Oh, the horror.
121120
* If we can't add the ACL or we fail in
122-
* xfs_init_security we must back out.
121+
* xfs_inode_init_security we must back out.
123122
* ENOSPC can hit here, among other things.
124123
*/
125124
xfs_dentry_to_name(&teardown, dentry);
@@ -205,7 +204,7 @@ xfs_generic_create(
205204

206205
inode = VFS_I(ip);
207206

208-
error = xfs_init_security(inode, dir, &dentry->d_name);
207+
error = xfs_inode_init_security(inode, dir, &dentry->d_name);
209208
if (unlikely(error))
210209
goto out_cleanup_inode;
211210

@@ -423,7 +422,7 @@ xfs_vn_symlink(
423422

424423
inode = VFS_I(cip);
425424

426-
error = xfs_init_security(inode, dir, &dentry->d_name);
425+
error = xfs_inode_init_security(inode, dir, &dentry->d_name);
427426
if (unlikely(error))
428427
goto out_cleanup_inode;
429428

fs/xfs/xfs_iops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ extern void xfs_setattr_time(struct xfs_inode *ip, struct iattr *iattr);
1717
int xfs_vn_setattr_size(struct user_namespace *mnt_userns,
1818
struct dentry *dentry, struct iattr *vap);
1919

20+
int xfs_inode_init_security(struct inode *inode, struct inode *dir,
21+
const struct qstr *qstr);
22+
2023
#endif /* __XFS_IOPS_H__ */

0 commit comments

Comments
 (0)