From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: "Ard Biesheuvel" <ardb@kernel.org>, "Kees Cook" <kees@kernel.org>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
stable@vger.kernel.org
Subject: [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock()
Date: Tue, 24 Nov 2026 18:28:12 +0100 [thread overview]
Message-ID: <20261124172811.2580784-9-ardb+git@google.com> (raw)
In-Reply-To: <20261124172811.2580784-7-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
efivar_lock() and efivar_trylock() check __efivars->ops after taking
efivars_lock, but __efivars itself is NULL whenever no efivars
implementation is registered.
That happens at runtime, not only before efivars is set up. For example,
tee_stmm_efi_probe() unregisters the generic efivars ops before
registering its own, and qcom_uefisecapp_remove() and gsmi_exit()
unregister efivars outright. A concurrent or subsequent efivarfs
access, or a write from a pstore backend that is still registered, then
dereferences a NULL pointer instead of failing with -ENODEV.
Check __efivars itself as well as __efivars->ops.
Fixes: 472831d4c4b2 ("efi: vars: Add thin wrapper around EFI get/set variable interface")
Cc: stable@vger.kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/vars.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index 3700e9869767..f9c28fbdb26d 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -143,7 +143,7 @@ int efivar_lock(void)
{
if (down_interruptible(&efivars_lock))
return -EINTR;
- if (!__efivars->ops) {
+ if (!__efivars || !__efivars->ops) {
up(&efivars_lock);
return -ENODEV;
}
@@ -159,7 +159,7 @@ int efivar_trylock(void)
{
if (down_trylock(&efivars_lock))
return -EBUSY;
- if (!__efivars->ops) {
+ if (!__efivars || !__efivars->ops) {
up(&efivars_lock);
return -ENODEV;
}
--
2.56.1.831.g720f3f5937-goog
next prev parent reply other threads:[~2026-11-24 17:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 17:28 [PATCH v2 0/5] efi: Fix pstore runtime en/disable Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel
2026-11-24 17:28 ` Ard Biesheuvel [this message]
2026-11-24 17:28 ` [PATCH v2 3/5] efi: Statically initialize efivar_ops_nh Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 4/5] efi: Tie 'efivars' pdev lifecycle to generic efivars Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 5/5] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124172811.2580784-9-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=gpiccoli@igalia.com \
--cc=kees@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=u.kleine-koenig@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).