From: "Ard Biesheuvel" <ardb@kernel.org>
To: jaidevshastri@vt.edu, "Ilias Apalodimas" <ilias.apalodimas@linaro.org>
Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] efi: capsule: publish capsule_pending after efi_reset_type
Date: Thu, 24 Sep 2026 13:06:35 +0200 [thread overview]
Message-ID: <501132b4-eba0-4bf8-a9c0-0c209e1bee3a@app.fastmail.com> (raw)
In-Reply-To: <20260921-mb-efi-capsule-v1-1-fbf2a2032afb@vt.edu>
Hello Jaidev,
On Tue, 22 Sep 2026, at 03:09, Jaidev Shastri via B4 Relay wrote:
> From: Jaidev Shastri <jaidevshastri@vt.edu>
>
> efi_capsule_update_locked() sets capsule_pending and then
> efi_reset_type, both with plain stores. efi_capsule_pending() reads them
> from the reboot path without capsule_mutex.
>
> The comment above efi_capsule_pending() covers a caller that misses the
> update entirely. It does not cover the other outcome: with neither the
> stores nor the loads ordered, a caller can observe capsule_pending set
> and efi_reset_type still -1, and the reboot path then acts on a capsule
> with an invalid reset type.
>
> Write efi_reset_type first and publish the flag with
> smp_store_release(), paired with smp_load_acquire() in
> efi_capsule_pending(). A caller that misses the update entirely still
> behaves as documented.
>
> Found with MBCheck, a static herd7-based memory consistency checker.
>
> Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>
> ---
> drivers/firmware/efi/capsule.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
I think the tool's conclusion is correct that concurrent execution
of efi_capsule_pending() and efi_capsule_update() may result in the
re-ordering and subsequent misreporting of the EFI reset type.
However, in practice, efi_capsule_pending() is only called on the
reboot path after all other CPUs have been stopped, so there is
really nothing to fix here.
> diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c
> index dd6252638..2129007d8 100644
> --- a/drivers/firmware/efi/capsule.c
> +++ b/drivers/firmware/efi/capsule.c
> @@ -50,7 +50,8 @@ static DEFINE_MUTEX(capsule_mutex);
> */
> bool efi_capsule_pending(int *reset_type)
> {
> - if (!capsule_pending)
> + /* Pairs with the smp_store_release() in efi_capsule_update_locked(). */
> + if (!smp_load_acquire(&capsule_pending))
> return false;
>
> if (reset_type)
> @@ -173,8 +174,14 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule,
>
> status = efi.update_capsule(&capsule, 1, sglist_phys);
> if (status == EFI_SUCCESS) {
> - capsule_pending = true;
> efi_reset_type = reset;
> + /*
> + * efi_capsule_pending() reads the flag without capsule_mutex
> + * and then the reset type, which is stored above. Publish the
> + * flag with release semantics so that a reader that sees it
> + * also sees the matching reset type.
> + */
> + smp_store_release(&capsule_pending, true);
> }
>
> return efi_status_to_err(status);
>
> ---
> base-commit: 93f51579e7df248780214094418f205253383cc5
> change-id: 20260921-mb-efi-capsule-d111fa00ae80
>
> Best regards,
> --
> Jaidev Shastri <jaidevshastri@vt.edu>
prev parent reply other threads:[~2026-09-24 11:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 1:09 Jaidev Shastri via B4 Relay
2026-09-24 11:06 ` Ard Biesheuvel [this message]
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=501132b4-eba0-4bf8-a9c0-0c209e1bee3a@app.fastmail.com \
--to=ardb@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=jaidevshastri@vt.edu \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®