Skip to contentSkip to conversation

mm: debug_page_alloc: fix NULL buf in debug_guardpage_minorder_setup

PATCH Applied Ye Liu 3 participants 5 messages Aug 6

Subsystems (2)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

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
index 41e3d1f1ad96..fd2664c3c86a 100644
@@ -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
reviewer Acked-by on v1 1/1
#1 lore raw
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 into kstrtoull() 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.

---
 mm/debug_page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

LGTM.

Signature · 2 lines
Best Regards,
Yan, Zi
#2 lore raw
In reply to Ye Liu
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 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.

Maybe a "Fixes:" tag is called for?

Quoted 10 lines
---
 mm/debug_page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug_page_alloc.c +0 -0
index 41e3d1f1ad96..fd2664c3c86a 100644

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
author
#3 lore raw
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 into kstrtoull() 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.

Fixes c0a32fc5a2e4 ("mm: more intensive memory corruption debugging")
Quoted 23 lines
Quoted 11 lines
---
 mm/debug_page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug_page_alloc.c +0 -0
index 41e3d1f1ad96..fd2664c3c86a 100644

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 · 2 lines
Thanks,
Ye Liu
Reviewed-by
#4 lore raw
Quoted 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 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.

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
---
 mm/debug_page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug_page_alloc.c +0 -0
index 41e3d1f1ad96..fd2664c3c86a 100644

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,