From patchwork Wed Jul 4 15:49:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10507289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 801D960325 for ; Wed, 4 Jul 2018 15:50:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF61288DA for ; Wed, 4 Jul 2018 15:50:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F2CD28A49; Wed, 4 Jul 2018 15:50:40 +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,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 EA3DB28884 for ; Wed, 4 Jul 2018 15:50:39 +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:References: In-Reply-To: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:List-Owner; bh=iArRuTaAhcTWs7ISFQmQp0+v4Q90vLdNv0ptE0uhqSg=; b=HlEWRCHyxcvsq7NJwRR0hI5auO yTksjynDntpQwVGAD69V95zBCgiibO62lRbXTZj6Huzf80ZmKX7N4vsmk2x59tQtWKZP1XU488i3w GDFzzLWlU/fXffVvDLOoF/j5T0vt1cHgZpTuE0GwyFA2XwQKiRxUq5FEgWsCrEVOw6X36T9oBURQG y7EOCB3NxMz85eVJBOF811+LtwplJhLEvi/46b9STQUnSlbZLqek0sQlhHQtjHP3XJ7YdhnMkSdIM 8a9HkpXJPmVwE4Bh6SeDWJkOr71c2QBWv4s7cUIGfDOAVAvpC/57Co4IWf0mDiV+VwkDwKHq1lzBm WEtD9erw==; 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 1fak35-0007K2-Bu; Wed, 04 Jul 2018 15:50:31 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fak2C-0006KK-0e for linux-arm-kernel@lists.infradead.org; Wed, 04 Jul 2018 15:49:40 +0000 Received: by mail-ed1-x541.google.com with SMTP id x5-v6so679800edr.0 for ; Wed, 04 Jul 2018 08:49:26 -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:in-reply-to:references; bh=64T+khMvPYCSc0LkwmPl3whpa/BzeGLlPQrPkqAiBPk=; b=DpbE6zkHu73tGW2xQmaPlobB14zMLuQUA1Rz9f5O1wgO6YWPTSVyxIH59/4I1jH8ab aEtA73GupHB2h1dbZTdMditJ2TBysD03aafz/LKTQgwj8kvKYs3qhAaU/WeImxVItSmg MrhbGXX0kij7pghV/6RibtWdqD4wxGt97EFmY= 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:in-reply-to :references; bh=64T+khMvPYCSc0LkwmPl3whpa/BzeGLlPQrPkqAiBPk=; b=Dar7SVMfBMfu4sC8Xw39n9X7NH3NBSsJ7yQvZZ8RJiqj6AMJ2dKmxtDg5HwAEc1egs w5/OI5t2ixIy6wgQ0j4zXZnkq5F5qCjsLwKqI+sr8yJXLv8G8mcP8qPOIli/FTW2qzuV mPZO10dbN41rD6wTMZJWvR+1SOJgjSjrYlMqug2ZErd64o08bFKWdlW5zCooeCPiC1GD ZphOVIeP1ZUWY3V70RaBh4MpzeHocd+BDNAwEyE9c9YJj6qE/tACwjP/sAZg3O9ug7cx 7dntUFZE+N5n/Pyhn6BVXhgZNrHV/19ADAp+YLsmJLakcn5dmJnQ+Vsn7Z6jDTHiRpXt cLQw== X-Gm-Message-State: APt69E1WLuPBjxVeOwUrgoEHCYQlqu0EAgYO/WSUPBCGNYOURVpG9P7B UViSq2soK9MCCX0MLVYyqm6qew== X-Google-Smtp-Source: AAOMgpdg+A2WCGNmhr922X2DH36eVWjk05suFa/d7JIRJzKgFWs7y4e2fUUZto58gwG6zuNGvKGUVg== X-Received: by 2002:a50:8266:: with SMTP id 93-v6mr3281588edf.269.1530719365603; Wed, 04 Jul 2018 08:49:25 -0700 (PDT) Received: from ards-mac-mini.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id l61-v6sm1966954edl.96.2018.07.04.08.49.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 08:49:24 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Subject: [RFC PATCH 2/2] efi/libstub: taken contents of LinuxExtraArgs UEFI variable into account Date: Wed, 4 Jul 2018 17:49:19 +0200 Message-Id: <20180704154919.18564-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704154919.18564-1-ard.biesheuvel@linaro.org> References: <20180704154919.18564-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180704_084936_235669_70709317 X-CRM114-Status: GOOD ( 15.48 ) 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: mark.rutland@arm.com, Lorenzo Pieralisi , Ard Biesheuvel , Geoff Levand , catalin.marinas@arm.com, Riku Voipio , Sudeep Holla , will.deacon@arm.com, leif.lindholm@linaro.org, linux-acpi@vger.kernel.org, James Morse , Hanjun Guo , Mark Salter , linux-arm-kernel@lists.infradead.org, Ian Campbell 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 In order to allow UEFI platforms to persistently configure Linux kernel options without relying on the contents of the EFI System Partition (ESP) or other block devices, implement support for passing extra kernel command line arguments via the LinuxExtraArgs UEFI variable. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 51 ++++++++++++++++++++ include/linux/efi.h | 1 + 2 files changed, 52 insertions(+) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index 97a2423782af..49a3b03b9f1f 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -35,6 +35,9 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; static int __section(.data) __nokaslr; static int __section(.data) __quiet; +static const efi_guid_t linux_args_guid = LINUX_EFI_EXTRA_ARGS_GUID; +static const efi_char16_t linux_args_name[] = L"LinuxExtraArgs"; + int __pure nokaslr(void) { return __nokaslr; @@ -786,6 +789,33 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n) #define MAX_CMDLINE_ADDRESS ULONG_MAX #endif +static u16 *get_extra_args(efi_system_table_t *sys_table_arg, + unsigned long *extra_args_size) +{ + u16 *extra_args; + efi_status_t status; + + *extra_args_size = 0; + status = efi_call_runtime(get_variable, (efi_char16_t *)linux_args_name, + (efi_guid_t *)&linux_args_guid, NULL, + extra_args_size, NULL); + if (status != EFI_BUFFER_TOO_SMALL) + return NULL; + + status = efi_call_early(allocate_pool, EFI_LOADER_DATA, + *extra_args_size, (void **)&extra_args); + if (status != EFI_SUCCESS) + return NULL; + + status = efi_call_runtime(get_variable, (efi_char16_t *)linux_args_name, + (efi_guid_t *)&linux_args_guid, NULL, + extra_args_size, extra_args); + if (status != EFI_SUCCESS) + return NULL; + + return extra_args; +} + /* * Convert the unicode UEFI command line to ASCII to pass to kernel. * Size of memory allocated return in *cmd_line_len. @@ -799,9 +829,12 @@ char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, unsigned long cmdline_addr = 0; int load_options_chars = image->load_options_size / 2; /* UTF-16 */ const u16 *options = image->load_options; + u16 *extra_args; int cmd_line_bytes = 0; /* UTF-8 bytes */ int options_chars = 0; /* UTF-16 chars */ + int extra_args_chars = 0; /* UTF-16 chars */ efi_status_t status; + unsigned long extra_args_size; u16 zero = 0; if (options) @@ -813,6 +846,19 @@ char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, options = &zero; } + extra_args = get_extra_args(sys_table_arg, &extra_args_size); + if (extra_args) { + cmd_line_bytes += 1 + count_utf8_bytes(extra_args, + extra_args_size / 2, + &extra_args_chars); + + pr_efi(sys_table_arg, + "Appending contents of 'LinuxExtraArgs' UEFI variable to kernel command line.\n"); + } else if (extra_args_size > 0) { + pr_efi_err(sys_table_arg, + "Failed to read 'LinuxExtraArgs' UEFI variable\n"); + } + cmd_line_bytes++; /* NUL termination */ status = efi_high_alloc(sys_table_arg, cmd_line_bytes, 0, @@ -821,6 +867,11 @@ char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, return NULL; s1 = efi_utf16_to_utf8((u8 *)cmdline_addr, options, options_chars); + if (extra_args) { + *s1++ = ' '; + s1 = efi_utf16_to_utf8(s1, extra_args, extra_args_chars); + efi_call_early(free_pool, extra_args); + } *s1 = '\0'; *cmd_line_len = cmd_line_bytes; diff --git a/include/linux/efi.h b/include/linux/efi.h index 56add823f190..c0902384fa13 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -672,6 +672,7 @@ void efi_native_runtime_setup(void); #define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f) #define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b) #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa) +#define LINUX_EFI_EXTRA_ARGS_GUID EFI_GUID(0x7cae4e6a, 0x08d7, 0x4079, 0x8e, 0xcd, 0x8c, 0x2e, 0xf4, 0x72, 0x30, 0x40) typedef struct { efi_guid_t guid;