From patchwork Fri Feb 14 13:46:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 865094 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp163229wrz; Fri, 14 Feb 2025 05:46:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXqUt+EtWbtqJpOniVrywPSKCBcp5Y38MHUNJPQNiWX1i/N9PZ2S2IGuZM5VddIQDJ3IIUWAw==@linaro.org X-Google-Smtp-Source: AGHT+IGwyvH+yPu9RN+8OnPmdEtUKzjZ3VEhj7L/a3UgPVQ5THbUk5Afj6syXu3qZxKMV2sxQYL3 X-Received: by 2002:a5d:5887:0:b0:38f:2861:8fa9 with SMTP id ffacd0b85a97d-38f286191d8mr6823320f8f.30.1739540815372; Fri, 14 Feb 2025 05:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739540815; cv=none; d=google.com; s=arc-20240605; b=GFdf5eW8raoQNjBjp5OwJo8KUY/eAoWghB+RigNnN5KDUKOiJmsJgzTRUJlrxH9Nb2 BR6eUYHx+W+awtXDl4xBMFRBFluqSf93USD0YVsCiUJA35ucIB406MgkSu+OAob9WU0k RqXea2tEGYMY6RdZe9693WX8Fx+v7PMAoPwkRuwbLReybat/Vr/kq1sifHohxWji3Jsd yO/4NV/tzr+/NsJEX2AFYtfuLDohCwK5/5ko31y2g7qRe8NiLSMGRAPTjg8xaOPfbS1j injfNE9TwK4UMwvvVPGRCSq6mw1uc31UgFquLnezOGeMaoMIKgZgjw/3CxrQNJRgWNtL KqyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=MS8sElT0ol9mirFZUQ7o/4Puh1j/VDoOzOalLIQooB4=; fh=KbRVlllmhXm5jURLMsxp+JqznyfOJXruP1ys4cS40HA=; b=HmzFuBIAVZ9FQXfOjHQEFMRJQU2rMUWKds7POyYTmGc3K7LpiIqtad8DGkrLfcQurl y+KR5rdlLDUO/3cZV9kAk/YzORVxr4S1rw8NKKr97m6yZtRxwx/9GMI7USL+lGTS9Rqw lWvL+jrMrW942TgK/gvSVabGkKgHNNWWL+91jlwTqGFI+0mCQInRMc8TZ0G6LHpyIDyz OdWwuKFtq1jIMCebi1H/y5G7FXkK9sFLprSt+1o+cPR9cXzafSq2IQqkUwjQPgggvvRA Q44QOJEQnnofWHp+3ER3TwjXJdtyvBeR5QP4vDpKI2sBFyc6nf9gJRuyOyG+jxeLdvk4 878A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gFLg7WmJ; 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; dara=neutral header.i=@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 ffacd0b85a97d-38f25a42031si4366482f8f.841.2025.02.14.05.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 05:46:55 -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=gFLg7WmJ; 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; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1BC2280756; Fri, 14 Feb 2025 14:46:54 +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="gFLg7WmJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CF39C80C7E; Fri, 14 Feb 2025 14:46:52 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 9D78B806FE for ; Fri, 14 Feb 2025 14:46:50 +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-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5de4d3bbc76so3340453a12.3 for ; Fri, 14 Feb 2025 05:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739540810; x=1740145610; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MS8sElT0ol9mirFZUQ7o/4Puh1j/VDoOzOalLIQooB4=; b=gFLg7WmJwpyWwgx+BkIuPUUNZPaL71YktWzsJjU2332oZ+fCdRnSGQTAwa07Ix/47J VuwZcs0I9rzEr5pTjUv2HGTfJbPCAPOyAz7wZv24zQP7ArTcobDhqzRMctcJWdnGFX91 Ro97tEWBX3rky7TuXaRoiifQit8kE1NLLq3NkHwXdq8tqF/wU+xybp7XOEMXowFULi6e N2xxv+8u/pUPZ7bZT724Xlc824um0eRkGf4TGA2Lxb/XM6TwzpLG8ddEnwOHkcrSsyUp Ra6EMf0dG3u/pTooEe20Eq5B4LzLpN+3wATixfoc/n9E8B+jU6aANz19Cld2e+bqUUu7 6OtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739540810; x=1740145610; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MS8sElT0ol9mirFZUQ7o/4Puh1j/VDoOzOalLIQooB4=; b=aX4qCdMA5F40fv5ppOP3DeqBKJbWwicI/H380yJJ615mHEFWEVpT1+lWW7USBiv6NT 7zz4DUxqy1USnjCeiQm3/3KwMYpoPgNG9GVKGlAviMg+j+Ke+E/4IhEppfZK4H6MZG1b u89qslSPwkIgDPvNwxfvnmFEW1EdrKuqjLWPuqIGx2rftSQU3ga5W0SZzoEFmESwBCGh sCaBEgo/3A6yCX11PDu8LkzXMPQkLOLWfPZQzQAHWhecDIkfwGwSXfP0QRtLnmonnmah 43QFQiLMb0yEEsh3I5mtyvv7Dk0FzuUBnGpzbGc56YZXcqwCWafEoJu8aQrp1Ti2geCC ksoA== X-Forwarded-Encrypted: i=1; AJvYcCWgTdgy3TLArz6LFxbQ9tKaFWwpa1mTo5Is4JISHi1LpWmpULj0n1WUglOys8CoP0CeDq5jwu4=@lists.denx.de X-Gm-Message-State: AOJu0Yy5CraJHbDiQpnYt/3GH8X8N+K/UquYIRl8ZL8ClbXG6m9dOEUg a+q9kl9ISrD03uRzSu7nbIcqNpexfohGZiZyAuyDyRMsMeMrmdmi2bmEk8dy3KIgoBeWC1+GfPN TzBA= X-Gm-Gg: ASbGncuzUuSKZmWzpHjxvKc5Wemr7Xjufde4H5ySNnwFzV7l93ZMfjeFDighGmgMX3q pyUkYVz2AyR2texA8mP+rTBL7SghZnhQyyIdLXJktE4GbmljEET3j/X1znHh2cad4f1pBqit45U zf9l5gPEqv23R1Ks09vlMzlPV7lLM+huaAEhqSF0J16LZ4bpipNR71VtPrARw4yFoc10HSYU0Aw Jp6QJXbmxrCHc3euYfcVU36PoTfBibURRTNq4f/nF2b4lU0f+0MSnyEhl6e2r0Zrlrx9ccAVYa2 snPGpCajqkOSEPM7y/lG3nl/OToHnby2iLe8wNZgsVgHN9kTkkr59nUT9mpmTSIEh86lAQ== X-Received: by 2002:a17:907:86a4:b0:ab7:d87f:6662 with SMTP id a640c23a62f3a-ab7f34a6156mr1076623466b.52.1739540809968; Fri, 14 Feb 2025 05:46:49 -0800 (PST) Received: from localhost.localdomain (ppp176092155198.access.hol.gr. [176.92.155.198]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aba53231f74sm349564866b.32.2025.02.14.05.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 05:46:49 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Tom Rini , u-boot@lists.denx.de Subject: [PATCH] efi_loader: remove comparisons to string literals from runtime Date: Fri, 14 Feb 2025 15:46:45 +0200 Message-ID: <20250214134646.173034-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean For EFI runtime services, we manage to preserve string literals by placing the .efi_runtime section just before .data and preserving it when marking the runtime memory by marking surrounding boottime code as runtime. This is ok for now but will break if we update any linker scripts and decouple .text and .runtime sections. So let's define the strings we used to compare in the appropriate section for runtime services Signed-off-by: Ilias Apalodimas Reviewed-by: Mark Kettenis --- lib/efi_loader/efi_var_mem.c | 3 ++- lib/efi_loader/efi_variable_tee.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c index b265d95dd6ba..31180df9e3a0 100644 --- a/lib/efi_loader/efi_var_mem.c +++ b/lib/efi_loader/efi_var_mem.c @@ -19,6 +19,7 @@ */ static struct efi_var_file __efi_runtime_data *efi_var_buf; static struct efi_var_entry __efi_runtime_data *efi_current_var; +static const u16 __efi_runtime_rodata vtf[] = u"VarToFile"; /** * efi_var_mem_compare() - compare GUID and name with a variable @@ -331,7 +332,7 @@ efi_get_variable_mem(const u16 *variable_name, const efi_guid_t *vendor, if (timep) *timep = var->time; - if (!u16_strcmp(variable_name, u"VarToFile")) + if (!u16_strcmp(variable_name, vtf)) return efi_var_collect_mem(data, data_size, EFI_VARIABLE_NON_VOLATILE); old_size = *data_size; diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index 0d090d051dd4..6a1fa39bb6f3 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -41,6 +41,7 @@ static u16 mm_sp_id; extern struct efi_var_file __efi_runtime_data *efi_var_buf; static efi_uintn_t max_buffer_size; /* comm + var + func + data */ static efi_uintn_t max_payload_size; /* func + data */ +static const u16 __efi_runtime_rodata pk[] = u"PK"; struct mm_connection { struct udevice *tee; @@ -858,7 +859,7 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, if (alt_ret != EFI_SUCCESS) goto out; - if (!u16_strcmp(variable_name, u"PK")) + if (!u16_strcmp(variable_name, pk)) alt_ret = efi_init_secure_state(); out: free(comm_buf);