2023-12-22 03:30:01

by Yongpeng Yang

[permalink] [raw]
Subject: [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs

The {struct f2fs_sb_info}->dir_level can be modified through the sysfs
interface, but its value range is not limited. If the value exceeds
MAX_DIR_HASH_DEPTH and the mount options include "noinline_dentry",
the following error will occur:
[root@fedora ~]# mount -o noinline_dentry /dev/sdb /mnt/sdb/
[root@fedora ~]# echo 128 > /sys/fs/f2fs/sdb/dir_level
[root@fedora ~]# cd /mnt/sdb/
[root@fedora sdb]# mkdir test
[root@fedora sdb]# cd test/
[root@fedora test]# mkdir test
mkdir: cannot create directory 'test': Argument list too long

Signed-off-by: Yongpeng Yang <[email protected]>
---
fs/f2fs/sysfs.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 7099ffa57299..8c8424b05fc7 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -741,6 +741,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count;
}

+ if (!strcmp(a->attr.name, "dir_level")) {
+ if (t > MAX_DIR_HASH_DEPTH)
+ return -EINVAL;
+ sbi->dir_level = t;
+ return count;
+ }
+
*ui = (unsigned int)t;

return count;
--
2.40.1



2023-12-22 03:30:50

by Yongpeng Yang

[permalink] [raw]
Subject: [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect

The function do_garbage_collect can return a value less than 0 due
to f2fs_cp_error being true or page allocation failure, as a result
of calling f2fs_get_sum_page. However, f2fs_gc does not account for
such cases, which could potentially lead to an abnormal total_freed
and thus cause subsequent code to behave unexpectedly. Given that
an f2fs_cp_error is irrecoverable, and considering that
do_garbage_collect already retries page allocation errors through
its call to f2fs_get_sum_page->f2fs_get_meta_page_retry, any error
reported by do_garbage_collect should immediately terminate the
current GC.

Signed-off-by: Yongpeng Yang <[email protected]>
---
fs/f2fs/gc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 405a6077bd83..771d56b0bfb8 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1865,6 +1865,9 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)

seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type,
gc_control->should_migrate_blocks);
+ if (seg_freed < 0)
+ goto stop;
+
total_freed += seg_freed;

if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno)) {
--
2.40.1


2023-12-22 09:42:35

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs

On 2023/12/22 11:29, Yongpeng Yang wrote:
> The {struct f2fs_sb_info}->dir_level can be modified through the sysfs
> interface, but its value range is not limited. If the value exceeds
> MAX_DIR_HASH_DEPTH and the mount options include "noinline_dentry",
> the following error will occur:
> [root@fedora ~]# mount -o noinline_dentry /dev/sdb /mnt/sdb/
> [root@fedora ~]# echo 128 > /sys/fs/f2fs/sdb/dir_level
> [root@fedora ~]# cd /mnt/sdb/
> [root@fedora sdb]# mkdir test
> [root@fedora sdb]# cd test/
> [root@fedora test]# mkdir test
> mkdir: cannot create directory 'test': Argument list too long
>
> Signed-off-by: Yongpeng Yang <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2023-12-22 09:42:50

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH 2/2] f2fs: Add error handling for negative returns from do_garbage_collect

On 2023/12/22 11:29, Yongpeng Yang wrote:
> The function do_garbage_collect can return a value less than 0 due
> to f2fs_cp_error being true or page allocation failure, as a result
> of calling f2fs_get_sum_page. However, f2fs_gc does not account for
> such cases, which could potentially lead to an abnormal total_freed
> and thus cause subsequent code to behave unexpectedly. Given that
> an f2fs_cp_error is irrecoverable, and considering that
> do_garbage_collect already retries page allocation errors through
> its call to f2fs_get_sum_page->f2fs_get_meta_page_retry, any error
> reported by do_garbage_collect should immediately terminate the
> current GC.
>
> Signed-off-by: Yongpeng Yang <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2023-12-29 19:10:37

by patchwork-bot+f2fs

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH 1/2] f2fs: Constrain the modification range of dir_level in the sysfs

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

On Fri, 22 Dec 2023 11:29:00 +0800 you wrote:
> The {struct f2fs_sb_info}->dir_level can be modified through the sysfs
> interface, but its value range is not limited. If the value exceeds
> MAX_DIR_HASH_DEPTH and the mount options include "noinline_dentry",
> the following error will occur:
> [root@fedora ~]# mount -o noinline_dentry /dev/sdb /mnt/sdb/
> [root@fedora ~]# echo 128 > /sys/fs/f2fs/sdb/dir_level
> [root@fedora ~]# cd /mnt/sdb/
> [root@fedora sdb]# mkdir test
> [root@fedora sdb]# cd test/
> [root@fedora test]# mkdir test
> mkdir: cannot create directory 'test': Argument list too long
>
> [...]

Here is the summary with links:
- [f2fs-dev,1/2] f2fs: Constrain the modification range of dir_level in the sysfs
https://git.kernel.org/jaegeuk/f2fs/c/0145eed6ed32
- [f2fs-dev,2/2] f2fs: Add error handling for negative returns from do_garbage_collect
https://git.kernel.org/jaegeuk/f2fs/c/19ec1d31fa56

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html