Skip to contentSkip to conversation

f2fs: avoid to create an empty string as the extension_list

PATCH Superseded Wang Xiaojun 2 participants 5 messages Jul 9, 2021 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: avoid to create an empty string as the extension_list

When creating a file, we need to set the temperature based on extension_list. If the empty string is a valid extension_list, the is_extension_exist will always returns true, which affects the separation of hot and cold.

---
 fs/f2fs/namei.c | 2 ++
 1 file changed, 2 insertions(+)
fs/f2fs/namei.c +2 -0
index a9cd9cf97229..34341d3edb8d 100644
@@ -219,6 +219,8 @@ int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
 	int start, count;
 	int i;
 
+	if (!strlen(name))
+		return -EINVAL;
 	if (set) {
 		if (total_count == F2FS_MAX_EXTENSION)
 			return -EINVAL;
Signature · 8 lines
2.25.4



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Wang Xiaojun

When creating a file, we need to set the temperature based on extension_list. If the empty string is a valid extension_list, the is_extension_exist will always returns true, which affects the separation of hot and cold.

---
  fs/f2fs/namei.c | 2 ++
  1 file changed, 2 insertions(+)
fs/f2fs/namei.c +0 -0
index a9cd9cf97229..34341d3edb8d 100644

fs/f2fs/namei.c int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, · line 223

Quoted 5 lines
fs/f2fs/namei.c +2 -0
@@ -219,6 +219,8 @@ int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
  	int start, count;
  	int i;
 
+	if (!strlen(name))
+		return -EINVAL;

How about adding this in __sbi_store()? like:

if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)

	return -EINVAL;

Otherwise, it looks good to me.

Thanks,

fs/f2fs/namei.c int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, · line 226

Quoted 4 lines
fs/f2fs/namei.c +0 -0
  	if (set) {
  		if (total_count == F2FS_MAX_EXTENSION)
  			return -EINVAL;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 24 lines · Chao Yu
Quoted 15 lines · Wang Xiaojun

When creating a file, we need to set the temperature based on extension_list. If the empty string is a valid extension_list, the is_extension_exist will always returns true, which affects the separation of hot and cold.

---
  fs/f2fs/namei.c | 2 ++

  1 file changed, 2 insertions(+)
fs/f2fs/namei.c +0 -0
index a9cd9cf97229..34341d3edb8d 100644

fs/f2fs/namei.c int f2fs_update_extension_list(struct · line 223

Quoted 5 lines
fs/f2fs/namei.c +1 -0
@@ -219,6 +219,8 @@ int f2fs_update_extension_list(struct 
 f2fs_sb_info *sbi, const char *name,
       int start, count;
       int i;
   +    if (!strlen(name))
+        return -EINVAL;

How about adding this in __sbi_store()? like:

Quoted 4 lines

if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN) return -EINVAL;

Otherwise, it looks good to me.

This is an alternative modification. Exception check is more compact here.

But if the f2fs_update_extension_list function is called elsewhere in the future,

checking inside the function can avoid this problem.

I was also a little unsure, and finally chose this modification.

Quoted 10 lines

Thanks,

Quoted 4 lines
fs/f2fs/namei.c +0 -0
       if (set) {
           if (total_count == F2FS_MAX_EXTENSION)

              return -EINVAL;

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#3 lore raw
Quoted 29 lines · wangxiaojun (N)
Quoted 27 lines · Chao Yu
Quoted 15 lines · Wang Xiaojun

When creating a file, we need to set the temperature based on extension_list. If the empty string is a valid extension_list, the is_extension_exist will always returns true, which affects the separation of hot and cold.

---
   fs/f2fs/namei.c | 2 ++
   1 file changed, 2 insertions(+)
fs/f2fs/namei.c +0 -0
index a9cd9cf97229..34341d3edb8d 100644

fs/f2fs/namei.c int f2fs_update_extension_list(struct · line 223

Quoted 5 lines
fs/f2fs/namei.c +1 -0
@@ -219,6 +219,8 @@ int f2fs_update_extension_list(struct
 f2fs_sb_info *sbi, const char *name,
       int start, count;
       int i;
   +    if (!strlen(name))
+        return -EINVAL;

How about adding this in __sbi_store()? like:

if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
    return -EINVAL;

Quoted 6 lines
Quoted 1 line

Otherwise, it looks good to me.

This is an alternative modification. Exception check is more compact here.

But if the f2fs_update_extension_list function is called elsewhere in the future,

There is other related check of @name in __sbi_store(), so I guess f2fs_update_extension_list() is coupling to __sbi_store() now.

Quoted 4 lines

checking inside the function can avoid this problem.

I was also a little unsure, and finally chose this modification.

I'm fine to move all checks into f2fs_update_extension_list(), but now it looks more clean to just let the caller do the check on @name.

Thanks,

Quoted 11 lines
Quoted 11 lines

Thanks,

fs/f2fs/namei.c int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, · line 226

Quoted 4 lines
fs/f2fs/namei.c +0 -0
       if (set) {
           if (total_count == F2FS_MAX_EXTENSION)
               return -EINVAL;

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 41 lines · Chao Yu
Quoted 29 lines · wangxiaojun (N)
Quoted 27 lines · Chao Yu
Quoted 15 lines · Wang Xiaojun

When creating a file, we need to set the temperature based on extension_list. If the empty string is a valid extension_list, the is_extension_exist will always returns true, which affects the separation of hot and cold.

---
   fs/f2fs/namei.c | 2 ++

   1 file changed, 2 insertions(+)
fs/f2fs/namei.c +0 -0
index a9cd9cf97229..34341d3edb8d 100644

fs/f2fs/namei.c int f2fs_update_extension_list(struct · line 223

Quoted 5 lines
fs/f2fs/namei.c +1 -0
@@ -219,6 +219,8 @@ int f2fs_update_extension_list(struct
 f2fs_sb_info *sbi, const char *name,
        int start, count;
        int i;
    +    if (!strlen(name))
+        return -EINVAL;

How about adding this in __sbi_store()? like:

if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN) return -EINVAL;

Quoted 6 lines
Quoted 1 line

Otherwise, it looks good to me.

This is an alternative modification. Exception check is more compact here.

But if the f2fs_update_extension_list function is called elsewhere in the future,

There is other related check of @name in __sbi_store(), so I guess f2fs_update_extension_list() is coupling to __sbi_store() now.

Quoted 1 line
Quoted 9 lines
Quoted 3 lines

checking inside the function can avoid this problem.

I was also a little unsure, and finally chose this modification.

I'm fine to move all checks into f2fs_update_extension_list(), but now it looks more clean to just let the caller do the check on @name.

Thanks,

Okay, I'll update in the v2 version as you suggest. It's definitely more clean.

Thanks,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

Thanks,

Quoted 4 lines
fs/f2fs/namei.c +0 -0
        if (set) {
            if (total_count == F2FS_MAX_EXTENSION)

               return -EINVAL;

.

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel