Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp259275ybj; Fri, 8 May 2020 11:07:10 -0700 (PDT) X-Google-Smtp-Source: APiQypIYtcgIFifTog4PfOqlPDGCSfcAyLEm95eJt1Im2uGJtE8C1fCXOFSVSc2oXMbRDAOAqG3U X-Received: by 2002:a05:6402:1a2f:: with SMTP id be15mr3343439edb.385.1588961230623; Fri, 08 May 2020 11:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588961230; cv=none; d=google.com; s=arc-20160816; b=EQa1YsOzLq3WNgeeI8rtK5JbjZj0A1t7/R5kK/oAEVO+VYjB21TkjKYrDnNY3P26Ka R5NeCfM6OZ8WRHBtuPSRL3cV0hDsdyYmgtnxySwyvyfbDMm/WOCDE1CUto0z0O79jCHE 6p1vCWKg4f/aAPUEtWSVN7BG3nHG7HI9rwM+WvWCANm1ACfYzF+QmaYk9DWcQ1EL4jv7 1nYyXjortmdXA0eOZF4z/kgUjyA8haYr/JAAC+/MuBgU7gCh3qYf84GBl1Y8Eu6MICJU MaFbTxp0WwAiwy2HJMalLt8/2hh3INlv2qRqfJ7dCaWpRESC8fAFwSybImvPMoLp5yp8 koQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=BYV63hpUaYEHb0p7IiTy5tXNYdI7ucFlQSKZbWlHokA=; b=PqOGR2Y400yJF1z3XmqJMGILFOoNUgBRdK9q1iQLrVn8PKQ/xRYR/AAVTy4X9QP4BM PLsDnUENYLrJFLeaZUarjkxts1DOq3UQ5IRELHOToxVdpH7qlBf24PhtfdGipqnY7xR3 cC48E3uNoJwiZ7a/Q3pSsPbAy0x0C6YkQi4IoFSNar6lFJESlcGwLFPnvkOKy7j0PY0B ieWtHSuf2XdpieHy5ajdFadUTtSird3cfwpUtWf5prrbKMuJLV/j5ykDNiJewxTUhK8d Hnw7ev7FS1HHPL0MMxYehfOALuNFhH66tyuy/N4jmD7ZIv++19Jr0u4jUKxlvKxVNUHF 7aLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dC5rEQLj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by19si1274106ejc.362.2020.05.08.11.06.45; Fri, 08 May 2020 11:07:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dC5rEQLj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727971AbgEHSCw (ORCPT + 99 others); Fri, 8 May 2020 14:02:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:48342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbgEHSCu (ORCPT ); Fri, 8 May 2020 14:02:50 -0400 Received: from e123331-lin.nice.arm.com (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E205721974; Fri, 8 May 2020 18:02:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588960969; bh=2jew03jHhbJ4tYdttjEtxxUUZNb9+fBYEcl/Fza8KHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dC5rEQLjwHmHetLSEiZcwaxJZ1kftToq3Sp6pjkfQneV3LjotGcj4EyPYiA7DNe3n ekcMAJ/royVlIhZ5kVffwvaiWnDleZC4zneskzf9yOlj1m/U0GHnd81zVMS0hY318+ M6eBqLTOiJ76IilGtlBHdVnC9JgjZSME39z74Dvg= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arnd Bergmann , Arvind Sankar , Guenter Roeck , Joe Perches Subject: [PATCH 11/15] efi/libstub: Check return value of efi_parse_options Date: Fri, 8 May 2020 20:01:53 +0200 Message-Id: <20200508180157.1816-12-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200508180157.1816-1-ardb@kernel.org> References: <20200508180157.1816-1-ardb@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arvind Sankar efi_parse_options can fail if it is unable to allocate space for a copy of the command line. Check the return value to make sure it succeeded. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200430182843.2510180-12-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub.c | 23 +++++++++++++++++------ drivers/firmware/efi/libstub/x86-stub.c | 12 ++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 63541c2440ef..c2484bf75c5d 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -207,11 +207,21 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg) if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || IS_ENABLED(CONFIG_CMDLINE_FORCE) || - cmdline_size == 0) - efi_parse_options(CONFIG_CMDLINE); + cmdline_size == 0) { + status = efi_parse_options(CONFIG_CMDLINE); + if (status != EFI_SUCCESS) { + efi_err("Failed to parse options\n"); + goto fail_free_cmdline; + } + } - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) - efi_parse_options(cmdline_ptr); + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) { + status = efi_parse_options(cmdline_ptr); + if (status != EFI_SUCCESS) { + efi_err("Failed to parse options\n"); + goto fail_free_cmdline; + } + } efi_info("Booting Linux Kernel...\n"); @@ -223,7 +233,7 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg) dram_base, image); if (status != EFI_SUCCESS) { efi_err("Failed to relocate kernel\n"); - goto fail_free_cmdline; + goto fail_free_screeninfo; } efi_retrieve_tpm2_eventlog(); @@ -326,8 +336,9 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg) fail_free_image: efi_free(image_size, image_addr); efi_free(reserve_size, reserve_addr); -fail_free_cmdline: +fail_free_screeninfo: free_screen_info(si); +fail_free_cmdline: efi_free(cmdline_size, (unsigned long)cmdline_ptr); fail: return status; diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index c84c5678e3e1..37154bb93c59 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -739,12 +739,20 @@ unsigned long efi_main(efi_handle_t handle, } #ifdef CONFIG_CMDLINE_BOOL - efi_parse_options(CONFIG_CMDLINE); + status = efi_parse_options(CONFIG_CMDLINE); + if (status != EFI_SUCCESS) { + efi_err("Failed to parse options\n"); + goto fail; + } #endif if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr | ((u64)boot_params->ext_cmd_line_ptr << 32)); - efi_parse_options((char *)cmdline_paddr); + status = efi_parse_options((char *)cmdline_paddr); + if (status != EFI_SUCCESS) { + efi_err("Failed to parse options\n"); + goto fail; + } } /* -- 2.17.1