From: Lingzhu Xiang <lxiang@redhat.com>
To: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: Matt Fleming <matt.fleming@intel.com>,
Ben Hutchings <ben@decadent.org.uk>,
Josh Boyer <jwboyer@redhat.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"linux-efi@vger.kernel.org" <linux-efi@vger.kernel.org>,
Seth Forshee <seth.forshee@canonical.com>
Subject: Re: efi: be more paranoid about available space when creating variables
Date: Tue, 26 Mar 2013 12:31:11 +0800 [thread overview]
Message-ID: <5151248F.2010303@redhat.com> (raw)
In-Reply-To: <20130326035600.GA6209@srcf.ucam.org>
On 03/26/2013 11:56 AM, Matthew Garrett wrote:
> Ok, so having thought some more about the actual problem (ie, Samsungs
> go wrong if there's too much used space marked as being active, not
> merely too much used space) I think we really want to be looking for the
> amount of active space rather than the remaining space value that
> QueryVariableInfo() gives us. Something like this (absolutely untested,
> provided here for comment) patch? I'll try rigging something up under
> OVMF to test it. This version certainly seems a little over-naive, since
> it won't handle the case of a variable that's being overwritten with
> something of a different size.
>
> commit 263c2ee36c67dfa6d869304a3b5aef7a14f1ec4e
> Author: Matthew Garrett <matthew.garrett@nebula.com>
> Date: Mon Mar 25 13:40:28 2013 -0400
>
> efi: Distinguish between "remaining space" and actually used space
>
> EFI implementations distinguish between space that is actively used by a
> variable and space that merely hasn't been garbage collected yet. Space
> that hasn't yet been garbage collected isn't available for use and so isn't
> counted in the remaining_space field returned by QueryVariableInfo().
>
> Combined with commit 68d9298 this can cause problems. Some implementations
> don't garbage collect until the remaining space is smaller than the maximum
> variable size, and as a result check_var_size() will always fail once more
> than 50% of the variable store has been used even if most of that space is
> marked as available for garbage collection. The user is unable to create
> new variables, and deleting variables doesn't increase the remaining space.
Do you mean they don't garbage collect across reboots?
> The problem that 68d9298 was attempting to avoid was one where certain
> platforms fail if the actively used space is greater than 50% of the
> available storage space. We should be able to calculate that by simply
> summing the size of each available variable and subtracting that from
> the total storage space. With luck this will fix the problem described in
What about the size of variable name, paddings, headers (especially
authenticated ones) and other internal stuff?
> https://bugzilla.kernel.org/show_bug.cgi?id=55471 without permitting
> damage to occur to the machines 68d9298 was attempting to fix.
This bug is reporting "query_variable_info sets max_size as zero". If
that's true, this patch doesn't seem to account for that case.
>
> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
>
> diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
> index 7acafb8..731ac7b 100644
> --- a/drivers/firmware/efivars.c
> +++ b/drivers/firmware/efivars.c
> @@ -436,9 +436,12 @@ static efi_status_t
> check_var_size_locked(struct efivars *efivars, u32 attributes,
> unsigned long size)
> {
> - u64 storage_size, remaining_size, max_size;
> + u64 storage_size, remaining_size, max_size, active_available;
> + struct efivar_entry *entry;
> + struct efi_variable *var;
> efi_status_t status;
> const struct efivar_operations *fops = efivars->ops;
> + unsigned long active_size = 0;
>
> if (!efivars->ops->query_variable_info)
> return EFI_UNSUPPORTED;
> @@ -449,8 +452,16 @@ check_var_size_locked(struct efivars *efivars, u32 attributes,
> if (status != EFI_SUCCESS)
> return status;
>
> + list_for_each_entry(entry, &efivars->list, list) {
> + var = &entry->var;
> + get_var_data_locked(efivars, var);
> + active_size += var->DataSize;
> + }
> +
> + active_available = storage_size - active_size;
> +
> if (!storage_size || size > remaining_size || size > max_size ||
> - (remaining_size - size) < (storage_size / 2))
> + (active_available - size) < (storage_size / 2))
> return EFI_OUT_OF_RESOURCES;
>
> return status;
>
next prev parent reply other threads:[~2013-03-26 4:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1364004995.3728.76.camel@deadeye.wl.decadent.org.uk>
[not found] ` <1364010441.3728.82.camel@deadeye.wl.decadent.org.uk>
[not found] ` <1364010441.3728.82.camel-nDn/Rdv9kqW9Jme8/bJn5UCKIB8iOfG2tUK59QYPAWc@public.gmane.org>
2013-03-23 20:24 ` efi: be more paranoid about available space when creating variables Fleming, Matt
2013-03-23 20:32 ` Matthew Garrett
[not found] ` <1364070731.2553.47.camel-tCUS0Eywp2Pehftex57rkxo58HMYffqeLoYNBG0abjxeoWH0uzbU5w@public.gmane.org>
2013-03-23 22:50 ` Matt Fleming
[not found] ` <514E31B0.4030305-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-03-26 3:56 ` Matthew Garrett
2013-03-26 4:31 ` Lingzhu Xiang [this message]
[not found] ` <5151248F.2010303-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-03-26 4:34 ` Ben Hutchings
2013-03-26 4:35 ` Matthew Garrett
[not found] ` <20130326035600.GA6209-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2013-03-26 7:40 ` Lingzhu Xiang
2013-04-01 15:13 ` [PATCH 1/2] efi: Determine how much space is used by boot services-only variables Matthew Garrett
[not found] ` <1364829240-26475-1-git-send-email-matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA@public.gmane.org>
2013-04-01 15:14 ` [PATCH 2/2] efi: Distinguish between "remaining space" and actually used space Matthew Garrett
[not found] ` <1364829240-26475-2-git-send-email-matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA@public.gmane.org>
2013-04-01 15:50 ` Ben Hutchings
2013-04-03 13:11 ` Matt Fleming
[not found] ` <515C2A86.6070606-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-04-03 13:48 ` Matthew Garrett
2013-04-03 17:12 ` Matt Fleming
[not found] ` <515C62E6.1070004-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-04-03 17:20 ` Matthew Garrett
2013-04-01 15:42 ` [PATCH 1/2] efi: Determine how much space is used by boot services-only variables Ben Hutchings
2013-04-03 13:09 ` Matt Fleming
[not found] ` <515C29EE.8050008-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-04-03 13:42 ` Matthew Garrett
2013-03-26 10:37 ` efi: be more paranoid about available space when creating variables Matt Fleming
2013-03-26 15:43 ` Matthew Garrett
[not found] ` <20130326154359.GA20530-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2013-03-27 9:09 ` Matt Fleming
[not found] ` <5152B75B.5080305-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-04-01 6:31 ` Ben Hutchings
2013-03-26 23:33 ` Seiji Aguchi
[not found] ` <A5ED84D3BB3A384992CBB9C77DEDA4D41AF79528-ohthHghroY0jroPwUH3sq+6wyyQG6/Uh@public.gmane.org>
2013-03-27 9:10 ` Matt Fleming
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=5151248F.2010303@redhat.com \
--to=lxiang@redhat.com \
--cc=ben@decadent.org.uk \
--cc=jwboyer@redhat.com \
--cc=linux-efi@vger.kernel.org \
--cc=matt.fleming@intel.com \
--cc=mjg59@srcf.ucam.org \
--cc=seth.forshee@canonical.com \
--cc=stable@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;
as well as URLs for NNTP newsgroup(s).