Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp893335yba; Thu, 18 Apr 2019 11:19:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXBbmg5Z+iSG5F4DRV7/UvJEU1LIiWC7rndmawQsMApca/ZH+W93weMws96b0azgFhSXJZ X-Received: by 2002:a17:902:864b:: with SMTP id y11mr96400421plt.1.1555611593612; Thu, 18 Apr 2019 11:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611593; cv=none; d=google.com; s=arc-20160816; b=QABGpXuTJrHDOWVMT85Z0goL155w/v8UWgWOQs8e78N5efa3BKX8q2WimA0v7jbbxo x8206TsepcU4UV9+x151KSZk0zP5eGz7Z+m1rSkOMvjc6pGtAJdvBo8bUgWkJlE9auz9 N0zre89Mf7VwzZ/gYpyZKpIDrFEEknGFZk8HBI5Erp95syTa4ddRNn/Wr75K2WBg6eRs Ck94fpWspOr6Dyauw16Ccb055Kc0bI+QDGDAviBPaEcVeMbwE/6OQzzFXc706yc+iBB8 UxQfKL8QqyDqxPAurtc9VZB8WVYPrd9m6q4v2tYYON+hx8gXDBzy+z2XFu+Tz1NUSmff mLTg== 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=d5TtYYS4iEw15ZnlDNCCRlZ95LDghQvjmIvq+99tM+Y=; b=Pz1LdRuH8hGaGMkW/qCX7WOXqBxW5hIFS+9HQqTu0Kv2/u1Ms2+pTHsC/1pgCanUHm 8ug4q5Xuh/WqOAT/IuZeMKxfxdDaFlBrlFLJM6sNAfjYLESjciVkP2M9/Fb9QxJSrEMU tSshDhC216ruCqkhv20bJmZsb8orkqmlNVMF2/yAkAl8zkOSYEp/8JQR8/jwhjU00XZF FEpu5qEWKVSnxtCdHYFW9pQ1F2x+7+05F5tEFAkKpZW22ZpTrXtOZ2er/sluYfK8riQu TK/25hyahK79ntJ5lCAbenpE7nHXD8QNX7saLiiMOdvw9afkK4khR/ccXyvqQnT6+vex 4JKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UckUm16P; 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 193si3161141pfv.108.2019.04.18.11.19.38; Thu, 18 Apr 2019 11:19:53 -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=UckUm16P; 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 S2404246AbfDRSLe (ORCPT + 99 others); Thu, 18 Apr 2019 14:11:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:41140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403910AbfDRSJa (ORCPT ); Thu, 18 Apr 2019 14:09:30 -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 DD9E421871; Thu, 18 Apr 2019 18:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610969; bh=kwDrbQ7Pdr5H1ZaQorcBxzavuMiV3zDRLEMzrrWthx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UckUm16PniVxhqOqK6Eb5KLZ30+GhaX4GnwtLQkPt/Tt1CiRPhEph/dryCR6c04RH Bnk4my2UOG/+4PfLvwLs/DKgk4iytqcT9FqlpNj/urm3+2qpaQCCvVZCSzQczTApbF MC/hMDiJM5KCR4FI8RsFOy6n5jW9T9OOTQwJvIYs= 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 5.0 01/93] ARC: u-boot args: check that magic number is correct Date: Thu, 18 Apr 2019 19:56:39 +0200 Message-Id: <20190418160436.924268700@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160436.781762249@linuxfoundation.org> References: <20190418160436.781762249@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 30e090625916..a72bbda2f7aa 100644 --- a/arch/arc/kernel/head.S +++ b/arch/arc/kernel/head.S @@ -106,6 +106,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] ; setup "current" tsk and optionally cache it in dedicated r25 diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c index 7b2340996cf8..7b3a7b3b380c 100644 --- a/arch/arc/kernel/setup.c +++ b/arch/arc/kernel/setup.c @@ -36,6 +36,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; @@ -497,6 +498,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) { @@ -511,6 +514,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