mm: debug_page_alloc: fix NULL buf in debug_guardpage_minorder_setup
Subsystems (2)
PATCH 1/1 mm: debug_page_alloc: fix NULL buf in debug_guardpage_minorder_setup
From: Ye Liu <[email protected]>
If the kernel command line includes "debug_guardpage_minorder" without an equals sign (i.e., no value is provided), the early parameter parser passes a NULL buf pointer to the setup function.
kstrtouint() does not perform a NULL check on its input and calls directly into kstrtoull() which dereferences s[0] unconditionally, leading to a NULL pointer dereference and early boot crash.
Additionally, the error path's pr_err("%s", buf) would also crash with a NULL format argument.
--- mm/debug_page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug_page_alloc.c +2 -2
@@ -22,8 +22,8 @@ static int __init debug_guardpage_minorder_setup(char *buf) {unsigned int res; -if (kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { -pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf); +if (!buf ||kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { +pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf ?:"(missing)" );return 0 ; } _debug_guardpage_minorder = res;
Signature · 1 line
2.25.1
Quoted 10 lines · Ye Liu
From: Ye Liu <[email protected]>
If the kernel command line includes "
debug_guardpage_minorder" without an equals sign (i.e., no value is provided), the early parameter parser passes a NULL buf pointer to the setup function.
kstrtouint()does not perform a NULL check on its input and calls directly intokstrtoull()which dereferences s[0] unconditionally, leading to a NULL pointer dereference and early boot crash.
Quoted 8 lines
Additionally, the error path's
pr_err("%s", buf)would also crash with a NULL format argument.Signed-off-by Ye Liu <[email protected]>--- mm/debug_page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
LGTM.
Signature · 2 lines
Best Regards, Yan, Zi
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
If the kernel command line includes "
debug_guardpage_minorder" without an equals sign (i.e., no value is provided), the early parameter parser passes a NULL buf pointer to the setup function.
Quoted 7 lines
kstrtouint()does not perform a NULL check on its input and calls directly intokstrtoull()which dereferences s[0] unconditionally, leading to a NULL pointer dereference and early boot crash.Additionally, the error path's
pr_err("%s", buf)would also crash with a NULL format argument.
Maybe a "Fixes:" tag is called for?
Quoted 10 lines
Signed-off-by Ye Liu <[email protected]>--- mm/debug_page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/debug_page_alloc.c +0
-0
mm/debug_page_alloc.c static int __init debug_guardpage_minorder_setup(char *buf) · line 29
Quoted 10 lines
mm/debug_page_alloc.c +2
-2@@ -22,8 +22,8 @@ static int __init debug_guardpage_minorder_setup(char *buf) {unsigned int res; -if (kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { -pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf); +if (!buf ||kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { +pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf ?:"(missing)" );return 0 ; } _debug_guardpage_minorder = res;
thanks,
Signature · 1 line
John Hubbard
Quoted 11 lines · John Hubbard
Quoted 10 lines · Ye Liu
From: Ye Liu <[email protected]>
If the kernel command line includes "
debug_guardpage_minorder" without an equals sign (i.e., no value is provided), the early parameter parser passes a NULL buf pointer to the setup function.
kstrtouint()does not perform a NULL check on its input and calls directly intokstrtoull()which dereferences s[0] unconditionally, leading to a NULL pointer dereference and early boot crash.
Quoted 6 lines
Quoted 3 lines
Additionally, the error path's
pr_err("%s", buf)would also crash with a NULL format argument.Maybe a "Fixes:" tag is called for?
Add the following Fixes. Thanks.
Quoted 23 lines
Quoted 11 lines
Signed-off-by Ye Liu <[email protected]>--- mm/debug_page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/debug_page_alloc.c +0
-0mm/debug_page_alloc.c static int __init debug_guardpage_minorder_setup(char *buf) · line 29
Quoted 10 lines
mm/debug_page_alloc.c +2
-2@@ -22,8 +22,8 @@ static int __init debug_guardpage_minorder_setup(char *buf) {unsigned int res; -if (kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { -pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf); +if (!buf ||kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { +pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf ?:"(missing)" );return 0 ; } _debug_guardpage_minorder = res;thanks,
Signature · 2 lines
Thanks, Ye Liu
John Hubbard
Reviewed-byQuoted 18 lines · Ye Liu
Quoted 15 lines · John Hubbard
Quoted 13 lines · Ye Liu
From: Ye Liu <[email protected]>
If the kernel command line includes "
debug_guardpage_minorder" without an equals sign (i.e., no value is provided), the early parameter parser passes a NULL buf pointer to the setup function.
kstrtouint()does not perform a NULL check on its input and calls directly intokstrtoull()which dereferences s[0] unconditionally, leading to a NULL pointer dereference and early boot crash.Additionally, the error path's
pr_err("%s", buf)would also crash with a NULL format argument.
Quoted 7 lines
Quoted 2 lines
Maybe a "Fixes:" tag is called for?
Add the following Fixes. Thanks.
Fixes c0a32fc5a2e4 ("mm: more intensive memory corruption debugging")
Looks good,
thanks,
Signature · 1 line
John Hubbard
Quoted 24 lines
Quoted 23 lines
Quoted 11 lines
Signed-off-by Ye Liu <[email protected]>--- mm/debug_page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/debug_page_alloc.c +0
-0mm/debug_page_alloc.c static int __init debug_guardpage_minorder_setup(char *buf) · line 29
Quoted 10 lines
mm/debug_page_alloc.c +2
-2@@ -22,8 +22,8 @@ static int __init debug_guardpage_minorder_setup(char *buf) {unsigned int res; -if (kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { -pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf); +if (!buf ||kstrtouint (buf,10 , &res) <0 || res >MAX_PAGE_ORDER /2 ) { +pr_err ("Bad debug_guardpage_minorder value: %s\n" , buf ?:"(missing)" );return 0 ; } _debug_guardpage_minorder = res;thanks,