Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp902058yba; Thu, 18 Apr 2019 11:29:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWjAqPrnA11lbNlUt2pizdlFRiPY7b3Kjew+SAJlvEa+OoaRDL4UwJdQJ/HMroAoPQTWmy X-Received: by 2002:a17:902:2a6a:: with SMTP id i97mr7935231plb.332.1555612189045; Thu, 18 Apr 2019 11:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555612189; cv=none; d=google.com; s=arc-20160816; b=AdMnuI4/rc3sIveBacxDGPdFfqW9sDhmfex3keapW71yGaSz0qIzoHrSzJwZ9mbDa7 Y4XWApwDplRVw8vPxs8vspaWSq+2hdGzesyRRB8nvLp2Xt5DxT4p/sjq9zq8O0n2obCj pym6OBz8w2ioieTnTdBMZIhFszO2i7u4RZVSF2lu3eCY63CSZ3KReT+bHwYn94HPZz01 10xGlCS4IYRh5TLbkRO/vGKJuXBBXSSgY6Go8ZFDfXxgyFxqG6PL1BaSMLakcXIYeq/4 5OfnNyH1/vJJ6Q1DVHXfSI92MVmQNaL7lLLEDP+p3CjH0LgFXdZbe47mYbnrE03tE26Q iS5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5I2x2BxzeGNcGxJXzYYE2I9t6vEiUUm7JpARa/dF9tI=; b=TczM4fBalsnCT72kvX66EtqSgAKsSjRcqYGqU9vUHWZj1yMr7tRbYIFnXC5rfMYBaz /0pNOngULrE9A+5P37MeIrV7QY0tRoV59A8C8Cxj4P+HAzGm65kcbcIyxkviJfGzxg5u F7ZOJqRHkz1V2AxaRpp1LPVwdlWhyaFMpUPWECrXDcq3vrYnANSdhVCNLYObq1wGTKdU 9TambHn9m506IJOpi+z1/skNw/yIvF63BxqDPesTg4ORoHwhSn9txIXqOX/LqFykx2xU g8mma3D/9ViJof9CM0L+xRoMqFwK5aAMi3vkf4ddCI7gTsxw1xakZq+5/qKrS6WOpu3l gKfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RJOhh6Q5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z13si2429752pgv.334.2019.04.18.11.29.34; Thu, 18 Apr 2019 11:29:49 -0700 (PDT) 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=@kernel.org header.s=default header.b=RJOhh6Q5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391031AbfDRS2q (ORCPT + 99 others); Thu, 18 Apr 2019 14:28:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:59682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390266AbfDRSDK (ORCPT ); Thu, 18 Apr 2019 14:03:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E81F721872; Thu, 18 Apr 2019 18:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610590; bh=zLI++sCPZGQ0OVaOT8taVqSvFLBfVMw3J5bK9CinC3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJOhh6Q588hF011LhyTO3AwOtFVw+3TZJUOR8gsowrVmk2tzddmdCiWv+DMjLxd4e 9qSZkmUoiRFHUbY2wVTCyDWWyA4tN7Jf7ZFKL/KVJ4jKRxt/gxRva9qPTxSQxDss0q hJJVebkjjl90GqjhHRNZaH4CePa0EqnS+Xf6qwzc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eugeniy Paltsev , Vineet Gupta , Sasha Levin Subject: [PATCH 4.14 01/92] ARC: u-boot args: check that magic number is correct Date: Thu, 18 Apr 2019 19:56:19 +0200 Message-Id: <20190418160430.489483154@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160430.325165109@linuxfoundation.org> References: <20190418160430.325165109@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit edb64bca50cd736c6894cc6081d5263c007ce005 ] In case of devboards we really often disable bootloader and load Linux image in memory via JTAG. Even if kernel tries to verify uboot_tag and uboot_arg there is sill a chance that we treat some garbage in registers as valid u-boot arguments in JTAG case. E.g. it is enough to have '1' in r0 to treat any value in r2 as a boot command line. So check that magic number passed from u-boot is correct and drop u-boot arguments otherwise. That helps to reduce the possibility of using garbage as u-boot arguments in JTAG case. We can safely check U-boot magic value (0x0) in linux passed via r1 register as U-boot pass it from the beginning. So there is no backward-compatibility issues. Signed-off-by: Eugeniy Paltsev Signed-off-by: Vineet Gupta Signed-off-by: Sasha Levin --- arch/arc/kernel/head.S | 1 + arch/arc/kernel/setup.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arch/arc/kernel/head.S b/arch/arc/kernel/head.S index 1f945d0f40da..208bf2c9e7b0 100644 --- a/arch/arc/kernel/head.S +++ b/arch/arc/kernel/head.S @@ -107,6 +107,7 @@ ENTRY(stext) ; r2 = pointer to uboot provided cmdline or external DTB in mem ; These are handled later in handle_uboot_args() st r0, [@uboot_tag] + st r1, [@uboot_magic] st r2, [@uboot_arg] #endif diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c index 709649e5f9bc..6b8d106e0d53 100644 --- a/arch/arc/kernel/setup.c +++ b/arch/arc/kernel/setup.c @@ -35,6 +35,7 @@ unsigned int intr_to_DE_cnt; /* Part of U-boot ABI: see head.S */ int __initdata uboot_tag; +int __initdata uboot_magic; char __initdata *uboot_arg; const struct machine_desc *machine_desc; @@ -433,6 +434,8 @@ static inline bool uboot_arg_invalid(unsigned long addr) #define UBOOT_TAG_NONE 0 #define UBOOT_TAG_CMDLINE 1 #define UBOOT_TAG_DTB 2 +/* We always pass 0 as magic from U-boot */ +#define UBOOT_MAGIC_VALUE 0 void __init handle_uboot_args(void) { @@ -448,6 +451,11 @@ void __init handle_uboot_args(void) goto ignore_uboot_args; } + if (uboot_magic != UBOOT_MAGIC_VALUE) { + pr_warn(IGNORE_ARGS "non zero uboot magic\n"); + goto ignore_uboot_args; + } + if (uboot_tag != UBOOT_TAG_NONE && uboot_arg_invalid((unsigned long)uboot_arg)) { pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg); -- 2.19.1