kconfig: check for a NULL pointer before access
PATCH 1/1 kconfig: check for a NULL pointer before access
The call to 'prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without checking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.
---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/symbol.c +1 -1
@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }
Signature · 1 line
2.49.0.1164.gab81da1b16-goog
Hi,
Quoted 21 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without checking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.Signed-off-by Bill Wendling <[email protected]>---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/kconfig/symbol.c +0
-0
scripts/kconfig/symbol.c struct symbol *sym_choice_default(struct menu *choice) · line 278
Quoted 8 lines
scripts/kconfig/symbol.c +1
-1@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }
The patch is missing the source file's indentation. (spaces/tabs are lost)
Signature · 1 line
~Randy
Quoted 20 lines · Randy Dunlap
Hi,
Quoted 16 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without checking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.Signed-off-by Bill Wendling <[email protected]>---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
scripts/kconfig/symbol.c struct symbol *sym_choice_default(struct menu *choice) · line 278
Quoted 13 lines
scripts/kconfig/symbol.c +1
-1@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }The patch is missing the source file's indentation. (spaces/tabs are lost)
Crud! My mailer borked. I sent v2 and it looks to have kept the whitespaces.
-bw
Quoted 38 lines · Bill Wendling
Quoted 20 lines · Randy Dunlap
Hi,
Quoted 16 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without checking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.Signed-off-by Bill Wendling <[email protected]>---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 17 lines
scripts/kconfig/symbol.c struct symbol *sym_choice_default(struct menu *choice) · line 278
Quoted 13 lines
scripts/kconfig/symbol.c +1
-1@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }The patch is missing the source file's indentation. (spaces/tabs are lost)
Quoted 1 line
Crud! My mailer borked. I sent v2 and it looks to have kept the whitespaces.
I don't think v2 worked either.
See https://lore.kernel.org/linux-kbuild/CAGG=3QXQkJ6n0J1gZcgxfEb68NWN2y200ZCuxxDtqPRgWPci=A@mail.gmail.com/T/#mf64c7afd19235d3dee4e572f96ff76936f921c6e
Signature · 1 line
~Randy
Quoted 39 lines · Randy Dunlap
Quoted 38 lines · Bill Wendling
Quoted 37 lines · Randy Dunlap
Hi,
Quoted 21 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without checking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.Signed-off-by Bill Wendling <[email protected]>---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/kconfig/symbol.c +0
-0scripts/kconfig/symbol.c struct symbol *sym_choice_default(struct menu *choice) · line 278
Quoted 8 lines
scripts/kconfig/symbol.c +1
-1@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }The patch is missing the source file's indentation. (spaces/tabs are lost)
Quoted 5 lines
Quoted 1 line
Crud! My mailer borked. I sent v2 and it looks to have kept the whitespaces.
I don't think v2 worked either.
See https://lore.kernel.org/linux-kbuild/CAGG=3QXQkJ6n0J1gZcgxfEb68NWN2y200ZCuxxDtqPRgWPci=A@mail.gmail.com/T/#mf64c7afd19235d3dee4e572f96ff76936f921c6e
Goddamnit! I'll try again...
-bw
PATCH v2 1/1 kconfig: check for a NULL pointer before access
In reply to Bill WendlingThe call to 'prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without checking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.
---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]
v2: Fix whitespaces.
--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/symbol.c +1 -1
@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }
Signature · 1 line
2.49.0.1164.gab81da1b16-goog
PATCH v3 1/1 kconfig: check for a NULL pointer before access
The call to 'prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without cheecking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.
---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]
v3:
- Fix whitespace for real now.
- Patch from another email account so that the whitespace is retained.
v2:
- Fix whitespace
--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/symbol.c +1 -1
@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }
Signature · 1 line
2.49.0.1164.gab81da1b16-goog
Hi Bill,
Quoted 8 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without cheecking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.Signed-off-by Bill Wendling <[email protected]>
although see whitespace issue below...
Quoted 18 lines
---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]
v3:
- Fix whitespace for real now.
- Patch from another email account so that the whitespace is retained.
v2:
- Fix whitespace--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/kconfig/symbol.c +0
-0
scripts/kconfig/symbol.c struct symbol *sym_choice_default(struct menu *choice) · line 278
Quoted 8 lines
scripts/kconfig/symbol.c +1
-1@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }
All of these lines are still indented incorrectly in what I received, so I downloaded the patch from
https://lore.kernel.org/linux-kbuild/[email protected]/raw
Running 'patch' (not git) on it gives me:
checking file scripts/kconfig/symbol.c
Hunk #1 FAILED at 272.
1 out of 1 hunk FAILED
done
In looking at the raw patch (link above), the non -/+ lines have an extra space at the beginning of each line (2 spaces instead of 1). If I remove one of those spaces, the patch applies cleanly. Or maybe I could just tell 'patch' to ignore whitespace. Yes, that also works.
Signature · 1 line
~Randy
Quoted 9 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without cheecking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.Signed-off-by Bill Wendling <[email protected]>
Same reaction to this patch
https://lore.kernel.org/linux-kbuild/[email protected]/
Please attach a test case
that causes a segfault with NULL pointer dereference.
Quoted 29 lines
---
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]
v3:
- Fix whitespace for real now.
- Patch from another email account so that the whitespace is retained.
v2:
- Fix whitespace--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/kconfig/symbol.c +1
-2@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; } --2.49.0.1164.gab81da1b16-goog
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 10 lines · Masahiro Yamada
Quoted 8 lines · Bill Wendling
The call to '
prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without cheecking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.
Quoted 6 lines
Quoted 1 line
Signed-off-by Bill Wendling <[email protected]>Same reaction to this patch
I apologize for the whitespace problems. My mailer is crap and sendmail isn't available on my local machine (it's a long story).
Quoted 3 lines
Please attach a test case
that causes a segfault with NULL pointer dereference.
I don't have a testcase. I discovered this while working on a Clang feature to isolate paths with undefined behavior. (GCC already has this pass.) The compiler notices that, after inlining, the path has UB. It's not necessarily important whether the current compiler messes up the code path, it's more a matter of *when* the compiler will mess up the code path, as marking UB paths as "not executable therefore not executed" is a common trope for some compiler developers.
-bw
PATCH v4 1/1 kconfig: check for a NULL pointer before access
The call to 'prop_get_symbol' may return NULL in some cases. The if-then statement accesses the returned value without cheecking if it's non-NULL. After inlining, the compiler may treat the conditional as 'undefined behavior', which the compiler may take the opportunity to do whatever it wants with the UB path. This patch simply adds a check to ensure that 'def_sym' is non-NULL to avoid this behavior.
---
Cc: Masahiro Yamada <[email protected]>
Cc: Randy Dunlap <[email protected]>
Cc: [email protected]
Cc: [email protected]
v4:
- Fix issue with patch formatting.
- Patch is sent from original email account.
v3:
- Fix whitespace for real now.
- Patch from another email account so that the whitespace is retained.
v2:
- Fix whitespace
--- scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/symbol.c +1 -1
@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)if (prop->visible.tri == no)continue ; def_sym =prop_get_symbol (prop); -if (def_sym->visible != no) +if (def_sym && def_sym->visible != no)return def_sym; }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog