Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp889152ima; Wed, 6 Feb 2019 09:59:03 -0800 (PST) X-Google-Smtp-Source: AHgI3IaKF1DWHYaFrirL0fPQwtjHp5dPjMWI/P1Hpm+3DrNy9RS/QxOK9OkXVMVpUNTvFIoexXOg X-Received: by 2002:a17:902:780c:: with SMTP id p12mr11688726pll.197.1549475943581; Wed, 06 Feb 2019 09:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549475943; cv=none; d=google.com; s=arc-20160816; b=hY6owE3k14USdEhj6fooOG+uarZeUfPGfsT7jocLuG6Bt3CU1TO6XLqmKgfZ5ZKYaY t4du24fTRGcFsQ2apBfR4YtDH8Nx4LFcCU+jrCbkdV3K0n2zeeAEzc4w5zW117MU5HTr wNm+ZkBIoVdvJp1OxXbWoD2a0+Ym1JCjWK5PcpnKtE0L5giVEynHevUWqS6vzSmJR+Zc aCcgK+fUbBAH5DWrZonQpM1DY0Nsx7CcHbt9wVqO0iYNx9xjcMU8q/BQaQ+9IZKBNbJI okBvOmVtlTwG9eQ30YeFbm0xEp0L6z2ZqzcT2wFNfDO0cLOR81N2bCT5qmdYN4e5xQnJ y7gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5X2PKpQwbvP0WxKLqh9yVlbTH7DSPdBGxtB+J+E9eew=; b=0LmebPEJ9EAxQnygQtSn77f+czPFc5UFHLyhnQVQ8x75YOemKD+YD55xT3xgjRi9in sKnyaktFtY7/Y6AHuRZ6/JNtQZvFgtvS0wvBzgdqR5rm/QiSqiZ4q7n6O9sabgw/x4zE MDrUcdd4XoW+MhQ0yAYdamWb9Ckj1fugN4iolQFBpfpd/Tug7nPJQb/ehBky/fLNx0xl pfbK0DO/j7hBofCptx69oXupHtI9J7Q9aaXiAHbkbNb+/k4oPh30P4i/kg7OkqdwBEcJ URl2rAeEyNV5NeoTKVln8fBVbO0uGQSM6LfcNawG1yJPV0JO2IpHi/KVsDoOF86b9NGO 8z9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=TJWNLa2s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p7si2153792pfj.115.2019.02.06.09.58.47; Wed, 06 Feb 2019 09:59:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=TJWNLa2s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729764AbfBFRWk (ORCPT + 99 others); Wed, 6 Feb 2019 12:22:40 -0500 Received: from smtprelay.synopsys.com ([198.182.47.9]:39474 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727467AbfBFRWj (ORCPT ); Wed, 6 Feb 2019 12:22:39 -0500 Received: from mailhost.synopsys.com (dc2-mailhost2.synopsys.com [10.12.135.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtprelay.synopsys.com (Postfix) with ESMTPS id C627D24E0823; Wed, 6 Feb 2019 09:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1549473758; bh=KuLUmrRIpDBisiiey89ewnqfovSewf7V3Z8GihPSOCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TJWNLa2sU+cE82Zo94Bx9D5nfaPxe8kedLfCacRcbqZ2B/9tcw51KGFngMrwz670N dCw6c1h8sq2jM+k5HhDI+aLwROJD0EVXgSpvRSheSb+AymkBDx+kHEAYl1T6uV5jt8 kOkhAw+hJ0wW5veHQ/84kzXEJvhHlfmMGiro7rkvlUqomPp7g2xg3sBMcr0i5/MX0N s+WX5QkDs0MquhJB9iL5lXtdoN9gUhpryHLKqRHCquHRP8xFHD1DHmevIudhK7U7qa 84gH+G8qC/24uWJM0W7839uIhBr0T6toJnXpDr+mJ1wuZzqUAdkHe0BFe5CTbEzBav dNabOAPW5Gqug== Received: from paltsev-e7480.internal.synopsys.com (paltsev-e7480.internal.synopsys.com [10.121.3.66]) by mailhost.synopsys.com (Postfix) with ESMTP id EE403A0090; Wed, 6 Feb 2019 17:22:35 +0000 (UTC) From: Eugeniy Paltsev To: linux-snps-arc@lists.infradead.org, Vineet Gupta Cc: linux-kernel@vger.kernel.org, Alexey Brodkin , Corentin Labbe , khilman@baylibre.com, Eugeniy Paltsev Subject: [RFC 1/2] ARC: U-boot: check arguments paranoidly Date: Wed, 6 Feb 2019 20:22:27 +0300 Message-Id: <20190206172228.9261-2-Eugeniy.Paltsev@synopsys.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190206172228.9261-1-Eugeniy.Paltsev@synopsys.com> References: <20190206172228.9261-1-Eugeniy.Paltsev@synopsys.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle U-boot arguments paranoidly: * don't allow to pass unknown tag. * try to use external device tree blob only if corresponding tag (TAG_DTB) is set. * don't check: uboot_tag if kernel build with no ARC_UBOOT_SUPPORT. While I'm at it refactor U-boot arguments handling code. Signed-off-by: Eugeniy Paltsev --- arch/arc/kernel/head.S | 2 +- arch/arc/kernel/setup.c | 65 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/arch/arc/kernel/head.S b/arch/arc/kernel/head.S index 8b90d25a15cc..7095055bb874 100644 --- a/arch/arc/kernel/head.S +++ b/arch/arc/kernel/head.S @@ -95,7 +95,7 @@ ENTRY(stext) ; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2 ; r1 = magic number (board identity, unused as of now ; r2 = pointer to uboot provided cmdline or external DTB in mem - ; These are handled later in setup_arch() + ; These are handled later in handle_uboot_args() st r0, [@uboot_tag] st r2, [@uboot_arg] #endif diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c index feb90093e6b1..7edb35c26322 100644 --- a/arch/arc/kernel/setup.c +++ b/arch/arc/kernel/setup.c @@ -462,43 +462,64 @@ void setup_processor(void) arc_chk_core_config(); } -static inline int is_kernel(unsigned long addr) +static inline bool is_kernel(unsigned long addr) { - if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end) - return 1; - return 0; + return addr >= (unsigned long)_stext && addr <= (unsigned long)_end; } -void __init setup_arch(char **cmdline_p) +/* uboot_tag values for U-boot - kernel ABI revisions 0+; see head.S */ +#define UBOOT_REV0P_TAG_NONE 0 +#define UBOOT_REV0P_TAG_CMDLINE 1 +#define UBOOT_REV0P_TAG_DTB 2 + +void __init handle_uboot_args(void) { + bool append_boot_cmdline = false; + bool use_embedded_dtb = true; + #ifdef CONFIG_ARC_UBOOT_SUPPORT + /* check that we know this tag */ + if (uboot_tag != UBOOT_REV0P_TAG_NONE && + uboot_tag != UBOOT_REV0P_TAG_CMDLINE && + uboot_tag != UBOOT_REV0P_TAG_DTB) + panic("Invalid uboot tag: '%08x'\n", uboot_tag); + /* make sure that uboot passed pointer to cmdline/dtb is valid */ - if (uboot_tag && is_kernel((unsigned long)uboot_arg)) + if (uboot_tag != UBOOT_REV0P_TAG_NONE && is_kernel((unsigned long)uboot_arg)) panic("Invalid uboot arg\n"); /* See if u-boot passed an external Device Tree blob */ - machine_desc = setup_machine_fdt(uboot_arg); /* uboot_tag == 2 */ - if (!machine_desc) + if (uboot_tag == UBOOT_REV0P_TAG_DTB) { + machine_desc = setup_machine_fdt(uboot_arg); + + /* external Device Tree blob is invalid - use embedded one */ + use_embedded_dtb = !machine_desc; + } + + if (uboot_tag == UBOOT_REV0P_TAG_CMDLINE) + append_boot_cmdline = true; #endif - { - /* No, so try the embedded one */ + + if (use_embedded_dtb) { machine_desc = setup_machine_fdt(__dtb_start); if (!machine_desc) panic("Embedded DT invalid\n"); + } - /* - * If we are here, it is established that @uboot_arg didn't - * point to DT blob. Instead if u-boot says it is cmdline, - * append to embedded DT cmdline. - * setup_machine_fdt() would have populated @boot_command_line - */ - if (uboot_tag == 1) { - /* Ensure a whitespace between the 2 cmdlines */ - strlcat(boot_command_line, " ", COMMAND_LINE_SIZE); - strlcat(boot_command_line, uboot_arg, - COMMAND_LINE_SIZE); - } + /* + * If we are here, U-boot says that @uboot_arg is cmdline, so append it + * to embedded DT cmdline. + */ + if (append_boot_cmdline) { + /* Ensure a whitespace between the 2 cmdlines */ + strlcat(boot_command_line, " ", COMMAND_LINE_SIZE); + strlcat(boot_command_line, uboot_arg, COMMAND_LINE_SIZE); } +} + +void __init setup_arch(char **cmdline_p) +{ + handle_uboot_args(); /* Save unparsed command line copy for /proc/cmdline */ *cmdline_p = boot_command_line; -- 2.14.5