Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp287285pxf; Tue, 6 Apr 2021 22:35:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK/hB5WH9FdBZ/USvZ9mfbpFms4dugXYzJgOAy/AJGAshCTACe2+iKy1ZTgmqapqYebHfu X-Received: by 2002:a6b:d318:: with SMTP id s24mr1209835iob.89.1617773759437; Tue, 06 Apr 2021 22:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617773759; cv=none; d=google.com; s=arc-20160816; b=BamzY96aXME6IC5FEVlVKNVUpuqVeM8s1xqEuYtMhyVMBOKzdBmvTYVxjJ98DLYvIs 3MtloLmrY6rWrliXQpf1YMNUhU0PYpaPrJYylyM+tzDGyeUbRNk6WEDawTb3ekApZB/W aOA8O0RB//XD+PX6J30iFcKvMrqsCNhklPvvDm7v/lbIlN853MRX7NaAmsM2V+KWRZxG Q7cqYGKtMqu81yIwpaAZtt8gjtoeHRy5L0l3Ic2nl0Sw814EA845dCxZ0YziTPB8Hl83 T6ZBi7XCZZnZLXYlY2LRquvvCVZINWT5AegbM0n5U3AZ3H3W7b+sTVYLcbcz5MHAJYRC oANA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=y9G6/jf3zobIkJzajUEXpnvsGBGadnjKD8d5G+SHk6c=; b=IKWhxkN6nMFXoSn4LFdYDWUrqmf8x+pszjayCUchGx4ww4OcvxVq7oblpEZeUE4N8O d6TBgI79nPSJ037vQIVJe9aRc62zUXmRh8cmQbwjEH2zG4P/K5V7dCKHZchMT6XNKzQ6 Eyxyrm5JLPTq5fE8CKVBeVNoOucsJOFjiTBfvkdB+PT2wHYM3VaiJjkivgl9ib8kd7Wh 7a/JxjOcJtQI/wdya7ADUyqRGzkA9sFd9WO4GXWsjhMawfOClS7n26/YZ+hqm2natkNX GHsmceqThTl1OIwH5QZhL2aj0uDMQyEY6AbaUrRv6eAke7MY2Xbuucgd+NNirlpPIk9V +IhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si6193599ilv.27.2021.04.06.22.35.47; Tue, 06 Apr 2021 22:35:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345325AbhDFOx1 (ORCPT + 99 others); Tue, 6 Apr 2021 10:53:27 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:42563 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239488AbhDFOx1 (ORCPT ); Tue, 6 Apr 2021 10:53:27 -0400 Received: from [192.168.1.12] (lfbn-lyo-1-457-219.w2-7.abo.wanadoo.fr [2.7.49.219]) (Authenticated sender: alex@ghiti.fr) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 7EA9D100008; Tue, 6 Apr 2021 14:53:17 +0000 (UTC) Subject: Re: [PATCH] driver: of: Properly truncate command line if too long To: Rob Herring Cc: 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: Tue, 6 Apr 2021 10:53:17 -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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 4/6/21 à 9:40 AM, Rob Herring a écrit : > On Sat, Apr 3, 2021 at 7:09 AM Alex Ghiti wrote: >> >> 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 ? > > It looks fine to me, but this will need to be adapted to the generic > command line support[1][2] when that is merged. So I've been waiting > to see if that's going to happen this cycle. Ok I'll take a look then, thanks. Alex > > Rob > > [1] https://lore.kernel.org/lkml/cover.1616765869.git.christophe.leroy@csgroup.eu/ > [2] https://lore.kernel.org/lkml/41021d66db2ab427c14255d2a24bb4517c8b58fd.1617126961.git.danielwa@cisco.com/ >