aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efivars.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firmware/efivars.c')
-rw-r--r--drivers/firmware/efivars.c150
1 files changed, 104 insertions, 46 deletions
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index fe62aa392239..7acafb80fd4c 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -103,6 +103,11 @@ MODULE_VERSION(EFIVARS_VERSION);
103 */ 103 */
104#define GUID_LEN 36 104#define GUID_LEN 36
105 105
106static bool efivars_pstore_disable =
107 IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
108
109module_param_named(pstore_disable, efivars_pstore_disable, bool, 0644);
110
106/* 111/*
107 * The maximum size of VariableName + Data = 1024 112 * The maximum size of VariableName + Data = 1024
108 * Therefore, it's reasonable to save that much 113 * Therefore, it's reasonable to save that much
@@ -165,6 +170,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
165 170
166static void efivar_update_sysfs_entries(struct work_struct *); 171static void efivar_update_sysfs_entries(struct work_struct *);
167static DECLARE_WORK(efivar_work, efivar_update_sysfs_entries); 172static DECLARE_WORK(efivar_work, efivar_update_sysfs_entries);
173static bool efivar_wq_enabled = true;
168 174
169/* Return the number of unicode characters in data */ 175/* Return the number of unicode characters in data */
170static unsigned long 176static unsigned long
@@ -1309,9 +1315,7 @@ static const struct inode_operations efivarfs_dir_inode_operations = {
1309 .create = efivarfs_create, 1315 .create = efivarfs_create,
1310}; 1316};
1311 1317
1312static struct pstore_info efi_pstore_info; 1318#ifdef CONFIG_EFI_VARS_PSTORE
1313
1314#ifdef CONFIG_PSTORE
1315 1319
1316static int efi_pstore_open(struct pstore_info *psi) 1320static int efi_pstore_open(struct pstore_info *psi)
1317{ 1321{
@@ -1441,7 +1445,7 @@ static int efi_pstore_write(enum pstore_type_id type,
1441 1445
1442 spin_unlock_irqrestore(&efivars->lock, flags); 1446 spin_unlock_irqrestore(&efivars->lock, flags);
1443 1447
1444 if (reason == KMSG_DUMP_OOPS) 1448 if (reason == KMSG_DUMP_OOPS && efivar_wq_enabled)
1445 schedule_work(&efivar_work); 1449 schedule_work(&efivar_work);
1446 1450
1447 *id = part; 1451 *id = part;
@@ -1514,38 +1518,6 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
1514 1518
1515 return 0; 1519 return 0;
1516} 1520}
1517#else
1518static int efi_pstore_open(struct pstore_info *psi)
1519{
1520 return 0;
1521}
1522
1523static int efi_pstore_close(struct pstore_info *psi)
1524{
1525 return 0;
1526}
1527
1528static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, int *count,
1529 struct timespec *timespec,
1530 char **buf, struct pstore_info *psi)
1531{
1532 return -1;
1533}
1534
1535static int efi_pstore_write(enum pstore_type_id type,
1536 enum kmsg_dump_reason reason, u64 *id,
1537 unsigned int part, int count, size_t size,
1538 struct pstore_info *psi)
1539{
1540 return 0;
1541}
1542
1543static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
1544 struct timespec time, struct pstore_info *psi)
1545{
1546 return 0;
1547}
1548#endif
1549 1521
1550static struct pstore_info efi_pstore_info = { 1522static struct pstore_info efi_pstore_info = {
1551 .owner = THIS_MODULE, 1523 .owner = THIS_MODULE,
@@ -1557,6 +1529,24 @@ static struct pstore_info efi_pstore_info = {
1557 .erase = efi_pstore_erase, 1529 .erase = efi_pstore_erase,
1558}; 1530};
1559 1531
1532static void efivar_pstore_register(struct efivars *efivars)
1533{
1534 efivars->efi_pstore_info = efi_pstore_info;
1535 efivars->efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL);
1536 if (efivars->efi_pstore_info.buf) {
1537 efivars->efi_pstore_info.bufsize = 1024;
1538 efivars->efi_pstore_info.data = efivars;
1539 spin_lock_init(&efivars->efi_pstore_info.buf_lock);
1540 pstore_register(&efivars->efi_pstore_info);
1541 }
1542}
1543#else
1544static void efivar_pstore_register(struct efivars *efivars)
1545{
1546 return;
1547}
1548#endif
1549
1560static ssize_t efivar_create(struct file *filp, struct kobject *kobj, 1550static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
1561 struct bin_attribute *bin_attr, 1551 struct bin_attribute *bin_attr,
1562 char *buf, loff_t pos, size_t count) 1552 char *buf, loff_t pos, size_t count)
@@ -1716,6 +1706,31 @@ static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor)
1716 return found; 1706 return found;
1717} 1707}
1718 1708
1709/*
1710 * Returns the size of variable_name, in bytes, including the
1711 * terminating NULL character, or variable_name_size if no NULL
1712 * character is found among the first variable_name_size bytes.
1713 */
1714static unsigned long var_name_strnsize(efi_char16_t *variable_name,
1715 unsigned long variable_name_size)
1716{
1717 unsigned long len;
1718 efi_char16_t c;
1719
1720 /*
1721 * The variable name is, by definition, a NULL-terminated
1722 * string, so make absolutely sure that variable_name_size is
1723 * the value we expect it to be. If not, return the real size.
1724 */
1725 for (len = 2; len <= variable_name_size; len += sizeof(c)) {
1726 c = variable_name[(len / sizeof(c)) - 1];
1727 if (!c)
1728 break;
1729 }
1730
1731 return min(len, variable_name_size);
1732}
1733
1719static void efivar_update_sysfs_entries(struct work_struct *work) 1734static void efivar_update_sysfs_entries(struct work_struct *work)
1720{ 1735{
1721 struct efivars *efivars = &__efivars; 1736 struct efivars *efivars = &__efivars;
@@ -1756,10 +1771,13 @@ static void efivar_update_sysfs_entries(struct work_struct *work)
1756 if (!found) { 1771 if (!found) {
1757 kfree(variable_name); 1772 kfree(variable_name);
1758 break; 1773 break;
1759 } else 1774 } else {
1775 variable_name_size = var_name_strnsize(variable_name,
1776 variable_name_size);
1760 efivar_create_sysfs_entry(efivars, 1777 efivar_create_sysfs_entry(efivars,
1761 variable_name_size, 1778 variable_name_size,
1762 variable_name, &vendor); 1779 variable_name, &vendor);
1780 }
1763 } 1781 }
1764} 1782}
1765 1783
@@ -1958,6 +1976,35 @@ void unregister_efivars(struct efivars *efivars)
1958} 1976}
1959EXPORT_SYMBOL_GPL(unregister_efivars); 1977EXPORT_SYMBOL_GPL(unregister_efivars);
1960 1978
1979/*
1980 * Print a warning when duplicate EFI variables are encountered and
1981 * disable the sysfs workqueue since the firmware is buggy.
1982 */
1983static void dup_variable_bug(efi_char16_t *s16, efi_guid_t *vendor_guid,
1984 unsigned long len16)
1985{
1986 size_t i, len8 = len16 / sizeof(efi_char16_t);
1987 char *s8;
1988
1989 /*
1990 * Disable the workqueue since the algorithm it uses for
1991 * detecting new variables won't work with this buggy
1992 * implementation of GetNextVariableName().
1993 */
1994 efivar_wq_enabled = false;
1995
1996 s8 = kzalloc(len8, GFP_KERNEL);
1997 if (!s8)
1998 return;
1999
2000 for (i = 0; i < len8; i++)
2001 s8[i] = s16[i];
2002
2003 printk(KERN_WARNING "efivars: duplicate variable: %s-%pUl\n",
2004 s8, vendor_guid);
2005 kfree(s8);
2006}
2007
1961int register_efivars(struct efivars *efivars, 2008int register_efivars(struct efivars *efivars,
1962 const struct efivar_operations *ops, 2009 const struct efivar_operations *ops,
1963 struct kobject *parent_kobj) 2010 struct kobject *parent_kobj)
@@ -2006,6 +2053,24 @@ int register_efivars(struct efivars *efivars,
2006 &vendor_guid); 2053 &vendor_guid);
2007 switch (status) { 2054 switch (status) {
2008 case EFI_SUCCESS: 2055 case EFI_SUCCESS:
2056 variable_name_size = var_name_strnsize(variable_name,
2057 variable_name_size);
2058
2059 /*
2060 * Some firmware implementations return the
2061 * same variable name on multiple calls to
2062 * get_next_variable(). Terminate the loop
2063 * immediately as there is no guarantee that
2064 * we'll ever see a different variable name,
2065 * and may end up looping here forever.
2066 */
2067 if (variable_is_present(variable_name, &vendor_guid)) {
2068 dup_variable_bug(variable_name, &vendor_guid,
2069 variable_name_size);
2070 status = EFI_NOT_FOUND;
2071 break;
2072 }
2073
2009 efivar_create_sysfs_entry(efivars, 2074 efivar_create_sysfs_entry(efivars,
2010 variable_name_size, 2075 variable_name_size,
2011 variable_name, 2076 variable_name,
@@ -2025,15 +2090,8 @@ int register_efivars(struct efivars *efivars,
2025 if (error) 2090 if (error)
2026 unregister_efivars(efivars); 2091 unregister_efivars(efivars);
2027 2092
2028 efivars->efi_pstore_info = efi_pstore_info; 2093 if (!efivars_pstore_disable)
2029 2094 efivar_pstore_register(efivars);
2030 efivars->efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL);
2031 if (efivars->efi_pstore_info.buf) {
2032 efivars->efi_pstore_info.bufsize = 1024;
2033 efivars->efi_pstore_info.data = efivars;
2034 spin_lock_init(&efivars->efi_pstore_info.buf_lock);
2035 pstore_register(&efivars->efi_pstore_info);
2036 }
2037 2095
2038 register_filesystem(&efivarfs_type); 2096 register_filesystem(&efivarfs_type);
2039 2097