Skip to content

Commit

Permalink
f2fs: fix to create selinux label during whiteout initialization
Browse files Browse the repository at this point in the history
[ Upstream commit 40b2d55e045222dd6de2a54a299f682e0f954b03 ]

#generic/700       - output mismatch (see /media/fstests/results//generic/700.out.bad)
#    --- tests/generic/700.out	2023-03-28 10:40:42.735529223 +0000
#    +++ /media/fstests/results//generic/700.out.bad	2024-02-06 04:37:56.000000000 +0000
#    @@ -1,2 +1,4 @@
#     QA output created by 700
#    +/mnt/scratch_f2fs/f1: security.selinux: No such attribute
#    +/mnt/scratch_f2fs/f2: security.selinux: No such attribute
#     Silence is golden
#    ...
#    (Run 'diff -u /media/fstests/tests/generic/700.out /media/fstests/results//generic/700.out.bad'  to see the entire diff)

HINT: You _MAY_ be missing kernel fix:
      70b589a xfs: add selinux labels to whiteout inodes

Previously, it missed to create selinux labels during whiteout inode
initialization, fix this issue.

Fixes: 7e01e7a ("f2fs: support RENAME_WHITEOUT")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
chaseyu authored and Sasha Levin committed Mar 26, 2024
1 parent 42249eb commit 64582cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 3 additions & 2 deletions fs/f2fs/dir.c
Expand Up @@ -830,13 +830,14 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
return err;
}

int f2fs_do_tmpfile(struct inode *inode, struct inode *dir)
int f2fs_do_tmpfile(struct inode *inode, struct inode *dir,
struct f2fs_filename *fname)
{
struct page *page;
int err = 0;

f2fs_down_write(&F2FS_I(inode)->i_sem);
page = f2fs_init_inode_metadata(inode, dir, NULL, NULL);
page = f2fs_init_inode_metadata(inode, dir, fname, NULL);
if (IS_ERR(page)) {
err = PTR_ERR(page);
goto fail;
Expand Down
3 changes: 2 additions & 1 deletion fs/f2fs/f2fs.h
Expand Up @@ -3579,7 +3579,8 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
struct inode *inode, nid_t ino, umode_t mode);
void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
struct inode *dir, struct inode *inode);
int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
int f2fs_do_tmpfile(struct inode *inode, struct inode *dir,
struct f2fs_filename *fname);
bool f2fs_empty_dir(struct inode *dir);

static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
Expand Down
25 changes: 17 additions & 8 deletions fs/f2fs/namei.c
Expand Up @@ -852,7 +852,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,

static int __f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode, bool is_whiteout,
struct inode **new_inode)
struct inode **new_inode, struct f2fs_filename *fname)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
struct inode *inode;
Expand Down Expand Up @@ -880,7 +880,7 @@ static int __f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
if (err)
goto out;

err = f2fs_do_tmpfile(inode, dir);
err = f2fs_do_tmpfile(inode, dir, fname);
if (err)
goto release_out;

Expand Down Expand Up @@ -931,22 +931,24 @@ static int f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
if (!f2fs_is_checkpoint_ready(sbi))
return -ENOSPC;

err = __f2fs_tmpfile(idmap, dir, file, mode, false, NULL);
err = __f2fs_tmpfile(idmap, dir, file, mode, false, NULL, NULL);

return finish_open_simple(file, err);
}

static int f2fs_create_whiteout(struct mnt_idmap *idmap,
struct inode *dir, struct inode **whiteout)
struct inode *dir, struct inode **whiteout,
struct f2fs_filename *fname)
{
return __f2fs_tmpfile(idmap, dir, NULL,
S_IFCHR | WHITEOUT_MODE, true, whiteout);
return __f2fs_tmpfile(idmap, dir, NULL, S_IFCHR | WHITEOUT_MODE,
true, whiteout, fname);
}

int f2fs_get_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct inode **new_inode)
{
return __f2fs_tmpfile(idmap, dir, NULL, S_IFREG, false, new_inode);
return __f2fs_tmpfile(idmap, dir, NULL, S_IFREG,
false, new_inode, NULL);
}

static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
Expand Down Expand Up @@ -990,7 +992,14 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
}

if (flags & RENAME_WHITEOUT) {
err = f2fs_create_whiteout(idmap, old_dir, &whiteout);
struct f2fs_filename fname;

err = f2fs_setup_filename(old_dir, &old_dentry->d_name,
0, &fname);
if (err)
return err;

err = f2fs_create_whiteout(idmap, old_dir, &whiteout, &fname);
if (err)
return err;
}
Expand Down

0 comments on commit 64582cc

Please sign in to comment.