lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <3bd1df97-9633-a8cd-291c-906b8574565d@ghiti.fr>
Date:   Wed, 7 Apr 2021 02:35:03 -0400
From:   Alex Ghiti <alex@...ti.fr>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     Rob Herring <robh+dt@...nel.org>,
        Frank Rowand <frowand.list@...il.com>,
        Dmitry Vyukov <dvyukov@...gle.com>,
        "devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] driver: of: Properly truncate command line if too long

Hi Andy,

Le 4/6/21 à 6:56 PM, Andy Shevchenko a écrit :
> 
> 
> On Tuesday, March 16, 2021, Alexandre Ghiti <alex@...ti.fr 
> <mailto:alex@...ti.fr>> wrote:
> 
>     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@...gle.com
>     <mailto:dvyukov@...gle.com>>
>     Signed-off-by: Alexandre Ghiti <alex@...ti.fr <mailto:alex@...ti.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--;
> 
> 
> Shouldn’t you check for cmd_p being always bigger than or equal to data?

Yes you're right.

> 
>     +
>     +                       *cmd_p = '\0';
>     +
>     +                       pr_err("Command line is too long: truncated
>     to %d bytes\n",
>     +                              (int)(cmd_p - (char *)data + 1));
> 
> 
> Do you really need that casting?

No, I can use %td to print a pointer difference.

I'll send a v2.

Thanks,

Alex

> 
>     +               }
>     +       }
>     +
>              /*
>               * CONFIG_CMDLINE is meant to be a default in case nothing else
>               * managed to set the command line, unless CONFIG_CMDLINE_FORCE
>     -- 
>     2.20.1
> 
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ