From patchwork Thu Jun 6 10:25:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 165973 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp8590843ili; Thu, 6 Jun 2019 03:25:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyChGIQWQigyWLS8SlEuOvCiFho+A8zaszaI+w2lxvRpga7EBWFn7E6UAbKLTl3l7VI5Lhj X-Received: by 2002:a17:902:760f:: with SMTP id k15mr24545340pll.125.1559816734322; Thu, 06 Jun 2019 03:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559816734; cv=none; d=google.com; s=arc-20160816; b=p/D26I9SBqTLtOQ9VbL29LZ3C4+FuHmLSZ/zuM9ffj0NZbnVKeOjhORDO8lElnN2Wv S4wM9ozonvFQ6KDRvVoCspc6JEcwjJuPmaWEVWga1hTOsTzEuPkKqoDNoGjqHXq2MYdM iUzTPgEAGcIAjxFOkoOxZbZZOV9CA3VmbvxuBLIGA6NNvWU0MoKUPt0EpfQclG3PUPm9 k6Yy+gZP+035+8b7Z4Xc10opNE/sPDZ+fuB4Q+IF73tf83INKxIY8/3ZQbV1DWrFb63t H/OfSoZzrkbDmLmqpMkL6p4ktt9kO/kKkSR7w8Xciw2ZbcFwPoDN5vHwKsF0GO/PguO2 fLdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RQPlTg6uUpRE5oDmTjzARjoKoGmiagH9gmTW8/5dICA=; b=rzUKvcJxsqE4DT7+Cr2itQMMpYFhe/gnFgcqeRRCt40k3mXP8bMau0ASBjUdIPJ7fO P27Fcfgjcyr/+6qn8qPKvLAv2QQ0tfOStxspL7aUIanha3CP1SZFq5p2zvrYtIX4SV7/ eAi7FxXO0R9eLl5dYx+Bk/iX4Mfhbe9I9H4zmzx8PaVubAvzTarqz+ZT2ZfP13StFg7h hdk9Ojdi17HFzLFqzLMg5SzzhSo+qflyaIuaYTsze7HBJjeCwZAzZJD4ZDshRbd3rIE9 f6iN0jtgjaks2W57oIyweziY3fGWMQBQv1cwpQ6NbDAVqswY+qvOiq+HWOuZCDKv/HjY 6S+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UHQRx9Q/"; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si1365391plr.193.2019.06.06.03.25.34; Thu, 06 Jun 2019 03:25:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=@linaro.org header.s=google header.b="UHQRx9Q/"; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbfFFKZd (ORCPT + 3 others); Thu, 6 Jun 2019 06:25:33 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51006 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727236AbfFFKZd (ORCPT ); Thu, 6 Jun 2019 06:25:33 -0400 Received: by mail-wm1-f66.google.com with SMTP id f204so1869838wme.0 for ; Thu, 06 Jun 2019 03:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RQPlTg6uUpRE5oDmTjzARjoKoGmiagH9gmTW8/5dICA=; b=UHQRx9Q/KPp0M2GSy4P9+yc1sYzXq6q24bkA1bqR34fF2QbVm13+ho75oqFRknjsgC SVVUmntzGH5wu64W+PUJ2neWS8USpW69Onp6mWIbCMvnkt63kIyE5iIvhMWBbfYfR2yY piidjN91uUZWF7z90ZuS4wSIEBr2PpAb03rs1gpvC0LXDh1HVP/ds7h0IMoGABHWIrGT VZks4dQi0P4RPa3OrKE7kfGroD+4lSUVh7ix1eHnE8FVbQHMlgBV/i8ICTZq7hNs/3J/ omvf6NHpSdeIdewEohYNsMq4fW2F9dCP8zjQ9tpWYNaUL/pGuolExMYF5nW506KlfTCm 558g== 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:mime-version :content-transfer-encoding; bh=RQPlTg6uUpRE5oDmTjzARjoKoGmiagH9gmTW8/5dICA=; b=V2y/9sOTaQuN+Y2+QK8FA3s/jz4v3R8YbsLbaYcd7+3QxurNOX6OSkgH+DbLXm24e9 nEvFzMqThNUJmb+dhzvKckVb2klEDYSIXf/v41nXu50pLv+sZpTgGe98JyPKu4rXRjwe F6GZL9sZ9rrqfmIo6gp9HCbBRuuiZECsMCSDrTiNpwRb6ESuLTK1HXoBtZGIPR+OxH80 eYbGV+dTlN3qHgb3rYydcKayfVa9gz7UCQR84bLgpHMk4Ex5lnWZRcQSdtMtlWEOLcKo TAZ3q+U9mx050E8x5kY/ExOkECN34NlOUDvSUT8Tg8k/JxAueO1YFMbbmPrw72WRFvsd OgGw== X-Gm-Message-State: APjAAAW4juFByyYd4vzhslajqa5XmJrqHV3EGlLPbi1TXBR11F17Mj08 5Ok2E4fSG7/EFYKTVV+kDEKdgw== X-Received: by 2002:a1c:c909:: with SMTP id f9mr13914013wmb.115.1559816730398; Thu, 06 Jun 2019 03:25:30 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:99ee:9f00:43cc:cfbf]) by smtp.gmail.com with ESMTPSA id u23sm1146611wmj.33.2019.06.06.03.25.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 03:25:29 -0700 (PDT) From: Ard Biesheuvel To: eb@emlix.com Cc: linux-efi@vger.kernel.org, gregkh@linuxfoundation.org, stable@vger.kernel.org, ndesaulniers@google.com, Ard Biesheuvel Subject: [PATCH for-4.9-stable] efi/libstub: Unify command line param parsing Date: Thu, 6 Jun 2019 12:25:13 +0200 Message-Id: <20190606102513.16321-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Commit 60f38de7a8d4e816100ceafd1b382df52527bd50 upstream. Merge the parsing of the command line carried out in arm-stub.c with the handling in efi_parse_options(). Note that this also fixes the missing handling of CONFIG_CMDLINE_FORCE=y, in which case the builtin command line should supersede the one passed by the firmware. Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Matt Fleming Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: bhe@redhat.com Cc: bhsharma@redhat.com Cc: bp@alien8.de Cc: eugene@hp.com Cc: evgeny.kalugin@intel.com Cc: jhugo@codeaurora.org Cc: leif.lindholm@linaro.org Cc: linux-efi@vger.kernel.org Cc: mark.rutland@arm.com Cc: roy.franz@cavium.com Cc: rruigrok@codeaurora.org Link: http://lkml.kernel.org/r/20170404160910.28115-1-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar [ardb: fix up merge conflicts with 4.9.180] Signed-off-by: Ard Biesheuvel --- This fixes the GCC build issue reported by Eike. Note that testing of arm64 stable kernels should cover CONFIG_RANDOMIZE_BASE, since it has a profound impact on how the kernel binary gets put together. drivers/firmware/efi/libstub/arm-stub.c | 23 ++++++-------------- drivers/firmware/efi/libstub/arm64-stub.c | 4 +--- drivers/firmware/efi/libstub/efi-stub-helper.c | 19 +++++++++------- drivers/firmware/efi/libstub/efistub.h | 2 ++ include/linux/efi.h | 2 +- 5 files changed, 22 insertions(+), 28 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 993aa56755f6..726d1467b778 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -18,7 +18,6 @@ #include "efistub.h" -bool __nokaslr; static int efi_get_secureboot(efi_system_table_t *sys_table_arg) { @@ -268,18 +267,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail; } - /* check whether 'nokaslr' was passed on the command line */ - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { - static const u8 default_cmdline[] = CONFIG_CMDLINE; - const u8 *str, *cmdline = cmdline_ptr; - - if (IS_ENABLED(CONFIG_CMDLINE_FORCE)) - cmdline = default_cmdline; - str = strstr(cmdline, "nokaslr"); - if (str == cmdline || (str > cmdline && *(str - 1) == ' ')) - __nokaslr = true; - } - si = setup_graphics(sys_table); status = handle_kernel_image(sys_table, image_addr, &image_size, @@ -291,9 +278,13 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail_free_cmdline; } - status = efi_parse_options(cmdline_ptr); - if (status != EFI_SUCCESS) - pr_efi_err(sys_table, "Failed to parse EFI cmdline options\n"); + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || + IS_ENABLED(CONFIG_CMDLINE_FORCE) || + cmdline_size == 0) + efi_parse_options(CONFIG_CMDLINE); + + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) + efi_parse_options(cmdline_ptr); secure_boot = efi_get_secureboot(sys_table); if (secure_boot > 0) diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c index 959d9b8d4845..f7a6970e9abc 100644 --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -24,8 +24,6 @@ #include "efistub.h" -extern bool __nokaslr; - efi_status_t check_platform_features(efi_system_table_t *sys_table_arg) { u64 tg; @@ -60,7 +58,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg, u64 phys_seed = 0; if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { - if (!__nokaslr) { + if (!nokaslr()) { status = efi_get_random_bytes(sys_table_arg, sizeof(phys_seed), (u8 *)&phys_seed); diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index 09d10dcf1fc6..1c963c4d1bde 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -32,6 +32,13 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; +static int __section(.data) __nokaslr; + +int __pure nokaslr(void) +{ + return __nokaslr; +} + /* * Allow the platform to override the allocation granularity: this allows * systems that have the capability to run with a larger page size to deal @@ -351,17 +358,13 @@ void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, * environments, first in the early boot environment of the EFI boot * stub, and subsequently during the kernel boot. */ -efi_status_t efi_parse_options(char *cmdline) +efi_status_t efi_parse_options(char const *cmdline) { char *str; - /* - * Currently, the only efi= option we look for is 'nochunk', which - * is intended to work around known issues on certain x86 UEFI - * versions. So ignore for now on other architectures. - */ - if (!IS_ENABLED(CONFIG_X86)) - return EFI_SUCCESS; + str = strstr(cmdline, "nokaslr"); + if (str == cmdline || (str && str > cmdline && *(str - 1) == ' ')) + __nokaslr = 1; /* * If no EFI parameters were specified on the cmdline we've got diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index fac67992bede..d0e5acab547f 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -15,6 +15,8 @@ */ #undef __init +extern int __pure nokaslr(void); + void efi_char16_printk(efi_system_table_t *, efi_char16_t *); efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, diff --git a/include/linux/efi.h b/include/linux/efi.h index e6711bf9f0d1..02c4f16685b6 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1427,7 +1427,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, unsigned long *load_addr, unsigned long *load_size); -efi_status_t efi_parse_options(char *cmdline); +efi_status_t efi_parse_options(char const *cmdline); efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg, struct screen_info *si, efi_guid_t *proto,