| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Originally from efivars.c, |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * This code takes all variables accessible from EFI runtime and |
|---|
| 8 | 9 | * exports them via sysfs |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 12 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | | - * (at your option) any later version. |
|---|
| 14 | | - * |
|---|
| 15 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | | - * GNU General Public License for more details. |
|---|
| 19 | | - * |
|---|
| 20 | | - * You should have received a copy of the GNU General Public License |
|---|
| 21 | | - * along with this program; if not, write to the Free Software |
|---|
| 22 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | | - * |
|---|
| 24 | | - * Changelog: |
|---|
| 25 | | - * |
|---|
| 26 | | - * 17 May 2004 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 27 | | - * remove check for efi_enabled in exit |
|---|
| 28 | | - * add MODULE_VERSION |
|---|
| 29 | | - * |
|---|
| 30 | | - * 26 Apr 2004 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 31 | | - * minor bug fixes |
|---|
| 32 | | - * |
|---|
| 33 | | - * 21 Apr 2004 - Matt Tolentino <matthew.e.tolentino@intel.com) |
|---|
| 34 | | - * converted driver to export variable information via sysfs |
|---|
| 35 | | - * and moved to drivers/firmware directory |
|---|
| 36 | | - * bumped revision number to v0.07 to reflect conversion & move |
|---|
| 37 | | - * |
|---|
| 38 | | - * 10 Dec 2002 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 39 | | - * fix locking per Peter Chubb's findings |
|---|
| 40 | | - * |
|---|
| 41 | | - * 25 Mar 2002 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 42 | | - * move uuid_unparse() to include/asm-ia64/efi.h:efi_guid_to_str() |
|---|
| 43 | | - * |
|---|
| 44 | | - * 12 Feb 2002 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 45 | | - * use list_for_each_safe when deleting vars. |
|---|
| 46 | | - * remove ifdef CONFIG_SMP around include <linux/smp.h> |
|---|
| 47 | | - * v0.04 release to linux-ia64@linuxia64.org |
|---|
| 48 | | - * |
|---|
| 49 | | - * 20 April 2001 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 50 | | - * Moved vars from /proc/efi to /proc/efi/vars, and made |
|---|
| 51 | | - * efi.c own the /proc/efi directory. |
|---|
| 52 | | - * v0.03 release to linux-ia64@linuxia64.org |
|---|
| 53 | | - * |
|---|
| 54 | | - * 26 March 2001 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 55 | | - * At the request of Stephane, moved ownership of /proc/efi |
|---|
| 56 | | - * to efi.c, and now efivars lives under /proc/efi/vars. |
|---|
| 57 | | - * |
|---|
| 58 | | - * 12 March 2001 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 59 | | - * Feedback received from Stephane Eranian incorporated. |
|---|
| 60 | | - * efivar_write() checks copy_from_user() return value. |
|---|
| 61 | | - * efivar_read/write() returns proper errno. |
|---|
| 62 | | - * v0.02 release to linux-ia64@linuxia64.org |
|---|
| 63 | | - * |
|---|
| 64 | | - * 26 February 2001 - Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 65 | | - * v0.01 release to linux-ia64@linuxia64.org |
|---|
| 66 | 10 | */ |
|---|
| 67 | 11 | |
|---|
| 68 | 12 | #include <linux/efi.h> |
|---|
| .. | .. |
|---|
| 78 | 22 | MODULE_DESCRIPTION("sysfs interface to EFI Variables"); |
|---|
| 79 | 23 | MODULE_LICENSE("GPL"); |
|---|
| 80 | 24 | MODULE_VERSION(EFIVARS_VERSION); |
|---|
| 81 | | -MODULE_ALIAS("platform:efivars"); |
|---|
| 82 | 25 | |
|---|
| 83 | | -LIST_HEAD(efivar_sysfs_list); |
|---|
| 84 | | -EXPORT_SYMBOL_GPL(efivar_sysfs_list); |
|---|
| 26 | +static LIST_HEAD(efivar_sysfs_list); |
|---|
| 85 | 27 | |
|---|
| 86 | 28 | static struct kset *efivars_kset; |
|---|
| 87 | 29 | |
|---|
| .. | .. |
|---|
| 238 | 180 | return 0; |
|---|
| 239 | 181 | } |
|---|
| 240 | 182 | |
|---|
| 241 | | -static inline bool is_compat(void) |
|---|
| 242 | | -{ |
|---|
| 243 | | - if (IS_ENABLED(CONFIG_COMPAT) && in_compat_syscall()) |
|---|
| 244 | | - return true; |
|---|
| 245 | | - |
|---|
| 246 | | - return false; |
|---|
| 247 | | -} |
|---|
| 248 | | - |
|---|
| 249 | 183 | static void |
|---|
| 250 | 184 | copy_out_compat(struct efi_variable *dst, struct compat_efi_variable *src) |
|---|
| 251 | 185 | { |
|---|
| .. | .. |
|---|
| 275 | 209 | if (!entry || !buf) |
|---|
| 276 | 210 | return -EINVAL; |
|---|
| 277 | 211 | |
|---|
| 278 | | - if (is_compat()) { |
|---|
| 212 | + if (in_compat_syscall()) { |
|---|
| 279 | 213 | struct compat_efi_variable *compat; |
|---|
| 280 | 214 | |
|---|
| 281 | 215 | if (count != sizeof(*compat)) |
|---|
| .. | .. |
|---|
| 338 | 272 | if (ret) |
|---|
| 339 | 273 | return -EIO; |
|---|
| 340 | 274 | |
|---|
| 341 | | - if (is_compat()) { |
|---|
| 275 | + if (in_compat_syscall()) { |
|---|
| 342 | 276 | compat = (struct compat_efi_variable *)buf; |
|---|
| 343 | 277 | |
|---|
| 344 | 278 | size = sizeof(*compat); |
|---|
| .. | .. |
|---|
| 432 | 366 | struct compat_efi_variable *compat = (struct compat_efi_variable *)buf; |
|---|
| 433 | 367 | struct efi_variable *new_var = (struct efi_variable *)buf; |
|---|
| 434 | 368 | struct efivar_entry *new_entry; |
|---|
| 435 | | - bool need_compat = is_compat(); |
|---|
| 369 | + bool need_compat = in_compat_syscall(); |
|---|
| 436 | 370 | efi_char16_t *name; |
|---|
| 437 | 371 | unsigned long size; |
|---|
| 438 | 372 | u32 attributes; |
|---|
| .. | .. |
|---|
| 509 | 443 | if (!capable(CAP_SYS_ADMIN)) |
|---|
| 510 | 444 | return -EACCES; |
|---|
| 511 | 445 | |
|---|
| 512 | | - if (is_compat()) { |
|---|
| 446 | + if (in_compat_syscall()) { |
|---|
| 513 | 447 | if (count != sizeof(*compat)) |
|---|
| 514 | 448 | return -EINVAL; |
|---|
| 515 | 449 | |
|---|
| .. | .. |
|---|
| 655 | 589 | return error; |
|---|
| 656 | 590 | } |
|---|
| 657 | 591 | |
|---|
| 658 | | -static int efivar_update_sysfs_entry(efi_char16_t *name, efi_guid_t vendor, |
|---|
| 659 | | - unsigned long name_size, void *data) |
|---|
| 660 | | -{ |
|---|
| 661 | | - struct efivar_entry *entry = data; |
|---|
| 662 | | - |
|---|
| 663 | | - if (efivar_entry_find(name, vendor, &efivar_sysfs_list, false)) |
|---|
| 664 | | - return 0; |
|---|
| 665 | | - |
|---|
| 666 | | - memcpy(entry->var.VariableName, name, name_size); |
|---|
| 667 | | - memcpy(&(entry->var.VendorGuid), &vendor, sizeof(efi_guid_t)); |
|---|
| 668 | | - |
|---|
| 669 | | - return 1; |
|---|
| 670 | | -} |
|---|
| 671 | | - |
|---|
| 672 | | -static void efivar_update_sysfs_entries(struct work_struct *work) |
|---|
| 673 | | -{ |
|---|
| 674 | | - struct efivar_entry *entry; |
|---|
| 675 | | - int err; |
|---|
| 676 | | - |
|---|
| 677 | | - /* Add new sysfs entries */ |
|---|
| 678 | | - while (1) { |
|---|
| 679 | | - entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
|---|
| 680 | | - if (!entry) |
|---|
| 681 | | - return; |
|---|
| 682 | | - |
|---|
| 683 | | - err = efivar_init(efivar_update_sysfs_entry, entry, |
|---|
| 684 | | - false, &efivar_sysfs_list); |
|---|
| 685 | | - if (!err) |
|---|
| 686 | | - break; |
|---|
| 687 | | - |
|---|
| 688 | | - efivar_create_sysfs_entry(entry); |
|---|
| 689 | | - } |
|---|
| 690 | | - |
|---|
| 691 | | - kfree(entry); |
|---|
| 692 | | -} |
|---|
| 693 | | - |
|---|
| 694 | 592 | static int efivars_sysfs_callback(efi_char16_t *name, efi_guid_t vendor, |
|---|
| 695 | 593 | unsigned long name_size, void *data) |
|---|
| 696 | 594 | { |
|---|
| .. | .. |
|---|
| 739 | 637 | kset_unregister(efivars_kset); |
|---|
| 740 | 638 | } |
|---|
| 741 | 639 | |
|---|
| 742 | | -int efivars_sysfs_init(void) |
|---|
| 640 | +static int efivars_sysfs_init(void) |
|---|
| 743 | 641 | { |
|---|
| 744 | 642 | struct kobject *parent_kobj = efivars_kobject(); |
|---|
| 745 | 643 | int error = 0; |
|---|
| 746 | 644 | |
|---|
| 747 | | - if (!efi_enabled(EFI_RUNTIME_SERVICES)) |
|---|
| 748 | | - return -ENODEV; |
|---|
| 749 | | - |
|---|
| 750 | 645 | /* No efivars has been registered yet */ |
|---|
| 751 | | - if (!parent_kobj) |
|---|
| 646 | + if (!parent_kobj || !efivar_supports_writes()) |
|---|
| 752 | 647 | return 0; |
|---|
| 753 | 648 | |
|---|
| 754 | 649 | printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, |
|---|
| .. | .. |
|---|
| 768 | 663 | return error; |
|---|
| 769 | 664 | } |
|---|
| 770 | 665 | |
|---|
| 771 | | - INIT_WORK(&efivar_work, efivar_update_sysfs_entries); |
|---|
| 772 | | - |
|---|
| 773 | 666 | return 0; |
|---|
| 774 | 667 | } |
|---|
| 775 | | -EXPORT_SYMBOL_GPL(efivars_sysfs_init); |
|---|
| 776 | 668 | |
|---|
| 777 | 669 | module_init(efivars_sysfs_init); |
|---|
| 778 | 670 | module_exit(efivars_sysfs_exit); |
|---|