efivars: Use local variables instead of a pointer dereference

In order to support a compat interface we need to stop passing pointers
to structures around, since the type of structure is going to depend on
whether the current task is a compat task.

Cc: Mike Waychison <mikew@google.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
This commit is contained in:
Matt Fleming 2014-03-16 12:14:49 +00:00
Родитель b738c6ea49
Коммит bafc84d539
1 изменённых файлов: 35 добавлений и 13 удалений

Просмотреть файл

@ -197,37 +197,48 @@ static ssize_t
efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
{ {
struct efi_variable *new_var, *var = &entry->var; struct efi_variable *new_var, *var = &entry->var;
efi_char16_t *name;
unsigned long size;
efi_guid_t vendor;
u32 attributes;
u8 *data;
int err; int err;
if (count != sizeof(struct efi_variable)) if (count != sizeof(struct efi_variable))
return -EINVAL; return -EINVAL;
new_var = (struct efi_variable *)buf; new_var = (struct efi_variable *)buf;
attributes = new_var->Attributes;
vendor = new_var->VendorGuid;
name = new_var->VariableName;
size = new_var->DataSize;
data = new_var->Data;
/* /*
* If only updating the variable data, then the name * If only updating the variable data, then the name
* and guid should remain the same * and guid should remain the same
*/ */
if (memcmp(new_var->VariableName, var->VariableName, sizeof(var->VariableName)) || if (memcmp(name, var->VariableName, sizeof(var->VariableName)) ||
efi_guidcmp(new_var->VendorGuid, var->VendorGuid)) { efi_guidcmp(vendor, var->VendorGuid)) {
printk(KERN_ERR "efivars: Cannot edit the wrong variable!\n"); printk(KERN_ERR "efivars: Cannot edit the wrong variable!\n");
return -EINVAL; return -EINVAL;
} }
if ((new_var->DataSize <= 0) || (new_var->Attributes == 0)){ if ((size <= 0) || (attributes == 0)){
printk(KERN_ERR "efivars: DataSize & Attributes must be valid!\n"); printk(KERN_ERR "efivars: DataSize & Attributes must be valid!\n");
return -EINVAL; return -EINVAL;
} }
if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 || if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
efivar_validate(new_var, new_var->Data, new_var->DataSize) == false) { efivar_validate(new_var, data, size) == false) {
printk(KERN_ERR "efivars: Malformed variable content\n"); printk(KERN_ERR "efivars: Malformed variable content\n");
return -EINVAL; return -EINVAL;
} }
memcpy(&entry->var, new_var, count); memcpy(&entry->var, new_var, count);
err = efivar_entry_set(entry, new_var->Attributes, err = efivar_entry_set(entry, attributes, size, data, NULL);
new_var->DataSize, new_var->Data, NULL);
if (err) { if (err) {
printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err); printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err);
return -EIO; return -EIO;
@ -328,13 +339,20 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
{ {
struct efi_variable *new_var = (struct efi_variable *)buf; struct efi_variable *new_var = (struct efi_variable *)buf;
struct efivar_entry *new_entry; struct efivar_entry *new_entry;
unsigned long size;
u32 attributes;
u8 *data;
int err; int err;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 || attributes = new_var->Attributes;
efivar_validate(new_var, new_var->Data, new_var->DataSize) == false) { size = new_var->DataSize;
data = new_var->Data;
if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
efivar_validate(new_var, data, size) == false) {
printk(KERN_ERR "efivars: Malformed variable content\n"); printk(KERN_ERR "efivars: Malformed variable content\n");
return -EINVAL; return -EINVAL;
} }
@ -345,8 +363,8 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
memcpy(&new_entry->var, new_var, sizeof(*new_var)); memcpy(&new_entry->var, new_var, sizeof(*new_var));
err = efivar_entry_set(new_entry, new_var->Attributes, new_var->DataSize, err = efivar_entry_set(new_entry, attributes, size,
new_var->Data, &efivar_sysfs_list); data, &efivar_sysfs_list);
if (err) { if (err) {
if (err == -EEXIST) if (err == -EEXIST)
err = -EINVAL; err = -EINVAL;
@ -370,14 +388,18 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
{ {
struct efi_variable *del_var = (struct efi_variable *)buf; struct efi_variable *del_var = (struct efi_variable *)buf;
struct efivar_entry *entry; struct efivar_entry *entry;
efi_char16_t *name;
efi_guid_t vendor;
int err = 0; int err = 0;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
name = del_var->VariableName;
vendor = del_var->VendorGuid;
efivar_entry_iter_begin(); efivar_entry_iter_begin();
entry = efivar_entry_find(del_var->VariableName, del_var->VendorGuid, entry = efivar_entry_find(name, vendor, &efivar_sysfs_list, true);
&efivar_sysfs_list, true);
if (!entry) if (!entry)
err = -EINVAL; err = -EINVAL;
else if (__efivar_entry_delete(entry)) else if (__efivar_entry_delete(entry))