Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3661900imm; Mon, 10 Sep 2018 23:20:10 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda2PUYBpjMrrsbucysq/E7Nfi2/hNeVXuZW/eIiotcOM9R6buNiJsM+MRe9qkx6f0XAcsrc X-Received: by 2002:a63:5358:: with SMTP id t24-v6mr25705207pgl.208.1536646810836; Mon, 10 Sep 2018 23:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536646810; cv=none; d=google.com; s=arc-20160816; b=SeauUvxZFoBes01hDveESUezgidcBS4f8xTHmpF1JIX3R3haYsn07B3g3NlDyiGaQG j9GK5cm7Gyd4x9aqnrnImoP7jPfGO5ZVFS4eiuaFe9EDSm89u9TsznKP05e9TJBVojUg OaR2HiH3qJxSArXhCEPBJTEWWPyu3ba9ealUa/2NrPXNMICA9M7jhhNlXUkCKxmQqI1o AxT4Tl84HmYr0vMiVwps24UCF51PCx1U4VROSQCKelF/Gonz/YUXxnPjX/BTwyNC39Vv L2MpKVKvA97ivcXms3Xh6MXmnMkKK4Y6YU1Hq/a2hCGPvilpYAZzg0xUO43Joc1T5YGL 8qFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=xkWaYaDXHrWEl6x2lR+U782oQdoSb60Flks6zjDoacY=; b=v+x6qz51uHITXbSjq1ijx3Ant7vyu+uhQ3XeH2u7lVXXQlaFXntywlxGjgcG1YhFfh hpky5T8yJxKTzCXH3FA1ZE8+20GAJA7Y5zgNoP8gdHUmiaRmC6Tojm9824Qi66pXci5f ZhXzmUoV8QW46orVhHhlYbkdeVE7raSrnleNSd3SmzJ5RyGzIT3xRo43LpUKiWjdg3lw CeQZNQBQuCNInvbyYQp8clp0BCUS4aIlKcYkXgtVnUxbBtq6/i09tWCf1qf51jvtMLOG tXh/WdHE/dazWRPK4ybNBA0tQ9NDml1+5XF+QO67hgHCKRnlydaHnUOM9+YnTSPMZMbf E2hA== ARC-Authentication-Results: i=1; mx.google.com; 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 g16-v6si18848876pgi.373.2018.09.10.23.19.55; Mon, 10 Sep 2018 23:20:10 -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; 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 S1726675AbeIKLRG (ORCPT + 99 others); Tue, 11 Sep 2018 07:17:06 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50103 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726332AbeIKLRF (ORCPT ); Tue, 11 Sep 2018 07:17:05 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w8B6IwkN2135511 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 10 Sep 2018 23:18:58 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w8B6IwHS2135508; Mon, 10 Sep 2018 23:18:58 -0700 Date: Mon, 10 Sep 2018 23:18:58 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for He Zhe Message-ID: Cc: zhe.he@windriver.com, peterz@infradead.org, mingo@kernel.org, torvalds@linux-foundation.org, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, hpa@zytor.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, zhe.he@windriver.com, peterz@infradead.org In-Reply-To: <1534260823-87917-1-git-send-email-zhe.he@windriver.com> References: <1534260823-87917-1-git-send-email-zhe.he@windriver.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/boot] x86/corruption-check: Fix panic in memory_corruption_check() when boot option without value is provided Git-Commit-ID: ccde460b9ae5c2bd5e4742af0a7f623c2daad566 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ccde460b9ae5c2bd5e4742af0a7f623c2daad566 Gitweb: https://git.kernel.org/tip/ccde460b9ae5c2bd5e4742af0a7f623c2daad566 Author: He Zhe AuthorDate: Tue, 14 Aug 2018 23:33:42 +0800 Committer: Ingo Molnar CommitDate: Mon, 10 Sep 2018 14:47:32 +0200 x86/corruption-check: Fix panic in memory_corruption_check() when boot option without value is provided memory_corruption_check[{_period|_size}]()'s handlers do not check input argument before passing it to kstrtoul() or simple_strtoull(). The argument would be a NULL pointer if each of the kernel parameters, without its value, is set in command line and thus cause the following panic. PANIC: early exception 0xe3 IP 10:ffffffff73587c22 error 0 cr2 0x0 [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #2 [ 0.000000] RIP: 0010:kstrtoull+0x2/0x10 ... [ 0.000000] Call Trace [ 0.000000] ? set_corruption_check+0x21/0x49 [ 0.000000] ? do_early_param+0x4d/0x82 [ 0.000000] ? parse_args+0x212/0x330 [ 0.000000] ? rdinit_setup+0x26/0x26 [ 0.000000] ? parse_early_options+0x20/0x23 [ 0.000000] ? rdinit_setup+0x26/0x26 [ 0.000000] ? parse_early_param+0x2d/0x39 [ 0.000000] ? setup_arch+0x2f7/0xbf4 [ 0.000000] ? start_kernel+0x5e/0x4c2 [ 0.000000] ? load_ucode_bsp+0x113/0x12f [ 0.000000] ? secondary_startup_64+0xa5/0xb0 This patch adds checks to prevent the panic. Signed-off-by: He Zhe Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: gregkh@linuxfoundation.org Cc: kstewart@linuxfoundation.org Cc: pombredanne@nexb.com Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/1534260823-87917-1-git-send-email-zhe.he@windriver.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/check.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c index 33399426793e..cc8258a5378b 100644 --- a/arch/x86/kernel/check.c +++ b/arch/x86/kernel/check.c @@ -31,6 +31,11 @@ static __init int set_corruption_check(char *arg) ssize_t ret; unsigned long val; + if (!arg) { + pr_err("memory_corruption_check config string not provided\n"); + return -EINVAL; + } + ret = kstrtoul(arg, 10, &val); if (ret) return ret; @@ -45,6 +50,11 @@ static __init int set_corruption_check_period(char *arg) ssize_t ret; unsigned long val; + if (!arg) { + pr_err("memory_corruption_check_period config string not provided\n"); + return -EINVAL; + } + ret = kstrtoul(arg, 10, &val); if (ret) return ret; @@ -59,6 +69,11 @@ static __init int set_corruption_check_size(char *arg) char *end; unsigned size; + if (!arg) { + pr_err("memory_corruption_check_size config string not provided\n"); + return -EINVAL; + } + size = memparse(arg, &end); if (*end == '\0')