From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1192AC433ED for ; Sat, 3 Apr 2021 12:12:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C988E6112E for ; Sat, 3 Apr 2021 12:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236592AbhDCMJI (ORCPT ); Sat, 3 Apr 2021 08:09:08 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:48893 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236629AbhDCMJH (ORCPT ); Sat, 3 Apr 2021 08:09:07 -0400 X-Originating-IP: 2.7.49.219 Received: from [192.168.1.100] (lfbn-lyo-1-457-219.w2-7.abo.wanadoo.fr [2.7.49.219]) (Authenticated sender: alex@ghiti.fr) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 53949C0004; Sat, 3 Apr 2021 12:09:02 +0000 (UTC) Subject: Re: [PATCH] driver: of: Properly truncate command line if too long To: Rob Herring , Frank Rowand , Dmitry Vyukov , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210316193820.3137-1-alex@ghiti.fr> From: Alex Ghiti Message-ID: Date: Sat, 3 Apr 2021 08:09:01 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210316193820.3137-1-alex@ghiti.fr> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Alexandre Ghiti > --- > 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 > #include > #include > +#include > > #include /* for COMMAND_LINE_SIZE */ > #include > @@ -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