From patchwork Wed Apr 24 06:33:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 10914173 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 1BD09922 for ; Wed, 24 Apr 2019 06:33:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0814228A5A for ; Wed, 24 Apr 2019 06:33:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEE5628A5C; Wed, 24 Apr 2019 06:33:36 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4055C28A5A for ; Wed, 24 Apr 2019 06:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=TklCobzcvI+YSyqrwfVwBsycse1+PPino+yh9mev93s=; b=PcK 5RfR/S4+/yaWSFEI+vrJQ67MFDT4jJWzpGZl7w5M2hdN0eMlntQONjeu2OjjrmHv2P+/D4t6Ns2x5 VqENYrc2u9se5DPbRrmYKQhE0PXtFQGYF08SduaElZdHzwkSB0U2unpMoPvJmJqTdRFpvHs1qOWdn assDPxqs1mfqT5a5sviXP80H7sGdfmNXAK0p2FdElJVrtKqbIwcN0wLsAbveCzrCdSbSA5JgEzjTn LcT2y4sT77MBJAcVjtKae1W7QMKZcO/hsBJwOiB1d6zRndIfDLpSJ7mw0TfOtFNTjrl1sVzHv6KlM 0fB1bfv54ipyz0WVq5P68SpXsoc5Gog==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJBTL-0006j4-4S; Wed, 24 Apr 2019 06:33:35 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJBTH-0006ih-EB for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2019 06:33:33 +0000 Received: by mail-pg1-x544.google.com with SMTP id y3so8846534pgk.12 for ; Tue, 23 Apr 2019 23:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rRlxu7N8hh5xmQuGaWtAPwwzwkjSE7ZjtdBUkUzkFjg=; b=Ezl0obkMUXLsojuUPwA01naDDy0yKrnepNBLd4lPd2ogj9s6xLk3A2TjDLuz2fenG7 ic1ncquBHMQISfz0siFBdqAup/62d5eoVdl/a8pyn1Nnkj78+P4mjteyTe0Oy7bvYqH6 oYBEpBiwZHmMP8q/Y0OJ0bm0LYCN7/Wz5zJwZf8X6m/na4fWB2ed/Dos/tObiXWj5Qeu WmrqQlNUzxaEOUpos42bqrOoLI/LeFQSUCiO80alacHQfFejy/JMechtkfzMhThVPQBj cNNNPLp9A8YO2srFP15cERNQmHcL6QHsgJESTIyo3er5LezRZxTzcoexgDOG+j6n8+0j xmPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rRlxu7N8hh5xmQuGaWtAPwwzwkjSE7ZjtdBUkUzkFjg=; b=da+YSKbQgfrRep0pO47sKKGa5Xxi3UyGl25w2JHPrygBAuPiulmBI5iIcFE0abuSFo cJiTF0ZCprat54Wyekf1qeRTSzCxNEiK5xBtGIoV3zf9RjW5j0nWmPd3U+AdfrOBnQEx zhitg+WdixGLFLuOHIW7gso3iv8d5h55fNhE6W6e0GZqBdtuDD7xO5EwKsuFa2iuBsYZ o1+r+7ZUypZitUXHV8x8jd1hz5WqvS4BA+1VHZVZgDa8VsUneTXlRpJAn0Cn+o5Pvwgv ng1xZQvkVi144cVWQgqLNRoSB7ZN2D+tENGbf8SiKyWWT6YAGI3MyGBLtXzQI/xKlpI4 a2GQ== X-Gm-Message-State: APjAAAWQnU+aGzcB6APJAicGlsh8/tviODSW0hvczw989Qj1qYAv3onN SmpNTzKbp/BXbGJAcLP+xg== X-Google-Smtp-Source: APXvYqzQlHbnH5HCXIk8ZMzLqSw4EkgMnJ1gk/Twyi27YfBVratB8NIesvJpC7AnOuBzfoxS8N/8Sw== X-Received: by 2002:a63:1702:: with SMTP id x2mr28734847pgl.448.1556087610281; Tue, 23 Apr 2019 23:33:30 -0700 (PDT) Received: from mylaptop.nay.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i15sm24448356pfr.8.2019.04.23.23.33.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 23:33:29 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Subject: [PATCHv2] kernel/crash: make parse_crashkernel()'s return value more indicant Date: Wed, 24 Apr 2019 14:33:01 +0800 Message-Id: <1556087581-14513-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190423_233331_476915_2344D3E8 X-CRM114-Status: GOOD ( 18.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rich Felker , linux-ia64@vger.kernel.org, Julien Thierry , Yangtao Li , Benjamin Herrenschmidt , Palmer Dabbelt , Heiko Carstens , x86@kernel.org, Pingfan Liu , linux-mips@vger.kernel.org, Paul Mackerras , "H. Peter Anvin" , linux-s390@vger.kernel.org, Florian Fainelli , Yoshinori Sato , linux-sh@vger.kernel.org, Michael Ellerman , David Hildenbrand , Russell King , Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , James Hogan , Dave Young , Fenghua Yu , Will Deacon , linuxppc-dev@lists.ozlabs.org, Ananth N Mavinakayanahalli , Borislav Petkov , Stefan Agner , Thomas Gleixner , Hari Bathini , Jens Axboe , Tony Luck , Baoquan He , Ard Biesheuvel , Robin Murphy , Greg Kroah-Hartman , Ralf Baechle , Thomas Bogendoerfer , Paul Burton , Johannes Weiner , Martin Schwidefsky , Andrew Morton , Logan Gunthorpe , Greg Hackmann MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP At present, both return and crash_size should be checked to guarantee the success of parse_crashkernel(). Take a close look at the cases, which causes crash_size=0. Beside syntax error, three cases cause parsing to get crash_size=0. -1st. in parse_crashkernel_mem(), the demanded crash size is bigger than system ram. -2nd. in parse_crashkernel_mem(), the system ram size does not match any item in the range list. -3rd. "crashkernel=0MB", which is impractical. All these cases can be treated as invalid argument. By this way, only need a simple check on return value of parse_crashkernel(). Signed-off-by: Pingfan Liu Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Tony Luck Cc: Fenghua Yu Cc: Ralf Baechle Cc: Paul Burton Cc: James Hogan Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Yoshinori Sato Cc: Rich Felker Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Andrew Morton Cc: Julien Thierry Cc: Palmer Dabbelt Cc: Ard Biesheuvel Cc: Florian Fainelli Cc: Logan Gunthorpe Cc: Robin Murphy Cc: Greg Hackmann Cc: Stefan Agner Cc: Johannes Weiner Cc: David Hildenbrand Cc: Jens Axboe Cc: Thomas Bogendoerfer Cc: Greg Kroah-Hartman Cc: Hari Bathini Cc: Ananth N Mavinakayanahalli Cc: Yangtao Li Cc: Dave Young Cc: Baoquan He Cc: x86@kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-ia64@vger.kernel.org Cc: linux-mips@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-s390@vger.kernel.org Cc: linux-sh@vger.kernel.org --- v1 -> v2: On error, return -EINVAL for all failure cases arch/arm/kernel/setup.c | 2 +- arch/arm64/mm/init.c | 2 +- arch/ia64/kernel/setup.c | 2 +- arch/mips/kernel/setup.c | 2 +- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/kernel/machine_kexec.c | 2 +- arch/s390/kernel/setup.c | 2 +- arch/sh/kernel/machine_kexec.c | 2 +- arch/x86/kernel/setup.c | 4 ++-- kernel/crash_core.c | 10 +++++++++- 10 files changed, 19 insertions(+), 11 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 5d78b6a..2feab13 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -997,7 +997,7 @@ static void __init reserve_crashkernel(void) total_mem = get_total_mem(); ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); - if (ret) + if (ret < 0) return; if (crash_base <= 0) { diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 6bc1350..240918c 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -79,7 +79,7 @@ static void __init reserve_crashkernel(void) ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); /* no crashkernel= or invalid value specified */ - if (ret || !crash_size) + if (ret < 0) return; crash_size = PAGE_ALIGN(crash_size); diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index 583a374..3bbb58b 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c @@ -277,7 +277,7 @@ static void __init setup_crashkernel(unsigned long total, int *n) ret = parse_crashkernel(boot_command_line, total, &size, &base); - if (ret == 0 && size > 0) { + if (!ret) { if (!base) { sort_regions(rsvd_region, *n); *n = merge_regions(rsvd_region, *n); diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 8d1dc6c..168571b 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -715,7 +715,7 @@ static void __init mips_parse_crashkernel(void) total_mem = get_total_mem(); ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); - if (ret != 0 || crash_size <= 0) + if (ret < 0) return; if (!memory_region_available(crash_base, crash_size)) { diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index 45a8d0b..3571504 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -376,7 +376,7 @@ static inline unsigned long fadump_calculate_reserve_size(void) */ ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &size, &base); - if (ret == 0 && size > 0) { + if (!ret) { unsigned long max_size; if (fw_dump.reserve_bootvar) diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c index 63f5a93..1697ad2 100644 --- a/arch/powerpc/kernel/machine_kexec.c +++ b/arch/powerpc/kernel/machine_kexec.c @@ -122,7 +122,7 @@ void __init reserve_crashkernel(void) /* use common parsing */ ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); - if (ret == 0 && crash_size > 0) { + if (!ret) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; } diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index 2c642af..d4bd61b 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -671,7 +671,7 @@ static void __init reserve_crashkernel(void) crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN); crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN); - if (rc || crash_size == 0) + if (rc < 0) return; if (memblock.memory.regions[0].size < crash_size) { diff --git a/arch/sh/kernel/machine_kexec.c b/arch/sh/kernel/machine_kexec.c index 63d63a3..3c03240 100644 --- a/arch/sh/kernel/machine_kexec.c +++ b/arch/sh/kernel/machine_kexec.c @@ -157,7 +157,7 @@ void __init reserve_crashkernel(void) ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); - if (ret == 0 && crash_size > 0) { + if (!ret) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; } diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 3d872a5..592d5ad 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -526,11 +526,11 @@ static void __init reserve_crashkernel(void) /* crashkernel=XM */ ret = parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base); - if (ret != 0 || crash_size <= 0) { + if (ret < 0) { /* crashkernel=X,high */ ret = parse_crashkernel_high(boot_command_line, total_mem, &crash_size, &crash_base); - if (ret != 0 || crash_size <= 0) + if (ret < 0) return; high = true; } diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 093c9f9..83ee4a9 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -108,8 +108,10 @@ static int __init parse_crashkernel_mem(char *cmdline, return -EINVAL; } } - } else + } else { pr_info("crashkernel size resulted in zero bytes\n"); + return -EINVAL; + } return 0; } @@ -139,6 +141,8 @@ static int __init parse_crashkernel_simple(char *cmdline, pr_warn("crashkernel: unrecognized char: %c\n", *cur); return -EINVAL; } + if (*crash_size == 0) + return -EINVAL; return 0; } @@ -181,6 +185,8 @@ static int __init parse_crashkernel_suffix(char *cmdline, pr_warn("crashkernel: unrecognized char: %c\n", *cur); return -EINVAL; } + if (*crash_size == 0) + return -EINVAL; return 0; } @@ -266,6 +272,8 @@ static int __init __parse_crashkernel(char *cmdline, /* * That function is the entry point for command line parsing and should be * called from the arch-specific code. + * On success 0. On error for either syntax error or crash_size=0, -EINVAL is + * returned. */ int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,