f2fs: fix to create selinux label during whiteout initialization
authorChao Yu <chao@kernel.org>
Wed, 7 Feb 2024 07:05:48 +0000 (15:05 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 27 Feb 2024 17:41:14 +0000 (09:41 -0800)
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:
      70b589a37e1a xfs: add selinux labels to whiteout inodes

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

Fixes: 7e01e7ad746b ("f2fs: support RENAME_WHITEOUT")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/dir.c
fs/f2fs/f2fs.h
fs/f2fs/namei.c

index 3f20d94..02c9355 100644 (file)
@@ -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;
index 50e7890..cef1577 100644 (file)
@@ -3576,7 +3576,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)
index ba11298..0875602 100644 (file)
@@ -852,7 +852,7 @@ out:
 
 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;
@@ -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;
 
@@ -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,
@@ -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;
        }