Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp85773pxf; Tue, 6 Apr 2021 15:48:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3acOnys0+MW2qvIrUt8k5qiknsXzBh7Nn8Q6KX1nABC79FPT2kYkIN4xej2n38hAy/fkq X-Received: by 2002:a17:906:6a94:: with SMTP id p20mr376071ejr.68.1617749280566; Tue, 06 Apr 2021 15:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617749280; cv=none; d=google.com; s=arc-20160816; b=tnGe8WB53rijj0f0KUg30wKME6pU8DcB2yCJOkEsDsmfCDrv3+J3Jz12NV6Y8x8Qmp VcHVAAmx5Mr8IGs40Rx8V67ae8UO5zZf/jlQNSTEzejOD29SXL7AQAraZ3u+cAB44Ckj eGAZleGcSbGm593RWxZvuyuCSP3ExwSVIltGtMnakEa9C3uWtwcw8tnFK+T8XnEC9/k0 M54nTuaH6FIiqcmODkekPKKhX04KzPgDA9Sk3f0mn/P+V4KV60DqFCgobGDqnuiWgadn 7pqrPsUTwFRpoWxlsyV8EaceaamSAj+QX8ewpG5QC/Mb+a52U8tk5FCbcgRVaCg3TmaO YToQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EXvU3ED7oKZS9/IQHEq/4usC/WcWv6He7ulmCusym7Y=; b=bPe+mU2TYmBdvw5H68g663IaXx2/6OvBxSsRWK75rjVKnFl9wBGxQWrjGoIAnkopTJ ujwueyGiaS5Zylolg2sDY/u1DLM7Rju9otv+EduwoMajpHvLfdr4Y4TO8sASW4GuOQEt s4TZWURS0hKhgdrwipdg3WpD0PrCbvLNKdgO1aCXu2XaeD65snBwNhAM6R4qk9kIn2GX FmP8oeeWFydCs440ExszagshZi/I98q04InUZlC28wzY/k8dONk2I5nX6fzYW8yA8D8j FDZqRqQiNH0cMORpJB3VU+tyYJ2wKvL7rCTIR0evwBx1i5pkYPYzMa3uXmnFj6HOtjFl 9NgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKvTcGDz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si17698614ejr.633.2021.04.06.15.47.29; Tue, 06 Apr 2021 15:48:00 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKvTcGDz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344592AbhDFNlI (ORCPT + 99 others); Tue, 6 Apr 2021 09:41:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:33064 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238827AbhDFNlH (ORCPT ); Tue, 6 Apr 2021 09:41:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6348D613CC; Tue, 6 Apr 2021 13:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617716459; bh=qDqK8wQ/7+OGAOOi2xbtIaP4WgZISHYYxdJR7Ffc8M8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IKvTcGDzC+BV8Bn3ZgVr2JE1vpteJc7rq1gMuR8nj780i50TxUJANEw0ZH5G8+XkT XK8Kpx97almclBQpSzQbI+luXqdH2FqPtZIE48qvYuiDFh0Bq62OsNt/GtM994YGus oRZfWHUk7jf/F/2us8KgRPRdZe2DXfBxC6dq1YZbemKPlyCaPwycs6+WZxFTDKLdb4 6hFFpfRO8AoELDUyRUCN8EUotmaTvrQe4KiRE6I4J8bITjhXhMFTZ2ZsybQjXyfFo6 YrjEPTdHDEyC5X6pxLbyicG5ulYzKXh3tLwxfciAvAwhIpoPTA5LZpJFysCC1FbiQd puWOsH3D9xclg== Received: by mail-ed1-f50.google.com with SMTP id o19so16640223edc.3; Tue, 06 Apr 2021 06:40:59 -0700 (PDT) X-Gm-Message-State: AOAM532GaL8d11YEr7LabqA+jV9EDSaswilyKeF5BlCcLhNpmbMV2hLq dS9U+RGfDyOdaocvtJB1uTao8OZ+i2DJq/lzOw== X-Received: by 2002:a05:6402:5252:: with SMTP id t18mr38710035edd.258.1617716457827; Tue, 06 Apr 2021 06:40:57 -0700 (PDT) MIME-Version: 1.0 References: <20210316193820.3137-1-alex@ghiti.fr> In-Reply-To: From: Rob Herring Date: Tue, 6 Apr 2021 08:40:46 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] driver: of: Properly truncate command line if too long To: Alex Ghiti Cc: Frank Rowand , Dmitry Vyukov , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 3, 2021 at 7:09 AM Alex Ghiti wrote: > > Hi, > > Le 3/16/21 =C3=A0 3:38 PM, Alexandre Ghiti a =C3=A9crit : > > 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 lo= ng node, const char *uname, > > > > /* Retrieve command line */ > > p =3D of_get_flat_dt_prop(node, "bootargs", &l); > > - if (p !=3D NULL && l > 0) > > + if (p !=3D 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 =3D (char *)data + COMMAND_LINE_SIZE = - 1; > > + > > + while (!isspace(*cmd_p)) > > + cmd_p--; > > + > > + *cmd_p =3D '\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. Rob [1] https://lore.kernel.org/lkml/cover.1616765869.git.christophe.leroy@csgr= oup.eu/ [2] https://lore.kernel.org/lkml/41021d66db2ab427c14255d2a24bb4517c8b58fd.1= 617126961.git.danielwa@cisco.com/