diff options
author | Seiji Aguchi <seiji.aguchi@hds.com> | 2012-11-14 15:25:37 -0500 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2012-11-26 19:01:46 -0500 |
commit | d80a361d779a9f19498943d1ca84243209cd5647 (patch) | |
tree | 7d142c3dd3b12f5d77aa9c105482bd2a1a9e354d /drivers/firmware | |
parent | 9489e9dcae718d5fde988e4a684a0f55b5f94d17 (diff) |
efi_pstore: Check remaining space with QueryVariableInfo() before writing data
[Issue]
As discussed in a thread below, Running out of space in EFI isn't a well-tested scenario.
And we wouldn't expect all firmware to handle it gracefully.
http://marc.info/?l=linux-kernel&m=134305325801789&w=2
On the other hand, current efi_pstore doesn't check a remaining space of storage at writing time.
Therefore, efi_pstore may not work if it tries to write a large amount of data.
[Patch Description]
To avoid handling the situation above, this patch checks if there is a space enough to log with
QueryVariableInfo() before writing data.
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Acked-by: Mike Waychison <mikew@google.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'drivers/firmware')
-rw-r--r-- | drivers/firmware/efivars.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index d10c9873dd9a..37ac21a08751 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c | |||
@@ -707,12 +707,29 @@ static int efi_pstore_write(enum pstore_type_id type, | |||
707 | struct efivars *efivars = psi->data; | 707 | struct efivars *efivars = psi->data; |
708 | struct efivar_entry *entry, *found = NULL; | 708 | struct efivar_entry *entry, *found = NULL; |
709 | int i, ret = 0; | 709 | int i, ret = 0; |
710 | u64 storage_space, remaining_space, max_variable_size; | ||
711 | efi_status_t status = EFI_NOT_FOUND; | ||
710 | 712 | ||
711 | sprintf(stub_name, "dump-type%u-%u-", type, part); | 713 | sprintf(stub_name, "dump-type%u-%u-", type, part); |
712 | sprintf(name, "%s%lu", stub_name, get_seconds()); | 714 | sprintf(name, "%s%lu", stub_name, get_seconds()); |
713 | 715 | ||
714 | spin_lock(&efivars->lock); | 716 | spin_lock(&efivars->lock); |
715 | 717 | ||
718 | /* | ||
719 | * Check if there is a space enough to log. | ||
720 | * size: a size of logging data | ||
721 | * DUMP_NAME_LEN * 2: a maximum size of variable name | ||
722 | */ | ||
723 | status = efivars->ops->query_variable_info(PSTORE_EFI_ATTRIBUTES, | ||
724 | &storage_space, | ||
725 | &remaining_space, | ||
726 | &max_variable_size); | ||
727 | if (status || remaining_space < size + DUMP_NAME_LEN * 2) { | ||
728 | spin_unlock(&efivars->lock); | ||
729 | *id = part; | ||
730 | return -ENOSPC; | ||
731 | } | ||
732 | |||
716 | for (i = 0; i < DUMP_NAME_LEN; i++) | 733 | for (i = 0; i < DUMP_NAME_LEN; i++) |
717 | efi_name[i] = stub_name[i]; | 734 | efi_name[i] = stub_name[i]; |
718 | 735 | ||
@@ -1237,6 +1254,7 @@ efivars_init(void) | |||
1237 | ops.get_variable = efi.get_variable; | 1254 | ops.get_variable = efi.get_variable; |
1238 | ops.set_variable = efi.set_variable; | 1255 | ops.set_variable = efi.set_variable; |
1239 | ops.get_next_variable = efi.get_next_variable; | 1256 | ops.get_next_variable = efi.get_next_variable; |
1257 | ops.query_variable_info = efi.query_variable_info; | ||
1240 | error = register_efivars(&__efivars, &ops, efi_kobj); | 1258 | error = register_efivars(&__efivars, &ops, efi_kobj); |
1241 | if (error) | 1259 | if (error) |
1242 | goto err_put; | 1260 | goto err_put; |