Commit fdd4fa1c authored by Mateusz Nosek's avatar Mateusz Nosek Committed by Linus Torvalds

mm/page_alloc.c: fix early params garbage value accesses

Previously in '__init early_init_on_alloc' and '__init early_init_on_free'
the return values from 'kstrtobool' were not handled properly.  That
caused potential garbage value read from variable 'bool_result'.
Introduced patch fixes error handling.
Signed-off-by: default avatarMateusz Nosek <mateusznosek0@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Link: https://lkml.kernel.org/r/20200916214125.28271-1-mateusznosek0@gmail.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent cfb4a541
...@@ -156,16 +156,16 @@ static int __init early_init_on_alloc(char *buf) ...@@ -156,16 +156,16 @@ static int __init early_init_on_alloc(char *buf)
int ret; int ret;
bool bool_result; bool bool_result;
if (!buf)
return -EINVAL;
ret = kstrtobool(buf, &bool_result); ret = kstrtobool(buf, &bool_result);
if (ret)
return ret;
if (bool_result && page_poisoning_enabled()) if (bool_result && page_poisoning_enabled())
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, will take precedence over init_on_alloc\n"); pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, will take precedence over init_on_alloc\n");
if (bool_result) if (bool_result)
static_branch_enable(&init_on_alloc); static_branch_enable(&init_on_alloc);
else else
static_branch_disable(&init_on_alloc); static_branch_disable(&init_on_alloc);
return ret; return 0;
} }
early_param("init_on_alloc", early_init_on_alloc); early_param("init_on_alloc", early_init_on_alloc);
...@@ -174,16 +174,16 @@ static int __init early_init_on_free(char *buf) ...@@ -174,16 +174,16 @@ static int __init early_init_on_free(char *buf)
int ret; int ret;
bool bool_result; bool bool_result;
if (!buf)
return -EINVAL;
ret = kstrtobool(buf, &bool_result); ret = kstrtobool(buf, &bool_result);
if (ret)
return ret;
if (bool_result && page_poisoning_enabled()) if (bool_result && page_poisoning_enabled())
pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, will take precedence over init_on_free\n"); pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, will take precedence over init_on_free\n");
if (bool_result) if (bool_result)
static_branch_enable(&init_on_free); static_branch_enable(&init_on_free);
else else
static_branch_disable(&init_on_free); static_branch_disable(&init_on_free);
return ret; return 0;
} }
early_param("init_on_free", early_init_on_free); early_param("init_on_free", early_init_on_free);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment