vars.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Originally from efivars.c
  4. *
  5. * Copyright (C) 2001,2003,2004 Dell <Matt_Domsch@dell.com>
  6. * Copyright (C) 2004 Intel Corporation <matthew.e.tolentino@intel.com>
  7. */
  8. #include <linux/capability.h>
  9. #include <linux/types.h>
  10. #include <linux/errno.h>
  11. #include <linux/init.h>
  12. #include <linux/mm.h>
  13. #include <linux/module.h>
  14. #include <linux/string.h>
  15. #include <linux/smp.h>
  16. #include <linux/efi.h>
  17. #include <linux/device.h>
  18. #include <linux/slab.h>
  19. #include <linux/ctype.h>
  20. #include <linux/ucs2_string.h>
  21. #include "internal.h"
  22. MODULE_IMPORT_NS(EFIVAR);
  23. static bool
  24. validate_device_path(efi_char16_t *var_name, int match, u8 *buffer,
  25. unsigned long len)
  26. {
  27. struct efi_generic_dev_path *node;
  28. int offset = 0;
  29. node = (struct efi_generic_dev_path *)buffer;
  30. if (len < sizeof(*node))
  31. return false;
  32. while (offset <= len - sizeof(*node) &&
  33. node->length >= sizeof(*node) &&
  34. node->length <= len - offset) {
  35. offset += node->length;
  36. if ((node->type == EFI_DEV_END_PATH ||
  37. node->type == EFI_DEV_END_PATH2) &&
  38. node->sub_type == EFI_DEV_END_ENTIRE)
  39. return true;
  40. node = (struct efi_generic_dev_path *)(buffer + offset);
  41. }
  42. /*
  43. * If we're here then either node->length pointed past the end
  44. * of the buffer or we reached the end of the buffer without
  45. * finding a device path end node.
  46. */
  47. return false;
  48. }
  49. static bool
  50. validate_boot_order(efi_char16_t *var_name, int match, u8 *buffer,
  51. unsigned long len)
  52. {
  53. /* An array of 16-bit integers */
  54. if ((len % 2) != 0)
  55. return false;
  56. return true;
  57. }
  58. static bool
  59. validate_load_option(efi_char16_t *var_name, int match, u8 *buffer,
  60. unsigned long len)
  61. {
  62. u16 filepathlength;
  63. int i, desclength = 0, namelen;
  64. namelen = ucs2_strnlen(var_name, EFI_VAR_NAME_LEN);
  65. /* Either "Boot" or "Driver" followed by four digits of hex */
  66. for (i = match; i < match+4; i++) {
  67. if (var_name[i] > 127 ||
  68. hex_to_bin(var_name[i] & 0xff) < 0)
  69. return true;
  70. }
  71. /* Reject it if there's 4 digits of hex and then further content */
  72. if (namelen > match + 4)
  73. return false;
  74. /* A valid entry must be at least 8 bytes */
  75. if (len < 8)
  76. return false;
  77. filepathlength = buffer[4] | buffer[5] << 8;
  78. /*
  79. * There's no stored length for the description, so it has to be
  80. * found by hand
  81. */
  82. desclength = ucs2_strsize((efi_char16_t *)(buffer + 6), len - 6) + 2;
  83. /* Each boot entry must have a descriptor */
  84. if (!desclength)
  85. return false;
  86. /*
  87. * If the sum of the length of the description, the claimed filepath
  88. * length and the original header are greater than the length of the
  89. * variable, it's malformed
  90. */
  91. if ((desclength + filepathlength + 6) > len)
  92. return false;
  93. /*
  94. * And, finally, check the filepath
  95. */
  96. return validate_device_path(var_name, match, buffer + desclength + 6,
  97. filepathlength);
  98. }
  99. static bool
  100. validate_uint16(efi_char16_t *var_name, int match, u8 *buffer,
  101. unsigned long len)
  102. {
  103. /* A single 16-bit integer */
  104. if (len != 2)
  105. return false;
  106. return true;
  107. }
  108. static bool
  109. validate_ascii_string(efi_char16_t *var_name, int match, u8 *buffer,
  110. unsigned long len)
  111. {
  112. int i;
  113. for (i = 0; i < len; i++) {
  114. if (buffer[i] > 127)
  115. return false;
  116. if (buffer[i] == 0)
  117. return true;
  118. }
  119. return false;
  120. }
  121. struct variable_validate {
  122. efi_guid_t vendor;
  123. char *name;
  124. bool (*validate)(efi_char16_t *var_name, int match, u8 *data,
  125. unsigned long len);
  126. };
  127. /*
  128. * This is the list of variables we need to validate, as well as the
  129. * whitelist for what we think is safe not to default to immutable.
  130. *
  131. * If it has a validate() method that's not NULL, it'll go into the
  132. * validation routine. If not, it is assumed valid, but still used for
  133. * whitelisting.
  134. *
  135. * Note that it's sorted by {vendor,name}, but globbed names must come after
  136. * any other name with the same prefix.
  137. */
  138. static const struct variable_validate variable_validate[] = {
  139. { EFI_GLOBAL_VARIABLE_GUID, "BootNext", validate_uint16 },
  140. { EFI_GLOBAL_VARIABLE_GUID, "BootOrder", validate_boot_order },
  141. { EFI_GLOBAL_VARIABLE_GUID, "Boot*", validate_load_option },
  142. { EFI_GLOBAL_VARIABLE_GUID, "DriverOrder", validate_boot_order },
  143. { EFI_GLOBAL_VARIABLE_GUID, "Driver*", validate_load_option },
  144. { EFI_GLOBAL_VARIABLE_GUID, "ConIn", validate_device_path },
  145. { EFI_GLOBAL_VARIABLE_GUID, "ConInDev", validate_device_path },
  146. { EFI_GLOBAL_VARIABLE_GUID, "ConOut", validate_device_path },
  147. { EFI_GLOBAL_VARIABLE_GUID, "ConOutDev", validate_device_path },
  148. { EFI_GLOBAL_VARIABLE_GUID, "ErrOut", validate_device_path },
  149. { EFI_GLOBAL_VARIABLE_GUID, "ErrOutDev", validate_device_path },
  150. { EFI_GLOBAL_VARIABLE_GUID, "Lang", validate_ascii_string },
  151. { EFI_GLOBAL_VARIABLE_GUID, "OsIndications", NULL },
  152. { EFI_GLOBAL_VARIABLE_GUID, "PlatformLang", validate_ascii_string },
  153. { EFI_GLOBAL_VARIABLE_GUID, "Timeout", validate_uint16 },
  154. { LINUX_EFI_CRASH_GUID, "*", NULL },
  155. { NULL_GUID, "", NULL },
  156. };
  157. /*
  158. * Check if @var_name matches the pattern given in @match_name.
  159. *
  160. * @var_name: an array of @len non-NUL characters.
  161. * @match_name: a NUL-terminated pattern string, optionally ending in "*". A
  162. * final "*" character matches any trailing characters @var_name,
  163. * including the case when there are none left in @var_name.
  164. * @match: on output, the number of non-wildcard characters in @match_name
  165. * that @var_name matches, regardless of the return value.
  166. * @return: whether @var_name fully matches @match_name.
  167. */
  168. static bool
  169. variable_matches(const char *var_name, size_t len, const char *match_name,
  170. int *match)
  171. {
  172. for (*match = 0; ; (*match)++) {
  173. char c = match_name[*match];
  174. switch (c) {
  175. case '*':
  176. /* Wildcard in @match_name means we've matched. */
  177. return true;
  178. case '\0':
  179. /* @match_name has ended. Has @var_name too? */
  180. return (*match == len);
  181. default:
  182. /*
  183. * We've reached a non-wildcard char in @match_name.
  184. * Continue only if there's an identical character in
  185. * @var_name.
  186. */
  187. if (*match < len && c == var_name[*match])
  188. continue;
  189. return false;
  190. }
  191. }
  192. }
  193. bool
  194. efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
  195. unsigned long data_size)
  196. {
  197. int i;
  198. unsigned long utf8_size;
  199. u8 *utf8_name;
  200. utf8_size = ucs2_utf8size(var_name);
  201. utf8_name = kmalloc(utf8_size + 1, GFP_KERNEL);
  202. if (!utf8_name)
  203. return false;
  204. ucs2_as_utf8(utf8_name, var_name, utf8_size);
  205. utf8_name[utf8_size] = '\0';
  206. for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
  207. const char *name = variable_validate[i].name;
  208. int match = 0;
  209. if (efi_guidcmp(vendor, variable_validate[i].vendor))
  210. continue;
  211. if (variable_matches(utf8_name, utf8_size+1, name, &match)) {
  212. if (variable_validate[i].validate == NULL)
  213. break;
  214. kfree(utf8_name);
  215. return variable_validate[i].validate(var_name, match,
  216. data, data_size);
  217. }
  218. }
  219. kfree(utf8_name);
  220. return true;
  221. }
  222. bool
  223. efivar_variable_is_removable(efi_guid_t vendor, const char *var_name,
  224. size_t len)
  225. {
  226. int i;
  227. bool found = false;
  228. int match = 0;
  229. /*
  230. * Check if our variable is in the validated variables list
  231. */
  232. for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
  233. if (efi_guidcmp(variable_validate[i].vendor, vendor))
  234. continue;
  235. if (variable_matches(var_name, len,
  236. variable_validate[i].name, &match)) {
  237. found = true;
  238. break;
  239. }
  240. }
  241. /*
  242. * If it's in our list, it is removable.
  243. */
  244. return found;
  245. }
  246. static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor,
  247. struct list_head *head)
  248. {
  249. struct efivar_entry *entry, *n;
  250. unsigned long strsize1, strsize2;
  251. bool found = false;
  252. strsize1 = ucs2_strsize(variable_name, EFI_VAR_NAME_LEN);
  253. list_for_each_entry_safe(entry, n, head, list) {
  254. strsize2 = ucs2_strsize(entry->var.VariableName, EFI_VAR_NAME_LEN);
  255. if (strsize1 == strsize2 &&
  256. !memcmp(variable_name, &(entry->var.VariableName),
  257. strsize2) &&
  258. !efi_guidcmp(entry->var.VendorGuid,
  259. *vendor)) {
  260. found = true;
  261. break;
  262. }
  263. }
  264. return found;
  265. }
  266. /*
  267. * Returns the size of variable_name, in bytes, including the
  268. * terminating NULL character, or variable_name_size if no NULL
  269. * character is found among the first variable_name_size bytes.
  270. */
  271. static unsigned long var_name_strnsize(efi_char16_t *variable_name,
  272. unsigned long variable_name_size)
  273. {
  274. unsigned long len;
  275. efi_char16_t c;
  276. /*
  277. * The variable name is, by definition, a NULL-terminated
  278. * string, so make absolutely sure that variable_name_size is
  279. * the value we expect it to be. If not, return the real size.
  280. */
  281. for (len = 2; len <= variable_name_size; len += sizeof(c)) {
  282. c = variable_name[(len / sizeof(c)) - 1];
  283. if (!c)
  284. break;
  285. }
  286. return min(len, variable_name_size);
  287. }
  288. /*
  289. * Print a warning when duplicate EFI variables are encountered and
  290. * disable the sysfs workqueue since the firmware is buggy.
  291. */
  292. static void dup_variable_bug(efi_char16_t *str16, efi_guid_t *vendor_guid,
  293. unsigned long len16)
  294. {
  295. size_t i, len8 = len16 / sizeof(efi_char16_t);
  296. char *str8;
  297. str8 = kzalloc(len8, GFP_KERNEL);
  298. if (!str8)
  299. return;
  300. for (i = 0; i < len8; i++)
  301. str8[i] = str16[i];
  302. printk(KERN_WARNING "efivars: duplicate variable: %s-%pUl\n",
  303. str8, vendor_guid);
  304. kfree(str8);
  305. }
  306. /**
  307. * efivar_init - build the initial list of EFI variables
  308. * @func: callback function to invoke for every variable
  309. * @data: function-specific data to pass to @func
  310. * @head: initialised head of variable list
  311. *
  312. * Get every EFI variable from the firmware and invoke @func. @func
  313. * should call efivar_entry_add() to build the list of variables.
  314. *
  315. * Returns 0 on success, or a kernel error code on failure.
  316. */
  317. int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
  318. struct list_head *),
  319. void *data, struct list_head *head)
  320. {
  321. unsigned long variable_name_size = 512;
  322. efi_char16_t *variable_name;
  323. efi_status_t status;
  324. efi_guid_t vendor_guid;
  325. int err = 0;
  326. variable_name = kzalloc(variable_name_size, GFP_KERNEL);
  327. if (!variable_name) {
  328. printk(KERN_ERR "efivars: Memory allocation failed.\n");
  329. return -ENOMEM;
  330. }
  331. err = efivar_lock();
  332. if (err)
  333. goto free;
  334. /*
  335. * A small set of old UEFI implementations reject sizes
  336. * above a certain threshold, the lowest seen in the wild
  337. * is 512.
  338. */
  339. do {
  340. variable_name_size = 512;
  341. BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
  342. status = efivar_get_next_variable(&variable_name_size,
  343. variable_name,
  344. &vendor_guid);
  345. switch (status) {
  346. case EFI_SUCCESS:
  347. variable_name_size = var_name_strnsize(variable_name,
  348. variable_name_size);
  349. /*
  350. * Some firmware implementations return the
  351. * same variable name on multiple calls to
  352. * get_next_variable(). Terminate the loop
  353. * immediately as there is no guarantee that
  354. * we'll ever see a different variable name,
  355. * and may end up looping here forever.
  356. */
  357. if (variable_is_present(variable_name, &vendor_guid,
  358. head)) {
  359. dup_variable_bug(variable_name, &vendor_guid,
  360. variable_name_size);
  361. status = EFI_NOT_FOUND;
  362. } else {
  363. err = func(variable_name, vendor_guid,
  364. variable_name_size, data, head);
  365. if (err)
  366. status = EFI_NOT_FOUND;
  367. }
  368. break;
  369. case EFI_UNSUPPORTED:
  370. err = -EOPNOTSUPP;
  371. status = EFI_NOT_FOUND;
  372. break;
  373. case EFI_NOT_FOUND:
  374. break;
  375. case EFI_BUFFER_TOO_SMALL:
  376. pr_warn("efivars: Variable name size exceeds maximum (%lu > 512)\n",
  377. variable_name_size);
  378. status = EFI_NOT_FOUND;
  379. break;
  380. default:
  381. pr_warn("efivars: get_next_variable: status=%lx\n", status);
  382. status = EFI_NOT_FOUND;
  383. break;
  384. }
  385. } while (status != EFI_NOT_FOUND);
  386. efivar_unlock();
  387. free:
  388. kfree(variable_name);
  389. return err;
  390. }
  391. /**
  392. * efivar_entry_add - add entry to variable list
  393. * @entry: entry to add to list
  394. * @head: list head
  395. *
  396. * Returns 0 on success, or a kernel error code on failure.
  397. */
  398. int efivar_entry_add(struct efivar_entry *entry, struct list_head *head)
  399. {
  400. int err;
  401. err = efivar_lock();
  402. if (err)
  403. return err;
  404. list_add(&entry->list, head);
  405. efivar_unlock();
  406. return 0;
  407. }
  408. /**
  409. * __efivar_entry_add - add entry to variable list
  410. * @entry: entry to add to list
  411. * @head: list head
  412. */
  413. void __efivar_entry_add(struct efivar_entry *entry, struct list_head *head)
  414. {
  415. list_add(&entry->list, head);
  416. }
  417. /**
  418. * efivar_entry_remove - remove entry from variable list
  419. * @entry: entry to remove from list
  420. *
  421. * Returns 0 on success, or a kernel error code on failure.
  422. */
  423. void efivar_entry_remove(struct efivar_entry *entry)
  424. {
  425. list_del(&entry->list);
  426. }
  427. /*
  428. * efivar_entry_list_del_unlock - remove entry from variable list
  429. * @entry: entry to remove
  430. *
  431. * Remove @entry from the variable list and release the list lock.
  432. *
  433. * NOTE: slightly weird locking semantics here - we expect to be
  434. * called with the efivars lock already held, and we release it before
  435. * returning. This is because this function is usually called after
  436. * set_variable() while the lock is still held.
  437. */
  438. static void efivar_entry_list_del_unlock(struct efivar_entry *entry)
  439. {
  440. list_del(&entry->list);
  441. efivar_unlock();
  442. }
  443. /**
  444. * efivar_entry_delete - delete variable and remove entry from list
  445. * @entry: entry containing variable to delete
  446. *
  447. * Delete the variable from the firmware and remove @entry from the
  448. * variable list. It is the caller's responsibility to free @entry
  449. * once we return.
  450. *
  451. * Returns 0 on success, -EINTR if we can't grab the semaphore,
  452. * converted EFI status code if set_variable() fails.
  453. */
  454. int efivar_entry_delete(struct efivar_entry *entry)
  455. {
  456. efi_status_t status;
  457. int err;
  458. err = efivar_lock();
  459. if (err)
  460. return err;
  461. status = efivar_set_variable_locked(entry->var.VariableName,
  462. &entry->var.VendorGuid,
  463. 0, 0, NULL, false);
  464. if (!(status == EFI_SUCCESS || status == EFI_NOT_FOUND)) {
  465. efivar_unlock();
  466. return efi_status_to_err(status);
  467. }
  468. efivar_entry_list_del_unlock(entry);
  469. return 0;
  470. }
  471. /**
  472. * efivar_entry_size - obtain the size of a variable
  473. * @entry: entry for this variable
  474. * @size: location to store the variable's size
  475. */
  476. int efivar_entry_size(struct efivar_entry *entry, unsigned long *size)
  477. {
  478. efi_status_t status;
  479. int err;
  480. *size = 0;
  481. err = efivar_lock();
  482. if (err)
  483. return err;
  484. status = efivar_get_variable(entry->var.VariableName,
  485. &entry->var.VendorGuid, NULL, size, NULL);
  486. efivar_unlock();
  487. if (status != EFI_BUFFER_TOO_SMALL)
  488. return efi_status_to_err(status);
  489. return 0;
  490. }
  491. /**
  492. * __efivar_entry_get - call get_variable()
  493. * @entry: read data for this variable
  494. * @attributes: variable attributes
  495. * @size: size of @data buffer
  496. * @data: buffer to store variable data
  497. *
  498. * The caller MUST call efivar_entry_iter_begin() and
  499. * efivar_entry_iter_end() before and after the invocation of this
  500. * function, respectively.
  501. */
  502. int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
  503. unsigned long *size, void *data)
  504. {
  505. efi_status_t status;
  506. status = efivar_get_variable(entry->var.VariableName,
  507. &entry->var.VendorGuid,
  508. attributes, size, data);
  509. return efi_status_to_err(status);
  510. }
  511. /**
  512. * efivar_entry_get - call get_variable()
  513. * @entry: read data for this variable
  514. * @attributes: variable attributes
  515. * @size: size of @data buffer
  516. * @data: buffer to store variable data
  517. */
  518. int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
  519. unsigned long *size, void *data)
  520. {
  521. int err;
  522. err = efivar_lock();
  523. if (err)
  524. return err;
  525. err = __efivar_entry_get(entry, attributes, size, data);
  526. efivar_unlock();
  527. return 0;
  528. }
  529. /**
  530. * efivar_entry_set_get_size - call set_variable() and get new size (atomic)
  531. * @entry: entry containing variable to set and get
  532. * @attributes: attributes of variable to be written
  533. * @size: size of data buffer
  534. * @data: buffer containing data to write
  535. * @set: did the set_variable() call succeed?
  536. *
  537. * This is a pretty special (complex) function. See efivarfs_file_write().
  538. *
  539. * Atomically call set_variable() for @entry and if the call is
  540. * successful, return the new size of the variable from get_variable()
  541. * in @size. The success of set_variable() is indicated by @set.
  542. *
  543. * Returns 0 on success, -EINVAL if the variable data is invalid,
  544. * -ENOSPC if the firmware does not have enough available space, or a
  545. * converted EFI status code if either of set_variable() or
  546. * get_variable() fail.
  547. *
  548. * If the EFI variable does not exist when calling set_variable()
  549. * (EFI_NOT_FOUND), @entry is removed from the variable list.
  550. */
  551. int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
  552. unsigned long *size, void *data, bool *set)
  553. {
  554. efi_char16_t *name = entry->var.VariableName;
  555. efi_guid_t *vendor = &entry->var.VendorGuid;
  556. efi_status_t status;
  557. int err;
  558. *set = false;
  559. if (efivar_validate(*vendor, name, data, *size) == false)
  560. return -EINVAL;
  561. /*
  562. * The lock here protects the get_variable call, the conditional
  563. * set_variable call, and removal of the variable from the efivars
  564. * list (in the case of an authenticated delete).
  565. */
  566. err = efivar_lock();
  567. if (err)
  568. return err;
  569. status = efivar_set_variable_locked(name, vendor, attributes, *size,
  570. data, false);
  571. if (status != EFI_SUCCESS) {
  572. err = efi_status_to_err(status);
  573. goto out;
  574. }
  575. *set = true;
  576. /*
  577. * Writing to the variable may have caused a change in size (which
  578. * could either be an append or an overwrite), or the variable to be
  579. * deleted. Perform a GetVariable() so we can tell what actually
  580. * happened.
  581. */
  582. *size = 0;
  583. status = efivar_get_variable(entry->var.VariableName,
  584. &entry->var.VendorGuid,
  585. NULL, size, NULL);
  586. if (status == EFI_NOT_FOUND)
  587. efivar_entry_list_del_unlock(entry);
  588. else
  589. efivar_unlock();
  590. if (status && status != EFI_BUFFER_TOO_SMALL)
  591. return efi_status_to_err(status);
  592. return 0;
  593. out:
  594. efivar_unlock();
  595. return err;
  596. }
  597. /**
  598. * efivar_entry_iter - iterate over variable list
  599. * @func: callback function
  600. * @head: head of variable list
  601. * @data: function-specific data to pass to callback
  602. *
  603. * Iterate over the list of EFI variables and call @func with every
  604. * entry on the list. It is safe for @func to remove entries in the
  605. * list via efivar_entry_delete() while iterating.
  606. *
  607. * Some notes for the callback function:
  608. * - a non-zero return value indicates an error and terminates the loop
  609. * - @func is called from atomic context
  610. */
  611. int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
  612. struct list_head *head, void *data)
  613. {
  614. struct efivar_entry *entry, *n;
  615. int err = 0;
  616. err = efivar_lock();
  617. if (err)
  618. return err;
  619. list_for_each_entry_safe(entry, n, head, list) {
  620. err = func(entry, data);
  621. if (err)
  622. break;
  623. }
  624. efivar_unlock();
  625. return err;
  626. }