aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2014-03-17 06:57:00 -0400
committerMatt Fleming <matt.fleming@intel.com>2014-04-17 08:53:43 -0400
commita5d92ad32dad94fd8f3f61778561d532bb3a2f77 (patch)
tree16c7c63f80dedd7996d0efb341aa34ba8b295993
parente003bbee2a6a19a4c733335989284caf1b179e0d (diff)
efivars: Stop passing a struct argument to efivar_validate()
In preparation for compat support, we can't assume that user variable object is represented by a 'struct efi_variable'. Convert the validation functions to take the variable name as an argument, which is the only piece of the struct that was ever used anyway. Cc: Mike Waychison <mikew@google.com> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
-rw-r--r--drivers/firmware/efi/efivars.c6
-rw-r--r--drivers/firmware/efi/vars.c30
-rw-r--r--include/linux/efi.h6
3 files changed, 23 insertions, 19 deletions
diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
index 2c21cccc2572..5ee2cfb96698 100644
--- a/drivers/firmware/efi/efivars.c
+++ b/drivers/firmware/efi/efivars.c
@@ -231,7 +231,7 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
231 } 231 }
232 232
233 if ((attributes & ~EFI_VARIABLE_MASK) != 0 || 233 if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
234 efivar_validate(new_var, data, size) == false) { 234 efivar_validate(name, data, size) == false) {
235 printk(KERN_ERR "efivars: Malformed variable content\n"); 235 printk(KERN_ERR "efivars: Malformed variable content\n");
236 return -EINVAL; 236 return -EINVAL;
237 } 237 }
@@ -339,6 +339,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
339{ 339{
340 struct efi_variable *new_var = (struct efi_variable *)buf; 340 struct efi_variable *new_var = (struct efi_variable *)buf;
341 struct efivar_entry *new_entry; 341 struct efivar_entry *new_entry;
342 efi_char16_t *name;
342 unsigned long size; 343 unsigned long size;
343 u32 attributes; 344 u32 attributes;
344 u8 *data; 345 u8 *data;
@@ -351,11 +352,12 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
351 return -EINVAL; 352 return -EINVAL;
352 353
353 attributes = new_var->Attributes; 354 attributes = new_var->Attributes;
355 name = new_var->VariableName;
354 size = new_var->DataSize; 356 size = new_var->DataSize;
355 data = new_var->Data; 357 data = new_var->Data;
356 358
357 if ((attributes & ~EFI_VARIABLE_MASK) != 0 || 359 if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
358 efivar_validate(new_var, data, size) == false) { 360 efivar_validate(name, data, size) == false) {
359 printk(KERN_ERR "efivars: Malformed variable content\n"); 361 printk(KERN_ERR "efivars: Malformed variable content\n");
360 return -EINVAL; 362 return -EINVAL;
361 } 363 }
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index b22659cccca4..f0a43646a2f3 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -42,7 +42,7 @@ DECLARE_WORK(efivar_work, NULL);
42EXPORT_SYMBOL_GPL(efivar_work); 42EXPORT_SYMBOL_GPL(efivar_work);
43 43
44static bool 44static bool
45validate_device_path(struct efi_variable *var, int match, u8 *buffer, 45validate_device_path(efi_char16_t *var_name, int match, u8 *buffer,
46 unsigned long len) 46 unsigned long len)
47{ 47{
48 struct efi_generic_dev_path *node; 48 struct efi_generic_dev_path *node;
@@ -75,7 +75,7 @@ validate_device_path(struct efi_variable *var, int match, u8 *buffer,
75} 75}
76 76
77static bool 77static bool
78validate_boot_order(struct efi_variable *var, int match, u8 *buffer, 78validate_boot_order(efi_char16_t *var_name, int match, u8 *buffer,
79 unsigned long len) 79 unsigned long len)
80{ 80{
81 /* An array of 16-bit integers */ 81 /* An array of 16-bit integers */
@@ -86,18 +86,18 @@ validate_boot_order(struct efi_variable *var, int match, u8 *buffer,
86} 86}
87 87
88static bool 88static bool
89validate_load_option(struct efi_variable *var, int match, u8 *buffer, 89validate_load_option(efi_char16_t *var_name, int match, u8 *buffer,
90 unsigned long len) 90 unsigned long len)
91{ 91{
92 u16 filepathlength; 92 u16 filepathlength;
93 int i, desclength = 0, namelen; 93 int i, desclength = 0, namelen;
94 94
95 namelen = ucs2_strnlen(var->VariableName, sizeof(var->VariableName)); 95 namelen = ucs2_strnlen(var_name, EFI_VAR_NAME_LEN);
96 96
97 /* Either "Boot" or "Driver" followed by four digits of hex */ 97 /* Either "Boot" or "Driver" followed by four digits of hex */
98 for (i = match; i < match+4; i++) { 98 for (i = match; i < match+4; i++) {
99 if (var->VariableName[i] > 127 || 99 if (var_name[i] > 127 ||
100 hex_to_bin(var->VariableName[i] & 0xff) < 0) 100 hex_to_bin(var_name[i] & 0xff) < 0)
101 return true; 101 return true;
102 } 102 }
103 103
@@ -132,12 +132,12 @@ validate_load_option(struct efi_variable *var, int match, u8 *buffer,
132 /* 132 /*
133 * And, finally, check the filepath 133 * And, finally, check the filepath
134 */ 134 */
135 return validate_device_path(var, match, buffer + desclength + 6, 135 return validate_device_path(var_name, match, buffer + desclength + 6,
136 filepathlength); 136 filepathlength);
137} 137}
138 138
139static bool 139static bool
140validate_uint16(struct efi_variable *var, int match, u8 *buffer, 140validate_uint16(efi_char16_t *var_name, int match, u8 *buffer,
141 unsigned long len) 141 unsigned long len)
142{ 142{
143 /* A single 16-bit integer */ 143 /* A single 16-bit integer */
@@ -148,7 +148,7 @@ validate_uint16(struct efi_variable *var, int match, u8 *buffer,
148} 148}
149 149
150static bool 150static bool
151validate_ascii_string(struct efi_variable *var, int match, u8 *buffer, 151validate_ascii_string(efi_char16_t *var_name, int match, u8 *buffer,
152 unsigned long len) 152 unsigned long len)
153{ 153{
154 int i; 154 int i;
@@ -166,7 +166,7 @@ validate_ascii_string(struct efi_variable *var, int match, u8 *buffer,
166 166
167struct variable_validate { 167struct variable_validate {
168 char *name; 168 char *name;
169 bool (*validate)(struct efi_variable *var, int match, u8 *data, 169 bool (*validate)(efi_char16_t *var_name, int match, u8 *data,
170 unsigned long len); 170 unsigned long len);
171}; 171};
172 172
@@ -189,10 +189,10 @@ static const struct variable_validate variable_validate[] = {
189}; 189};
190 190
191bool 191bool
192efivar_validate(struct efi_variable *var, u8 *data, unsigned long len) 192efivar_validate(efi_char16_t *var_name, u8 *data, unsigned long len)
193{ 193{
194 int i; 194 int i;
195 u16 *unicode_name = var->VariableName; 195 u16 *unicode_name = var_name;
196 196
197 for (i = 0; variable_validate[i].validate != NULL; i++) { 197 for (i = 0; variable_validate[i].validate != NULL; i++) {
198 const char *name = variable_validate[i].name; 198 const char *name = variable_validate[i].name;
@@ -208,7 +208,7 @@ efivar_validate(struct efi_variable *var, u8 *data, unsigned long len)
208 208
209 /* Wildcard in the matching name means we've matched */ 209 /* Wildcard in the matching name means we've matched */
210 if (c == '*') 210 if (c == '*')
211 return variable_validate[i].validate(var, 211 return variable_validate[i].validate(var_name,
212 match, data, len); 212 match, data, len);
213 213
214 /* Case sensitive match */ 214 /* Case sensitive match */
@@ -217,7 +217,7 @@ efivar_validate(struct efi_variable *var, u8 *data, unsigned long len)
217 217
218 /* Reached the end of the string while matching */ 218 /* Reached the end of the string while matching */
219 if (!c) 219 if (!c)
220 return variable_validate[i].validate(var, 220 return variable_validate[i].validate(var_name,
221 match, data, len); 221 match, data, len);
222 } 222 }
223 } 223 }
@@ -805,7 +805,7 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
805 805
806 *set = false; 806 *set = false;
807 807
808 if (efivar_validate(&entry->var, data, *size) == false) 808 if (efivar_validate(name, data, *size) == false)
809 return -EINVAL; 809 return -EINVAL;
810 810
811 /* 811 /*
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 82d0abb2b19f..6a4d8e27d1d7 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1039,8 +1039,10 @@ struct efivars {
1039 * and we use a page for reading/writing. 1039 * and we use a page for reading/writing.
1040 */ 1040 */
1041 1041
1042#define EFI_VAR_NAME_LEN 1024
1043
1042struct efi_variable { 1044struct efi_variable {
1043 efi_char16_t VariableName[1024/sizeof(efi_char16_t)]; 1045 efi_char16_t VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1044 efi_guid_t VendorGuid; 1046 efi_guid_t VendorGuid;
1045 unsigned long DataSize; 1047 unsigned long DataSize;
1046 __u8 Data[1024]; 1048 __u8 Data[1024];
@@ -1122,7 +1124,7 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1122struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid, 1124struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1123 struct list_head *head, bool remove); 1125 struct list_head *head, bool remove);
1124 1126
1125bool efivar_validate(struct efi_variable *var, u8 *data, unsigned long len); 1127bool efivar_validate(efi_char16_t *var_name, u8 *data, unsigned long len);
1126 1128
1127extern struct work_struct efivar_work; 1129extern struct work_struct efivar_work;
1128void efivar_run_worker(void); 1130void efivar_run_worker(void);