Message ID | 03f9401a6c8b87a1c786a2138d16b048f8d0eb53.1667336095.git.christophe.jaillet@wanadoo.fr (mailing list archive) |
---|---|
State | Mainlined |
Commit | f15be1b8d449a8eebe82d77164bf760804753651 |
Headers | show |
Series | None | expand |
On Tue, Nov 01, 2022 at 10:14:09PM +0100, Christophe JAILLET wrote: > strtobool() is the same as kstrtobool(). > However, the latter is more used within the kernel. > > In order to remove strtobool() and slightly simplify kstrtox.h, switch to > the other function name. > > While at it, include the corresponding header file (<linux/kstrtox.h>) > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > This patch is part of a serie that axes all usages of strtobool(). > Each patch can be applied independently from the other ones. > > The last patch of the serie removes the definition of strtobool(). > > You may not be in copy of the cover letter. So, if needed, it is available > at [1]. > > [1]: https://lore.kernel.org/all/cover.1667336095.git.christophe.jaillet@wanadoo.fr/ This seems in keeping with the removal of the simple_*str*() helpers: https://docs.kernel.org/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull Reviewed-by: Kees Cook <keescook@chromium.org>
On Tue, Nov 01, 2022 at 03:47:20PM -0700, Kees Cook wrote: > On Tue, Nov 01, 2022 at 10:14:09PM +0100, Christophe JAILLET wrote: ... > This seems in keeping with the removal of the simple_*str*() helpers: > https://docs.kernel.org/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull That piece of the documentation is partially wrong. Nobody will going to remove simple_strtox() due to their convenience when it's related to parse something from the stream. Yes, overflow is possible, but here is a trade-off. Note, kstrtox() may not work at early boot stages when we need to parse stream (with mixed digits and text and symbols) without acquiring space from the heap, i.o.w. RO strings.
On Tue, Nov 1, 2022 at 5:15 PM Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > strtobool() is the same as kstrtobool(). > However, the latter is more used within the kernel. > > In order to remove strtobool() and slightly simplify kstrtox.h, switch to > the other function name. > > While at it, include the corresponding header file (<linux/kstrtox.h>) > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > This patch is part of a serie that axes all usages of strtobool(). > Each patch can be applied independently from the other ones. > > The last patch of the serie removes the definition of strtobool(). > > You may not be in copy of the cover letter. So, if needed, it is available > at [1]. > > [1]: https://lore.kernel.org/all/cover.1667336095.git.christophe.jaillet@wanadoo.fr/ > --- > mm/page_table_check.c | 3 ++- > mm/usercopy.c | 3 ++- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/page_table_check.c b/mm/page_table_check.c > index 433dbce13fe1..93e633c1d587 100644 > --- a/mm/page_table_check.c > +++ b/mm/page_table_check.c > @@ -4,6 +4,7 @@ > * Copyright (c) 2021, Google LLC. > * Pasha Tatashin <pasha.tatashin@soleen.com> > */ > +#include <linux/kstrtox.h> > #include <linux/mm.h> > #include <linux/page_table_check.h> > > @@ -23,7 +24,7 @@ EXPORT_SYMBOL(page_table_check_disabled); > > static int __init early_page_table_check_param(char *buf) > { > - return strtobool(buf, &__page_table_check_enabled); > + return kstrtobool(buf, &__page_table_check_enabled); > } Acked-by: Pasha Tatashin <pasha.tatashin@soleen.com> > > early_param("page_table_check", early_page_table_check_param); > diff --git a/mm/usercopy.c b/mm/usercopy.c > index c1ee15a98633..4c3164beacec 100644 > --- a/mm/usercopy.c > +++ b/mm/usercopy.c > @@ -12,6 +12,7 @@ > > #include <linux/mm.h> > #include <linux/highmem.h> > +#include <linux/kstrtox.h> > #include <linux/slab.h> > #include <linux/sched.h> > #include <linux/sched/task.h> > @@ -258,7 +259,7 @@ static bool enable_checks __initdata = true; > > static int __init parse_hardened_usercopy(char *str) > { > - if (strtobool(str, &enable_checks)) > + if (kstrtobool(str, &enable_checks)) > pr_warn("Invalid option string for hardened_usercopy: '%s'\n", > str); > return 1; > -- > 2.34.1 >
diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 433dbce13fe1..93e633c1d587 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -4,6 +4,7 @@ * Copyright (c) 2021, Google LLC. * Pasha Tatashin <pasha.tatashin@soleen.com> */ +#include <linux/kstrtox.h> #include <linux/mm.h> #include <linux/page_table_check.h> @@ -23,7 +24,7 @@ EXPORT_SYMBOL(page_table_check_disabled); static int __init early_page_table_check_param(char *buf) { - return strtobool(buf, &__page_table_check_enabled); + return kstrtobool(buf, &__page_table_check_enabled); } early_param("page_table_check", early_page_table_check_param); diff --git a/mm/usercopy.c b/mm/usercopy.c index c1ee15a98633..4c3164beacec 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -12,6 +12,7 @@ #include <linux/mm.h> #include <linux/highmem.h> +#include <linux/kstrtox.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/sched/task.h> @@ -258,7 +259,7 @@ static bool enable_checks __initdata = true; static int __init parse_hardened_usercopy(char *str) { - if (strtobool(str, &enable_checks)) + if (kstrtobool(str, &enable_checks)) pr_warn("Invalid option string for hardened_usercopy: '%s'\n", str); return 1;
strtobool() is the same as kstrtobool(). However, the latter is more used within the kernel. In order to remove strtobool() and slightly simplify kstrtox.h, switch to the other function name. While at it, include the corresponding header file (<linux/kstrtox.h>) Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- This patch is part of a serie that axes all usages of strtobool(). Each patch can be applied independently from the other ones. The last patch of the serie removes the definition of strtobool(). You may not be in copy of the cover letter. So, if needed, it is available at [1]. [1]: https://lore.kernel.org/all/cover.1667336095.git.christophe.jaillet@wanadoo.fr/ --- mm/page_table_check.c | 3 ++- mm/usercopy.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)