Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp884279yba; Thu, 18 Apr 2019 11:10:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxKvAFfDn7EM8FSkUTiflVIOI728lMNaD6CeAaAnZNOwCd+hiDbOEq8GgCsjXkUhY8wgkC X-Received: by 2002:a63:5012:: with SMTP id e18mr534914pgb.383.1555611027876; Thu, 18 Apr 2019 11:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611027; cv=none; d=google.com; s=arc-20160816; b=P6JmHD3F6mSmO0jJR91DfzznJxkrDg3La7vdZJwoQ7+nxVaAGmi3AaJJGXO2WDxvaS 3zhsujBF5w0Ou6pQ6MfJL1XHfIrYUR5jK6i8CZe12PLKk8nB4uW8ljWB/wnmGsmUlk7f wai9WT3TnLlxzi+KfgtvYWzhu1CHCIEHm26yKdMUwTm3ZJlJEelmtB+IAFY4JE9ZdyxL i4vxt5Yi2ZLXpfwjE6/Dmt2ipe6V7tHObsprkX4ZeCyYamp1ikv9jJnz7Af/eCCx+/D3 ViM9BfqNwavnMKAGg+AVNB/JTXU5JMkyjUfDrj10n3YBzWlmKTo5hpCF8lNBBWREkp22 oFrQ== 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=u3qnFrwn2QPdwvhT4ZIkoGM0sRBCsnAMBxTwenwHG5c=; b=Go3jluV1UeoxzJ3D0uziLE9LGxum+O/Xy6aYuWxXY9jJXPhsLxjWA382qwvyAhlBAX +GEEQsqU3e9krh+S17k29IqHczqox9KETOevgWHWGURBWcvsZVtTnjBEk+fw0RBoxB0k 16TOS8k0YF94mpXG5hGGRfuRYY3uFnK4LFLBsS6lkFpdm7bXYSr+6MAnQ6Z1oStwkJUw HeyYpWtc8ZJg+tttIR1XpLZOPZ3GXrQ/jn6pshiCO8z2E37jGpemFUQtBUfhx4uTHXmr aWT4DCjzFOYZY9Q3VadpER1yVU2VIUhgF8QP+HkLJ/zhkg2my2X0odRvgN2XNAt3yozZ OrIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lwPD1QSH; 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 r184si2451309pgr.24.2019.04.18.11.10.12; Thu, 18 Apr 2019 11:10:27 -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=lwPD1QSH; 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 S2391609AbfDRSHS (ORCPT + 99 others); Thu, 18 Apr 2019 14:07:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:37430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391591AbfDRSHP (ORCPT ); Thu, 18 Apr 2019 14:07:15 -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 CE57B218FE; Thu, 18 Apr 2019 18:07:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610834; bh=DA5xvt7z+gzGXESXo++qjpNuS6n4RrWdkbESB+z74cQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lwPD1QSHVnvhE31VgraopwlKTuvdIW7u+bSQEfeCZ4SUlFTjkEFci+MCKg+wVi/gQ YCjZjDT1RSqiHG5wpGQlwtHZf9y+wSzynJqJrnyFwb4ckjgBVCRrwTECG/ydWkK2cT +4uYxpT0RLq1QScQ+e+P8xc070ru8Ktez09LyYlE= 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.9 01/50] ARC: u-boot args: check that magic number is correct Date: Thu, 18 Apr 2019 19:57:12 +0200 Message-Id: <20190418160422.904029591@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160422.455656724@linuxfoundation.org> References: <20190418160422.455656724@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 9119bea503a7..9f96120eee6e 100644 --- a/arch/arc/kernel/setup.c +++ b/arch/arc/kernel/setup.c @@ -32,6 +32,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; @@ -400,6 +401,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) { @@ -415,6 +418,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