fs: bug fixes
cover fs: bug fixes
---
Zijun Hu (5):
fs/filesystems: Fix potential unsigned integer underflow in fs_name() fs/fs_parse: Fix macro fsparam_u32hex() definition
fs/fs_parse: Fix 3 issues for validate_constant_table()
fs/fs_parse: Correct comments of fs_validate_description()
fs/fs_context: Mark an unlikely if condition with unlikely() in vfs_parse_monolithic_sep()
fs/filesystems.c | 14 +++++++++----- fs/fs_context.c | 2 +- fs/fs_parser.c | 13 ++++++++----- include/linux/fs_parser.h | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250410-fix_fs-6e0a97c4e59f
Best regards,
Signature · 1 line
Zijun Hu <[email protected]>
PATCH 1/5 fs/filesystems: Fix potential unsigned integer underflow in fs_name()
From: Zijun Hu <[email protected]>
fs_name() has @index as unsigned int, so there is underflow risk for operation '@index--'.
Fix by breaking the for loop when '@index == 0' which is also more proper than '@index <= 0' for unsigned integer comparison.
--- fs/filesystems.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
fs/filesystems.c +9 -5
@@ -156,15 +156,19 @@ static int fs_index(const char __user * __name)static int fs_name (unsigned int index,char __user * buf) {struct file_system_type * tmp; -int len, res; +int len, res = -EINVAL ;read_lock (&file_systems_lock); -for (tmp = file_systems; tmp; tmp = tmp->next, index--) -if (index <=0 &&try_module_get (tmp->owner)) +for (tmp = file_systems; tmp; tmp = tmp->next, index--) { +if (index ==0 ) { +if (try_module_get (tmp->owner)) + res =0 ;break ; + } + }read_unlock (&file_systems_lock); -if (!tmp) -return -EINVAL ; +if (res) +return res;/* OK, we got the reference, so we can safely block */ len =strlen (tmp->name) +1 ;
Signature · 1 line
2.34.1
Re: (subset) [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
Quoted 8 lines · Zijun Hu
fs_name()has @index as unsigned int, so there is underflow risk for operation '@index--'.Fix by breaking the for loop when '@index == 0' which is also more proper than '@index <= 0' for unsigned integer comparison.
[...]
Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.16.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.16.misc
[1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
https://git.kernel.org/vfs/vfs/c/d319af11e9a1
Christian Brauner
maintainerRe: [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
In reply to Zijun HuQuoted 10 lines · Zijun Hu
From: Zijun Hu <[email protected]>
fs_name()has @index as unsigned int, so there is underflow risk for operation '@index--'.Fix by breaking the for loop when '@index == 0' which is also more proper than '@index <= 0' for unsigned integer comparison.
Signed-off-by Zijun Hu <[email protected]>---
This is honestly not worth the effort thinking about.
I'm going to propose that we remove this system call or at least switch the default to N. Nobody uses this anymore I'm pretty sure.
Quoted 36 lines
fs/filesystems.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)fs/filesystems.c +9
-5@@ -156,15 +156,19 @@ static int fs_index(const char __user * __name)static int fs_name (unsigned int index,char __user * buf) {struct file_system_type * tmp; -int len, res; +int len, res = -EINVAL ;read_lock (&file_systems_lock); -for (tmp = file_systems; tmp; tmp = tmp->next, index--) -if (index <=0 &&try_module_get (tmp->owner)) +for (tmp = file_systems; tmp; tmp = tmp->next, index--) { +if (index ==0 ) { +if (try_module_get (tmp->owner)) + res =0 ;break ; + } + }read_unlock (&file_systems_lock); -if (!tmp) -return -EINVAL ; +if (res) +return res;/* OK, we got the reference, so we can safely block */ len =strlen (tmp->name) +1 ;Signature · 2 lines
-- 2.34.1
Re: [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
Quoted 8 lines · Christian Brauner
Quoted 5 lines
Fix by breaking the for loop when '@index == 0' which is also more proper than '@index <= 0' for unsigned integer comparison.
Signed-off-by Zijun Hu <[email protected]>---
This is honestly not worth the effort thinking about.
I'm going to propose that we remove this system call or at least switch the default to N. Nobody uses this anymore I'm pretty sure
Sound good.
i just started looking at FS code (^^).
Re: [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
In reply to Zijun HuQuoted 5 lines · Zijun Hu
fs_name()has @index as unsigned int, so there is underflow risk for operation '@index--'.Fix by breaking the for loop when '@index == 0' which is also more proper than '@index <= 0' for unsigned integer comparison.
There isn't really a risk. The list walked by "tmp" and the checks that this is or is not NULL will prevent a problem.
I also feel that breaking out of the loop with "<= 0" - even if the variable is unsigned - is safer, on the off chance that someone in the future changes the signedness of the variable.
David
Re: [PATCH 1/5] fs/filesystems: Fix potential unsigned integer underflow in fs_name()
Quoted 5 lines · David Howells
Quoted 2 lines
Fix by breaking the for loop when '@index == 0' which is also more proper than '@index <= 0' for unsigned integer comparison.
There isn't really a risk. The list walked by "tmp" and the checks that this is or is not NULL will prevent a problem.
no fixes tag is added and just improve code logic a bit since there is no reason to continue the loop when @index reach 0.
Quoted 3 lines
I also feel that breaking out of the loop with "<= 0" - even if the variable is unsigned - is safer, on the off chance that someone in the future changes the signedness of the variable.
for parameter @index representing filesystem index. unsigned integer type may be better than signed.
PATCH 2/5 fs/fs_parse: Fix macro fsparam_u32hex() definition
In reply to Zijun HuFrom: Zijun Hu <[email protected]>
Macro fsparam_u32hex() uses as type @fs_param_is_u32_hex which is never defined.
Fix by using @fs_param_is_u32 instead as fsparam_u32oct() does.
--- include/linux/fs_parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fs_parser.h +1 -1
@@ -126,7 +126,7 @@ static inline bool fs_validate_description(const char *name,#define fsparam_u32oct (NAME ,OPT ) \ __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8)#define fsparam_u32hex (NAME ,OPT ) \ - __fsparam(fs_param_is_u32_hex, NAME, OPT, 0, (void *)16) + __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)16)#define fsparam_s32 (NAME ,OPT ) __fsparam(fs_param_is_s32, NAME, OPT, 0, NULL)#define fsparam_u64 (NAME ,OPT ) __fsparam(fs_param_is_u64, NAME, OPT, 0, NULL)#define fsparam_enum (NAME ,OPT , array) __fsparam(fs_param_is_enum, NAME, OPT, 0, array)
Signature · 1 line
2.34.1
Christian Brauner
maintainerRe: [PATCH 2/5] fs/fs_parse: Fix macro fsparam_u32hex() definition
Quoted 18 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Macro
fsparam_u32hex()uses as type @fs_param_is_u32_hex which is never defined.Fix by using @fs_param_is_u32 instead as
fsparam_u32oct()does.Fixes 328de5287b10 ("turn fs_param_is_... into functions")Signed-off-by Zijun Hu <[email protected]>--- include/linux/fs_parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/fs_parser.h +0
-0
include/linux/fs_parser.h static inline bool fs_validate_description(const char *name, · line 129
Quoted 5 lines
include/linux/fs_parser.h +1
-1@@ -126,7 +126,7 @@ static inline bool fs_validate_description(const char *name,#define fsparam_u32oct (NAME ,OPT ) \ __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8)#define fsparam_u32hex (NAME ,OPT ) \ - __fsparam(fs_param_is_u32_hex, NAME, OPT, 0, (void *)16) + __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)16)
Remove that define completely as it's unused. There's no point keeping dead code around.
Re: [PATCH 2/5] fs/fs_parse: Fix macro fsparam_u32hex() definition
Quoted 4 lines · Christian Brauner
Quoted 4 lines
include/linux/fs_parser.h +0
-0
Quoted 8 lines
include/linux/fs_parser.h static inline bool fs_validate_description(const char *name, · line 129
Quoted 6 lines
include/linux/fs_parser.h +1
-1@@ -126,7 +126,7 @@ static inline bool fs_validate_description(const char *name,#define fsparam_u32oct (NAME ,OPT ) \ __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8)#define fsparam_u32hex (NAME ,OPT ) \ - __fsparam(fs_param_is_u32_hex, NAME, OPT, 0, (void *)16) + __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)16)Remove that define completely as it's unused. There's no point keeping dead code around.
sure. will do it. (^^)
PATCH 3/5 fs/fs_parse: Fix 3 issues for validate_constant_table()
In reply to Zijun HuFrom: Zijun Hu <[email protected]>
Constant table array array[] which must end with a empty entry and fix below issues for validate_constant_table(array, ARRAY_SIZE(array), ...):
- Always return wrong value for good constant table array which ends with a empty entry.
- Imprecise error message for missorted case.
- Potential NULL pointer dereference.
--- fs/fs_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/fs_parser.c +5 -2
@@ -399,6 +399,9 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, }for (i =0 ; i < tbl_size; i++) { +if (!tbl[i].name && (i +1 == tbl_size)) +break ; +if (!tbl[i].name) {pr_err ("VALIDATE C-TBL[%zu]: Null\n" , i); good = false;
@@ -411,13 +414,13 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, good = false; }if (c >0 ) { -pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>=%s\n" , +pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>%s\n" , i, tbl[i-1 ].name, tbl[i].name); good = false; } } -if (tbl[i].value != special && +if (tbl[i].name && tbl[i].value != special && (tbl[i].value < low || tbl[i].value > high)) {pr_err ("VALIDATE C-TBL[%zu]: %s->%d const out of range (%d-%d)\n" , i, tbl[i].name, tbl[i].value, low, high);
Signature · 1 line
2.34.1
Christian Brauner
maintainerRe: [PATCH 3/5] fs/fs_parse: Fix 3 issues for validate_constant_table()
Quoted 11 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Constant table array array[] which must end with a empty entry and fix below issues for
validate_constant_table(array, ARRAY_SIZE(array), ...):- Always return wrong value for good constant table array which ends with a empty entry.
- Imprecise error message for missorted case.
- Potential NULL pointer dereference.
I really dislike "potential NULL deref" without an explanation. Please explain how this supposed NULL deref can happen.
Quoted 40 lines
Fixes 31d921c7fb96 ("vfs: Add configuration parser helpers")Signed-off-by Zijun Hu <[email protected]>--- fs/fs_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/fs_parser.c +5
-2@@ -399,6 +399,9 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, }for (i =0 ; i < tbl_size; i++) { +if (!tbl[i].name && (i +1 == tbl_size)) +break ; +if (!tbl[i].name) {pr_err ("VALIDATE C-TBL[%zu]: Null\n" , i); good = false;@@ -411,13 +414,13 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, good = false; }if (c >0 ) { -pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>=%s\n" , +pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>%s\n" , i, tbl[i-1 ].name, tbl[i].name); good = false; } } -if (tbl[i].value != special && +if (tbl[i].name && tbl[i].value != special && (tbl[i].value < low || tbl[i].value > high)) {pr_err ("VALIDATE C-TBL[%zu]: %s->%d const out of range (%d-%d)\n" , i, tbl[i].name, tbl[i].value, low, high);Signature · 2 lines
-- 2.34.1
Re: [PATCH 3/5] fs/fs_parse: Fix 3 issues for validate_constant_table()
Quoted 4 lines · Christian Brauner
Quoted 1 line
- Potential NULL pointer dereference.
I really dislike "potential NULL deref" without an explanation. Please explain how this supposed NULL deref can happen.
okay.
Quoted 31 lines
Quoted 31 lines
Fixes 31d921c7fb96 ("vfs: Add configuration parser helpers")Signed-off-by Zijun Hu <[email protected]>--- fs/fs_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/fs_parser.c +4
-1@@ -399,6 +399,9 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, }for (i =0 ; i < tbl_size; i++) { +if (!tbl[i].name && (i +1 == tbl_size)) +break ; +if (!tbl[i].name) {pr_err ("VALIDATE C-TBL[%zu]: Null\n" , i); good = false;@@ -411,13 +414,13 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, good = false; }if (c >0 ) { -pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>=%s\n" , +pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>%s\n" , i, tbl[i-1 ].name, tbl[i].name); good = false; } }
Quoted 5 lines
fs/fs_parser.c bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, · line 426
Quoted 5 lines
fs/fs_parser.c +1
-1-if (tbl[i].value != special && +if (tbl[i].name && tbl[i].value != special && (tbl[i].value < low || tbl[i].value > high)) {pr_err ("VALIDATE C-TBL[%zu]: %s->%d const out of range (%d-%d)\n" , i, tbl[i].name, tbl[i].value, low, high);
for good constant table which ends with empty entry. for original logic, when loop reach the last empty entry. above pr_err() may access NULL pointer tbl[i].name.
i find out this validate_constant_table() also has no callers. fix it or remove it ?
Jan Kara
reviewerRe: [PATCH 3/5] fs/fs_parse: Fix 3 issues for validate_constant_table()
Quoted 50 lines · Zijun Hu
Quoted 4 lines · Christian Brauner
Quoted 1 line
- Potential NULL pointer dereference.
I really dislike "potential NULL deref" without an explanation. Please explain how this supposed NULL deref can happen.
okay.
Quoted 31 lines
Quoted 31 lines
Fixes 31d921c7fb96 ("vfs: Add configuration parser helpers")Signed-off-by Zijun Hu <[email protected]>--- fs/fs_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/fs_parser.c +4
-1@@ -399,6 +399,9 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, }for (i =0 ; i < tbl_size; i++) { +if (!tbl[i].name && (i +1 == tbl_size)) +break ; +if (!tbl[i].name) {pr_err ("VALIDATE C-TBL[%zu]: Null\n" , i); good = false;@@ -411,13 +414,13 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, good = false; }if (c >0 ) { -pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>=%s\n" , +pr_err ("VALIDATE C-TBL[%zu]: Missorted %s>%s\n" , i, tbl[i-1 ].name, tbl[i].name); good = false; } }Quoted 5 lines
fs/fs_parser.c bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, · line 426
Quoted 5 lines
fs/fs_parser.c +1
-1-if (tbl[i].value != special && +if (tbl[i].name && tbl[i].value != special && (tbl[i].value < low || tbl[i].value > high)) {pr_err ("VALIDATE C-TBL[%zu]: %s->%d const out of range (%d-%d)\n" , i, tbl[i].name, tbl[i].value, low, high);for good constant table which ends with empty entry. for original logic, when loop reach the last empty entry. above
pr_err()may access NULL pointer tbl[i].name.
Quoted 2 lines
i find out this
validate_constant_table()also has no callers. fix it or remove it ?
Yeah, just drop it. In the kernel we are pretty aggressive in dropping unused code :)
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 4/5 fs/fs_parse: Correct comments of fs_validate_description()
In reply to Zijun HuFrom: Zijun Hu <[email protected]>
For fs_validate_description(), its comments easily mislead reader that the function will search array @desc for duplicated entries with name specified by parameter @name, but @name is not used for search actually.
Fix by marking name as owner's name of these parameter specifications.
--- fs/fs_parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/fs_parser.c +3 -3
@@ -432,9 +432,9 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, }/** -* fs_validate_description - Validate a parameter description -* @name: The parameter name to search for. -* @desc: The parameter description to validate. +* fs_validate_description - Validate a parameter specification array +* @name: Owner name of the parameter specification array +* @desc: The parameter specification array to validate. */ bool fs_validate_description (const char *name,const struct fs_parameter_spec *desc)
Signature · 1 line
2.34.1
Re: (subset) [PATCH 4/5] fs/fs_parse: Correct comments of fs_validate_description()
Quoted 8 lines · Zijun Hu
For
fs_validate_description(), its comments easily mislead reader that the function will search array @desc for duplicated entries with name specified by parameter @name, but @name is not used for search actually.Fix by marking name as owner's name of these parameter specifications.
[...]
Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.16.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.16.misc
[4/5] fs/fs_parse: Correct comments of fs_validate_description()
https://git.kernel.org/vfs/vfs/c/a8fca9b51158
PATCH 5/5 fs/fs_context: Mark an unlikely if condition with unlikely() in vfs_parse_monolithic_sep()
In reply to Zijun HuFrom: Zijun Hu <[email protected]>
There is no mount option with pattern "...,=key_or_value,...", so the if condition '(value == key)' in while loop of vfs_parse_monolithic_sep() is is unlikely true.
Mark the condition with unlikely() to improve both performance and readability.
--- fs/fs_context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs_context.c +1 -1
@@ -222,7 +222,7 @@ int vfs_parse_monolithic_sep(struct fs_context *fc, void *data,char *value =strchr (key,'=' );if (value) { -if (value == key) +if (unlikely (value == key))continue ; *value++ =0 ; v_len =strlen (value);
Signature · 1 line
2.34.1
Re: (subset) [PATCH 5/5] fs/fs_context: Mark an unlikely if condition with unlikely() in vfs_parse_monolithic_sep()
Quoted 8 lines · Zijun Hu
There is no mount option with pattern "...,=key_or_value,...", so the if condition '(value == key)' in while loop of
vfs_parse_monolithic_sep()is is unlikely true.Mark the condition with
unlikely()to improve both performance and readability.[...]
Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.16.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.16.misc
[5/5] fs/fs_context: Mark an unlikely if condition with unlikely() in vfs_parse_monolithic_sep()
https://git.kernel.org/vfs/vfs/c/95bfd4b5928f