Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4694565imc; Mon, 25 Feb 2019 09:17:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IaNDBXV1ySOPA7rqrV7IXpg3E7h5NUbHeaPW3L4zkTrR28c0WcqMG6YQEwWJ819+bvAC3YN X-Received: by 2002:a63:5b43:: with SMTP id l3mr19907048pgm.298.1551115032688; Mon, 25 Feb 2019 09:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551115032; cv=none; d=google.com; s=arc-20160816; b=H1FjTzAfrSS0aef6DyPrmIyIQ9Qt5Scp1iK9Tg26G4lq+TnqDyVly3nJPliHtEPDO5 OYKNxS5mszBBo/AzOHa3hRiYGy5FEW0jUXguPC4cNYSXpSralFnwCarNi9RMTCYZTqeA p02O+mO3wmrU0lnhDiWRHyhhhtYk7/3xHsz/eKcfipM1yoCWAtF9k3a4YFaUyErZuDHS v3vvLrPWxiA0d+VskDNMTb2K+Q+/f7VpxmoJM9TqiAMc7LZFjOXQSmfLVFB/zE/Gr+CO A0nuUojzE6a/gQUrf95CX+xdZCFcmRVUv8m9lZsFSVhuEABK/Wf+UueFJNANbTs3moNr YNew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=4jIfwYpdGA6y3St3yHOSmYoTfl/tthKn+Rw/EOQvub0=; b=O8yK/js4z0u5jTpvL9o33jkUcECMCtOOEYOK9YESEIyVnDwYB8/ybUvZ+3EWxWgWLe iOywMqip5nx8+RxANS/3AQrVyIPebN4vsWtSir5OHyPTXWvjMH46oQud7LZfCvZlLiuU FNk1P0sedtnpQKW4Ki1ayGIsFpgkiAX2xpo4hdWRENN0mUf45PgtF1cKGJYv2y9BaV+R gB3+GWzCKIDRWeRAB5k9X23DRj8BtYJSJfZ8Su0VIr8Xzc0c3+csyZ9eFE91cvP8eEZ6 TclSzk0ylQdJGNw3D55zVqMwnO5u+OMOfsNFX5poN91BbEspbKp3gTrX2l9HP+Edov2M yvOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=Symr4B3w; 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 k14si9865747pgl.40.2019.02.25.09.16.57; Mon, 25 Feb 2019 09:17:12 -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=Symr4B3w; 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 S1728645AbfBYRQG (ORCPT + 99 others); Mon, 25 Feb 2019 12:16:06 -0500 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:41616 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728368AbfBYRQG (ORCPT ); Mon, 25 Feb 2019 12:16:06 -0500 Received: from mailhost.synopsys.com (dc8-mailhost2.synopsys.com [10.13.135.210]) (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 EF70D10C1B0C; Mon, 25 Feb 2019 09:16:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1551114965; bh=+AJZwoITg1zBzicOGaSlqYwX4ilh0Z250kgVtDqS5SA=; h=From:To:Cc:Subject:Date:From; b=Symr4B3wIicVyvUW5qa5fkxj9g0GaPdjhLlV0rj/wZu2YzCZugaVC80GgEhKtoAGO LYPLVHwCDQLO73jOy2LMquqiwSU14UdSouxzhygHpwL3MLgUpUSY4eMmqYz3ZRQi/H ouYUTOlngtJwrdKi/sos9LsmRZRpZCWOKtklHrEsHlMVM9Ak4jdbOawfvecHKaSAbC jyubTWXYNUoaeGluN/VhziTzinOlZ38ZyZeZdwLjZtltB8GqZg2BmKM7AP8y4R1IRK ImVvzwqZU2lrpM9iGeuRnzlM9NxIX/Sjq54Da6zZgFGIudzhVbnfkFICKduqmD88Vj CFtD++tXVZrSw== Received: from paltsev-e7480.internal.synopsys.com (paltsev-e7480.internal.synopsys.com [10.121.8.77]) by mailhost.synopsys.com (Postfix) with ESMTP id AACFBA0062; Mon, 25 Feb 2019 17:16:03 +0000 (UTC) From: Eugeniy Paltsev To: linux-snps-arc@lists.infradead.org, Vineet Gupta Cc: linux-kernel@vger.kernel.org, Alexey Brodkin , Eugeniy Paltsev Subject: [PATCH] ARC: u-boot args: check that magic number is correct Date: Mon, 25 Feb 2019 20:16:01 +0300 Message-Id: <20190225171601.5004-1-Eugeniy.Paltsev@synopsys.com> X-Mailer: git-send-email 2.14.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.14.5