From patchwork Fri Jan 15 16:00:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 363655 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp422502jap; Fri, 15 Jan 2021 08:00:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdbavl/bqM0XiHtrWOE8W7XtDTUuFm5s97kNxyWSKva3R6AAp5xtsWoFU1sHC4O2bV9Ugl X-Received: by 2002:a17:906:5e45:: with SMTP id b5mr6201823eju.69.1610726435696; Fri, 15 Jan 2021 08:00:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610726435; cv=none; d=google.com; s=arc-20160816; b=e01rqSJhR08FKtxjw3fS9gRADWccc9sG8m35N6tpngzvEB72u+NZ1WdoDtKVj3T3bY M0PDqAZVjRMdO47I75949K/JgV8MCaH3Rr6JkyBlNbDVHiacaPXrLo/2GwL0DbJ9TcOp /BC/d+4CeUb4Y337L3b0fcBL9WE+i8Jdfo2YrKgfy+EDSM4Ff/PiUkTGiBRLIxwtpGcY 2BbDQmjbFBhGlH7MozdzfE8G1yR8AAJ/LbvwG3cIACtDB7Yo6jhog2QyjH20gWd1gk1O Ggy8x5iw4j2KbsiqCAJhZ+RlzcLP1QEv/IIAwoQi2iCT8tACAiN7DjUUnJ52m2K7XjnQ obYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=d9HkXdAeaNOUEppZBd2Lfzw/RwO9iBTfwbSNLYFs+KQ=; b=RZLczoh0eLj7K6z4QNiTH6cQiH55uDiy6bxtfGb6+R7ZRs8Fngc0quBrAGpW3Y3PIz 2DCkm+hCzlCxHiI+ZFsMl8Oj4lEfWuFbaZkv6ttKklqtj/vxtkvxi/sbjtgYSSCc4ozg Mbo+5OMCW0HAJ0gd6espRayAQucrSiiGtWmbAtr7uuJ/EqIpvwRl1EF4rBVWCgiOpL0P 27igXjE+3/fU4mcpTCX/wl4Bwchmi5AWNUhqDFR7tsDsADaoS5Dc6axlezcokD+ydxIn 0atDq8YkGAbRcxJhqzYVGegs5Jlt/NbzeogoJ4kRcpNQUhefB60It+Sqk4htdkuEFRS2 gdEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B7bEvVHe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id mj15si3852746ejb.102.2021.01.15.08.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 08:00:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B7bEvVHe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 982A882564; Fri, 15 Jan 2021 17:00:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="B7bEvVHe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 83EA5824E0; Fri, 15 Jan 2021 17:00:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4CB75824E0 for ; Fri, 15 Jan 2021 17:00:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x430.google.com with SMTP id a9so6323807wrt.5 for ; Fri, 15 Jan 2021 08:00:27 -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:mime-version :content-transfer-encoding; bh=d9HkXdAeaNOUEppZBd2Lfzw/RwO9iBTfwbSNLYFs+KQ=; b=B7bEvVHeLzqR2i439dTzqj79Jn0BDI6xbdRXbnwVyTK/bjnq8+BUxnWSCuiAdyi9/L Gx43/hMAvXlzyFFKOmyUCfKH3XOyuqYbK93LkyfdHh09ZNbEIh+5B1LpOLkOfBV+MV66 da917zzTx1ggeaaT/14OJo16mYTsh2APDYL0Y2WQhLv0wH1m4ZzRn6ton//j42zO9tXh rLEORtZUH1wO5dYu0Cq+rmCJWML47Kv38V0TKPlcmXSBV3PO0Iq00m5imow91OBZLCIO ADUdHty9GJzhZD2jYDYL8T5MUR14sywmChSAlV/BDf2kSO/mZ6Dh2K7CbdBLpLGSevrs prKQ== 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=d9HkXdAeaNOUEppZBd2Lfzw/RwO9iBTfwbSNLYFs+KQ=; b=mJvmItZN3Sk0bgcLNigawElj+ri5yW5JLlg2reoBp1PluZ+x0CH1nkTGxnKzMW7OjF AEJJ/miQBLdl+e4m19MNe16KH7KdxPqK5QbNubWmDCu2xViVv1uF98JQw9RgkBILDeMx V0MJY9W1WemX5sggKe0duFHzlhDxeMhEL3K4M3K5ffJtdgkTT4olSwSkyJKhr+afgcxm 6SxA4igl18GlGbueI9CCjIKn3LUVzltC1uNBecQmwTMZZ/+7bg8bgu/AsmppxmkwMX7J lexzhNCawOaxMLtgm8sMW5ABjo9+rR8aSsgHxhTdCqukwc/EryPK0WsJo8ZlVnRw/2LJ o4cg== X-Gm-Message-State: AOAM530q/qQgCYQ7NRNSdCUSaBfUJR9ALcHddlfQy0hVozxZ36Nr5tTG wPdQqEdkvfT+JMEAst/E4jk0iA== X-Received: by 2002:adf:f605:: with SMTP id t5mr13621917wrp.39.1610726426851; Fri, 15 Jan 2021 08:00:26 -0800 (PST) Received: from apalos.home ([2a02:587:4667:3e9:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g187sm7662039wmf.1.2021.01.15.08.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 08:00:26 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Atish Patra , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH] efi_loader: Avoid emitting efi_var_buf to .GOT Date: Fri, 15 Jan 2021 18:00:15 +0200 Message-Id: <20210115160016.181511-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Atish reports than on RISC-V, accessing the EFI variables causes a kernel panic. An objdump of the file verifies that, since the global pointer for efi_var_buf ends up in .GOT section which is not mapped in virtual address space for Linux. 0000000000000084 : 84: 715d addi sp,sp,-80 * objdump -dr 0000000000000086 <.LCFI2>: 86: e0a2 sd s0,64(sp) 88: fc26 sd s1,56(sp) 8a: e486 sd ra,72(sp) 8c: f84a sd s2,48(sp) 8e: f44e sd s3,40(sp) 90: f052 sd s4,32(sp) 92: ec56 sd s5,24(sp) 94: 00000497 auipc s1,0x0 94: R_RISCV_GOT_HI20 efi_var_buf 98: 0004b483 ld s1,0(s1) # 94 <.LCFI2+0xe> 98: R_RISCV_PCREL_LO12_I .L0 98: R_RISCV_RELAX *ABS* * objdump -t 0000000000000084 g F .text.efi_runtime 00000000000000b8 efi_var_mem_find With the patch applied: * objdump -dr 0000000000000086 <.LCFI2>: 86: e0a2 sd s0,64(sp) 88: fc26 sd s1,56(sp) 8a: e486 sd ra,72(sp) 8c: f84a sd s2,48(sp) 8e: f44e sd s3,40(sp) 90: f052 sd s4,32(sp) 92: ec56 sd s5,24(sp) 94: 00000497 auipc s1,0x0 94: R_RISCV_PCREL_HI20 .LANCHOR0 94: R_RISCV_RELAX *ABS* 98: 00048493 mv s1,s1 98: R_RISCV_PCREL_LO12_I .L0 98: R_RISCV_RELAX *ABS* * objdump -t 0000000000000008 l O .data.efi_runtime 0000000000000008 efi_var_buf On arm64 this works, because there's no .GOT entries for this and everything is converted to relative references. * objdump -dr (identical pre-post patch, only the new function shows up) 00000000000000b4 : b4: aa0003ee mov x14, x0 b8: 9000000a adrp x10, 0 b8: R_AARCH64_ADR_PREL_PG_HI21 .data.efi_runtime bc: 91000140 add x0, x10, #0x0 bc: R_AARCH64_ADD_ABS_LO12_NC .data.efi_runtime c0: aa0103ed mov x13, x1 c4: 79400021 ldrh w1, [x1] c8: aa0203eb mov x11, x2 cc: f9400400 ldr x0, [x0, #8] d0: b940100c ldr w12, [x0, #16] d4: 8b0c000c add x12, x0, x12 So let's switch efi_var_buf to static and create a helper function for anyone that needs to update it. Fixes: e01aed47d6a0 ("efi_loader: Enable run-time variable support for tee based variables") Reported-by: Atish Patra Signed-off-by: Ilias Apalodimas --- Atish can you give it a spin and let me know if this fixes the issue for you? The objdump seems to be correct now, but I am not familiar with RISC-V. No regressions on Arm with TEE or memory backed variables. include/efi_variable.h | 12 ++++++++++++ lib/efi_loader/efi_var_mem.c | 12 +++++++++++- lib/efi_loader/efi_variable_tee.c | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) -- 2.30.0.rc2 Reviewed-by: Heinrich Schuchardt Tested-by: Atish Patra diff --git a/include/efi_variable.h b/include/efi_variable.h index 4704a3c16e65..b2317eb7bf1c 100644 --- a/include/efi_variable.h +++ b/include/efi_variable.h @@ -306,4 +306,16 @@ efi_status_t __efi_runtime EFIAPI efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size, u16 *variable_name, efi_guid_t *guid); +/** + * efi_var_buf_update() - Update the value of efi_var_buf in efi_var_mem.c + * + * @var_buf: Source buffer + * + * efi_var_buf is special since we use it on Runtime Services. We need + * to keep it static in efi_var_mem.c and avoid having it pulled into + * .GOT. Since it has to be static this function must be used to update + * it + */ +void efi_var_buf_update(struct efi_var_file *var_buf); + #endif diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c index d155f25f60e6..fcf0043b5d3b 100644 --- a/lib/efi_loader/efi_var_mem.c +++ b/lib/efi_loader/efi_var_mem.c @@ -10,7 +10,12 @@ #include #include -struct efi_var_file __efi_runtime_data *efi_var_buf; +/* + * keep efi_var_buf as static , moving it out might move it to .got + * which is not mapped in virtual address for Linux. Whenever + * we try to invoke get_variable service, it will panic. + */ +static struct efi_var_file __efi_runtime_data *efi_var_buf; static struct efi_var_entry __efi_runtime_data *efi_current_var; /** @@ -339,3 +344,8 @@ efi_get_next_variable_name_mem(efi_uintn_t *variable_name_size, return EFI_SUCCESS; } + +void efi_var_buf_update(struct efi_var_file *var_buf) +{ + memcpy(efi_var_buf, var_buf, EFI_VAR_BUF_SIZE); +} diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index be6f3dfad469..c69330443801 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -692,7 +692,7 @@ void efi_variables_boot_exit_notify(void) if (ret != EFI_SUCCESS) log_err("Can't populate EFI variables. No runtime variables will be available\n"); else - memcpy(efi_var_buf, var_buf, len); + efi_var_buf_update(var_buf); free(var_buf); /* Update runtime service table */