From patchwork Tue Sep 18 15:33:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: He Zhe X-Patchwork-Id: 10604495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 838105A4 for ; Tue, 18 Sep 2018 15:34:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 738CD2B4D8 for ; Tue, 18 Sep 2018 15:34:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 718182B557; Tue, 18 Sep 2018 15:34:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FB502B513 for ; Tue, 18 Sep 2018 15:34:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E1138E0002; Tue, 18 Sep 2018 11:34:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2921B8E0001; Tue, 18 Sep 2018 11:34:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A7EB8E0002; Tue, 18 Sep 2018 11:34:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id CF1698E0001 for ; Tue, 18 Sep 2018 11:34:47 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id h65-v6so1239452pfk.18 for ; Tue, 18 Sep 2018 08:34:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version; bh=nUuUgyORnjHPiBJnjB2z7B5AyMcyU39SJmiAeHE7GvA=; b=GSYg71XU6pSAjp8bwoYBdtw4s3gQe2M3Lyy0iOuar3P/Y6/+9h96xOoDUqRG0vW4Fm qiYbelKHJPQ4SC1vAnduuQSpHsldzuJ015V8u/emAVOh1ueYBQw/69iw5OaK2ZK4t6Zj iRceIciwwuK0zwSBvpDm61N8/Jd2+yp8qgWeb2aMqCGDNgizUgMBqSLbvaWXE9VZmKAp nwHj7eWynEcVRpAsd79pUs13PpmUKG5e+OuLfjco4GBSEiCgiCAEeQ5k40Gb3GUDqBlQ troAo8d/gLp35DwMp7wqrKtt+2ySkxx9jJzqvTD0iJm81ttbGUy8es3jpX/YdoNw1FuV V1KQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) smtp.mailfrom=Zhe.He@windriver.com X-Gm-Message-State: APzg51Bc4TOgsxXW1Bm7Kh0wH7qQGCRffrdnkXSpcky2tZVGG7+pcsOO CgBPg5MJXINwThtUGr17qeHDLCJ1Lm7CudnBqYx0+2c6MttrH77Es+3Kh65Ht9H+Jum3LW6SGX0 prRusN8qVvsBC6z6dkx0orhKxCL2bmYCRE9zH9xZR1ebul0Qf2/xGVgUZbcGjIl5XRA== X-Received: by 2002:a62:1605:: with SMTP id 5-v6mr31439839pfw.11.1537284887511; Tue, 18 Sep 2018 08:34:47 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda82EEDl3wZeHaBfq86fz+tSorMd/snA6tU5in/sRU2bpkymrt0+V5Zrfz1a4vlPSCn0obH X-Received: by 2002:a62:1605:: with SMTP id 5-v6mr31439756pfw.11.1537284886366; Tue, 18 Sep 2018 08:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537284886; cv=none; d=google.com; s=arc-20160816; b=x0I+f+sTD1LFG3ExEFrCevSJkJZhGxLKEH5fGjnTaMDDa3JBz9ibFFasxswNpTxzSJ S1fwmRYRk1va7ATYEo0imKvE0dPToXSCh7CEDiCaN/zO3eia/BvYdkAkVJQM93831eV2 auc1O2Apby+r0NMX32q2iXt7u9DnNFlHEC0ReQa96gknb32cD53Avzumtf72ePWBI6NT m2h9+Oqjt6pbRJ51BsZnFjcVeEnCwunRkklx5Z2yPsKZyAtESBKietkd8/4eGg/UzREe lV9JIk3THYnhECSwcDHqANSAGivHps7w429qKVrgIXxWFOianW9x7TRrQyhE1fkDG++7 /0cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:cc:to:from; bh=nUuUgyORnjHPiBJnjB2z7B5AyMcyU39SJmiAeHE7GvA=; b=0vKtsJdEVy+/IDEe8v8t8BZplyLSsePh4ByJKCoNrfc9nlYxiq0YqZHJLAtuFHxBS9 otWoiTbFrklDpuXPPDrlpIAGVZ89SfijQTgH5Cct2+iBXfFLV69uYefg7CJjEQgLqM8+ 0DPLpCmx4Mx0HPZ28/14z2ueQN+X7fxrHNEuub1tBY7jbyAj4rYyP33C0OX+ihAx+MDI QMVKbcT5ZnZ31K02py8rmP6r9FPff6xQ4gDKNURGuxf3GsX4OU/cP+uI+AVf5WwN9otw ngCU7VxbjjSTCMo1s0EhveUo+zoYrZFDdKMJKxRyPRwpU0NGR4IopRzY2t4cK56Faz6E gmCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) smtp.mailfrom=Zhe.He@windriver.com Received: from mail5.wrs.com (mail5.windriver.com. [192.103.53.11]) by mx.google.com with ESMTPS id j64-v6si16769326pgc.88.2018.09.18.08.34.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 08:34:46 -0700 (PDT) Received-SPF: pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) client-ip=192.103.53.11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) smtp.mailfrom=Zhe.He@windriver.com Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id w8IFXLdt009250 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 18 Sep 2018 08:33:32 -0700 Received: from pek-lpg-core2.corp.ad.wrs.com (128.224.153.41) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.408.0; Tue, 18 Sep 2018 08:33:11 -0700 From: To: , , , , , , , , , CC: Subject: [PATCH] mm/page_alloc: Fix panic caused by passing debug_guardpage_minorder or kernelcore to command line Date: Tue, 18 Sep 2018 23:33:08 +0800 Message-ID: <1537284788-428784-1-git-send-email-zhe.he@windriver.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: He Zhe debug_guardpage_minorder_setup and cmdline_parse_kernelcore do not check input argument before using it. The argument would be a NULL pointer if "debug_guardpage_minorder" or "kernelcore", without its value, is set in command line and thus causes the following panic. PANIC: early exception 0xe3 IP 10:ffffffffa08146f1 error 0 cr2 0x0 [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-rc4-yocto-standard+ #1 [ 0.000000] RIP: 0010:parse_option_str+0x11/0x90 ... [ 0.000000] Call Trace: [ 0.000000] cmdline_parse_kernelcore+0x19/0x41 [ 0.000000] do_early_param+0x57/0x8e [ 0.000000] parse_args+0x208/0x320 [ 0.000000] ? rdinit_setup+0x30/0x30 [ 0.000000] parse_early_options+0x29/0x2d [ 0.000000] ? rdinit_setup+0x30/0x30 [ 0.000000] parse_early_param+0x36/0x4d [ 0.000000] setup_arch+0x336/0x99e [ 0.000000] start_kernel+0x6f/0x4ee [ 0.000000] x86_64_start_reservations+0x24/0x26 [ 0.000000] x86_64_start_kernel+0x6f/0x72 [ 0.000000] secondary_startup_64+0xa4/0xb0 This patch adds a check to prevent the panic and adds KBUILD_MODNAME to prints. Signed-off-by: He Zhe Cc: stable@vger.kernel.org Cc: akpm@linux-foundation.org Cc: mhocko@suse.com Cc: vbabka@suse.cz Cc: pasha.tatashin@oracle.com Cc: mgorman@techsingularity.net Cc: aaron.lu@intel.com Cc: osalvador@suse.de Cc: iamjoonsoo.kim@lge.com --- mm/page_alloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 89d2a2a..d4cda06 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -14,6 +14,8 @@ * (lots of bits borrowed from Ingo Molnar & Andrew Morton) */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -630,6 +632,11 @@ static int __init debug_guardpage_minorder_setup(char *buf) { unsigned long res; + if (!buf) { + pr_err("Config string not provided\n"); + return -EINVAL; + } + if (kstrtoul(buf, 10, &res) < 0 || res > MAX_ORDER / 2) { pr_err("Bad debug_guardpage_minorder value\n"); return 0; @@ -6952,6 +6959,11 @@ static int __init cmdline_parse_core(char *p, unsigned long *core, */ static int __init cmdline_parse_kernelcore(char *p) { + if (!p) { + pr_err("Config string not provided\n"); + return -EINVAL; + } + /* parse kernelcore=mirror */ if (parse_option_str(p, "mirror")) { mirrored_kernelcore = true;