From patchwork Mon Jan 11 13:19:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 59480 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2105347lbb; Mon, 11 Jan 2016 05:21:40 -0800 (PST) X-Received: by 10.98.65.203 with SMTP id g72mr26133867pfd.44.1452518500852; Mon, 11 Jan 2016 05:21:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tl10si17210786pac.177.2016.01.11.05.21.40; Mon, 11 Jan 2016 05:21:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760013AbcAKNVj (ORCPT + 29 others); Mon, 11 Jan 2016 08:21:39 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:35264 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932793AbcAKNUP (ORCPT ); Mon, 11 Jan 2016 08:20:15 -0500 Received: by mail-wm0-f45.google.com with SMTP id f206so211201847wmf.0 for ; Mon, 11 Jan 2016 05:20:14 -0800 (PST) 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=kstwCp60R4b/GOn39S0I2jz3J+L6gTxQkQq7xHTGh7w=; b=W+0koYJUW0G1jluL0nEDSfhWNbVcNy+9CmWRuvyqHIqPZ4gSoNbDhkG8eMdqB6PRYY XOmUsOqNFXtbilnlDjPRoJofI0MelKEHS2/oVZSLDx78+pecQ8q8VyR0Yn+25q2vXy2/ eREH0fM+u2GcM1gUDV0HnMJ1emu035NfOSN+g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kstwCp60R4b/GOn39S0I2jz3J+L6gTxQkQq7xHTGh7w=; b=fykxdodUknRUJaQCK7K0ln/84BtLJWen0Ie2ohZUl4qL1FIwXJFOi2fIZmbDmoESho e2gYEyra2Jmtkbr6ZcdkXezqCs9xZ1Yigrqnzql6AANZY9Goy0BWoaGVd4i1+8vFtQPf n4LxmHnVFM2a2NOKF7gZ87v+g86u85qWrsRTkBZC4l+GhjDscM9BHCsqr/XoC2IrZ9vN iC++62IrZ8tXfyO7DZmF5xAPJmlwDJ0YCk1Am9gbIdig5r5OfNrrLE2ZSkyz9Lm658Dj P+jMRWDQrhbUPY2LmS4xrdInioYzpHKQc10YoizRjwTZJHzh8Zu5XKh7rswxEridCrcV Oo3g== X-Gm-Message-State: ALoCoQmetpKARwyjYlOCXnsCnuO4BO7gLazdvOMpVzOBpRFKPtMnuxH96NQ14WsESBnVCIewpwiE+2WBVdlWadwrruRhiAQiLQ== X-Received: by 10.28.228.87 with SMTP id b84mr14532311wmh.36.1452518413800; Mon, 11 Jan 2016 05:20:13 -0800 (PST) Received: from localhost.localdomain (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by smtp.gmail.com with ESMTPSA id c15sm12766055wmd.19.2016.01.11.05.20.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 05:20:13 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, leif.lindholm@linaro.org, keescook@chromium.org, linux-kernel@vger.kernel.org Cc: stuart.yoder@freescale.com, bhupesh.sharma@freescale.com, arnd@arndb.de, marc.zyngier@arm.com, christoffer.dall@linaro.org, Ard Biesheuvel Subject: [PATCH v3 18/21] efi: stub: implement efi_get_random_bytes() based on EFI_RNG_PROTOCOL Date: Mon, 11 Jan 2016 14:19:12 +0100 Message-Id: <1452518355-4606-20-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> References: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This exposes the firmware's implementation of EFI_RNG_PROTOCOL via a new function efi_get_random_bytes(). Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/firmware/efi/libstub/efistub.h | 3 ++ drivers/firmware/efi/libstub/random.c | 35 ++++++++++++++++++++ include/linux/efi.h | 5 ++- 4 files changed, 43 insertions(+), 2 deletions(-) -- 2.5.0 diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index c0ddd1b8dca3..9f0c813d739c 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -23,7 +23,7 @@ KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \ GCOV_PROFILE := n KASAN_SANITIZE := n -lib-y := efi-stub-helper.o +lib-y := efi-stub-helper.o random.o # include the stub's generic dependencies from lib/ when building for ARM/arm64 arm-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c sort.c diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 6b6548fda089..206b7252b9d1 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -43,4 +43,7 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size, unsigned long desc_size, efi_memory_desc_t *runtime_map, int *count); +efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table, + unsigned long size, u8 *out); + #endif diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c new file mode 100644 index 000000000000..f539b1e31459 --- /dev/null +++ b/drivers/firmware/efi/libstub/random.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 Linaro Ltd; + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include + +#include "efistub.h" + +struct efi_rng_protocol_t { + efi_status_t (*get_info)(struct efi_rng_protocol_t *, + unsigned long *, efi_guid_t *); + efi_status_t (*get_rng)(struct efi_rng_protocol_t *, + efi_guid_t *, unsigned long, u8 *out); +}; + +efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table, + unsigned long size, u8 *out) +{ + efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID; + efi_status_t status; + struct efi_rng_protocol_t *rng; + + status = sys_table->boottime->locate_protocol(&rng_proto, NULL, + (void **)&rng); + if (status != EFI_SUCCESS) + return status; + + return rng->get_rng(rng, NULL, size, out); +} diff --git a/include/linux/efi.h b/include/linux/efi.h index 569b5a866bb1..13783fdc9bdd 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -299,7 +299,7 @@ typedef struct { void *open_protocol_information; void *protocols_per_handle; void *locate_handle_buffer; - void *locate_protocol; + efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **); void *install_multiple_protocol_interfaces; void *uninstall_multiple_protocol_interfaces; void *calculate_crc32; @@ -599,6 +599,9 @@ void efi_native_runtime_setup(void); #define EFI_PROPERTIES_TABLE_GUID \ EFI_GUID( 0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5 ) +#define EFI_RNG_PROTOCOL_GUID \ + EFI_GUID( 0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 ) + typedef struct { efi_guid_t guid; u64 table;