From: Alex Ghiti <alex@ghiti.fr>
To: Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] driver: of: Properly truncate command line if too long
Date: Sat, 3 Apr 2021 08:09:01 -0400 [thread overview]
Message-ID: <ee702ff7-f43c-745c-4157-b1cba53bb0b2@ghiti.fr> (raw)
In-Reply-To: <20210316193820.3137-1-alex@ghiti.fr>
Hi,
Le 3/16/21 à 3:38 PM, Alexandre Ghiti a écrit :
> In case the command line given by the user is too long, warn about it
> and truncate it to the last full argument.
>
> This is what efi already does in commit 80b1bfe1cb2f ("efi/libstub:
> Don't parse overlong command lines").
>
> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
> ---
> drivers/of/fdt.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index dcc1dd96911a..de4c6f9bac39 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -25,6 +25,7 @@
> #include <linux/serial_core.h>
> #include <linux/sysfs.h>
> #include <linux/random.h>
> +#include <linux/ctype.h>
>
> #include <asm/setup.h> /* for COMMAND_LINE_SIZE */
> #include <asm/page.h>
> @@ -1050,9 +1051,27 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
>
> /* Retrieve command line */
> p = of_get_flat_dt_prop(node, "bootargs", &l);
> - if (p != NULL && l > 0)
> + if (p != NULL && l > 0) {
> strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
>
> + /*
> + * If the given command line size is larger than
> + * COMMAND_LINE_SIZE, truncate it to the last complete
> + * parameter.
> + */
> + if (l > COMMAND_LINE_SIZE) {
> + char *cmd_p = (char *)data + COMMAND_LINE_SIZE - 1;
> +
> + while (!isspace(*cmd_p))
> + cmd_p--;
> +
> + *cmd_p = '\0';
> +
> + pr_err("Command line is too long: truncated to %d bytes\n",
> + (int)(cmd_p - (char *)data + 1));
> + }
> + }
> +
> /*
> * CONFIG_CMDLINE is meant to be a default in case nothing else
> * managed to set the command line, unless CONFIG_CMDLINE_FORCE
>
Any thought about that ?
Thanks,
Alex
next prev parent reply other threads:[~2021-04-03 12:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 19:38 [PATCH] driver: of: Properly truncate command line if too long Alexandre Ghiti
2021-04-03 12:09 ` Alex Ghiti [this message]
2021-04-06 13:40 ` Rob Herring
2021-04-06 14:53 ` Alex Ghiti
[not found] ` <CAHp75VfqztgEcs8wVD7k=F-cmXsVFN=_KTgcRq5+=HpjAJCZPQ@mail.gmail.com>
2021-04-07 6:35 ` Alex Ghiti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee702ff7-f43c-745c-4157-b1cba53bb0b2@ghiti.fr \
--to=alex@ghiti.fr \
--cc=devicetree@vger.kernel.org \
--cc=dvyukov@google.com \
--cc=frowand.list@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).