aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2014-03-17 11:08:34 -0400
committerMatt Fleming <matt.fleming@intel.com>2014-04-17 08:53:48 -0400
commit54d2fbfb0c9d341c891926100ed0e5d4c4b0c987 (patch)
tree98f66a6f6fc09b9ecc84c07b95af323a6808098e /drivers/firmware/efi
parenta5d92ad32dad94fd8f3f61778561d532bb3a2f77 (diff)
efivars: Refactor sanity checking code into separate function
Move a large chunk of code that checks the validity of efi_variable into a new function, because we'll also need to use it for the compat code. Cc: Mike Waychison <mikew@google.com> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'drivers/firmware/efi')
-rw-r--r--drivers/firmware/efi/efivars.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
index 5ee2cfb96698..a44310c6a8ba 100644
--- a/drivers/firmware/efi/efivars.c
+++ b/drivers/firmware/efi/efivars.c
@@ -189,6 +189,35 @@ efivar_data_read(struct efivar_entry *entry, char *buf)
189 memcpy(buf, var->Data, var->DataSize); 189 memcpy(buf, var->Data, var->DataSize);
190 return var->DataSize; 190 return var->DataSize;
191} 191}
192
193static inline int
194sanity_check(struct efi_variable *var, efi_char16_t *name, efi_guid_t vendor,
195 unsigned long size, u32 attributes, u8 *data)
196{
197 /*
198 * If only updating the variable data, then the name
199 * and guid should remain the same
200 */
201 if (memcmp(name, var->VariableName, sizeof(var->VariableName)) ||
202 efi_guidcmp(vendor, var->VendorGuid)) {
203 printk(KERN_ERR "efivars: Cannot edit the wrong variable!\n");
204 return -EINVAL;
205 }
206
207 if ((size <= 0) || (attributes == 0)){
208 printk(KERN_ERR "efivars: DataSize & Attributes must be valid!\n");
209 return -EINVAL;
210 }
211
212 if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
213 efivar_validate(name, data, size) == false) {
214 printk(KERN_ERR "efivars: Malformed variable content\n");
215 return -EINVAL;
216 }
217
218 return 0;
219}
220
192/* 221/*
193 * We allow each variable to be edited via rewriting the 222 * We allow each variable to be edited via rewriting the
194 * entire efi variable structure. 223 * entire efi variable structure.
@@ -215,26 +244,9 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
215 size = new_var->DataSize; 244 size = new_var->DataSize;
216 data = new_var->Data; 245 data = new_var->Data;
217 246
218 /* 247 err = sanity_check(var, name, vendor, size, attributes, data);
219 * If only updating the variable data, then the name 248 if (err)
220 * and guid should remain the same 249 return err;
221 */
222 if (memcmp(name, var->VariableName, sizeof(var->VariableName)) ||
223 efi_guidcmp(vendor, var->VendorGuid)) {
224 printk(KERN_ERR "efivars: Cannot edit the wrong variable!\n");
225 return -EINVAL;
226 }
227
228 if ((size <= 0) || (attributes == 0)){
229 printk(KERN_ERR "efivars: DataSize & Attributes must be valid!\n");
230 return -EINVAL;
231 }
232
233 if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
234 efivar_validate(name, data, size) == false) {
235 printk(KERN_ERR "efivars: Malformed variable content\n");
236 return -EINVAL;
237 }
238 250
239 memcpy(&entry->var, new_var, count); 251 memcpy(&entry->var, new_var, count);
240 252