Changes in 4.9.247 perf event: Check ref_reloc_sym before using it mm/userfaultfd: do not access vma->vm_mm after calling handle_userfault() btrfs: fix lockdep splat when reading qgroup config on mount PCI: Add device even if driver attach failed btrfs: tree-checker: Enhance chunk checker to validate chunk profile btrfs: inode: Verify inode mode to avoid NULL pointer dereference arm64: pgtable: Fix pte_accessible() ALSA: hda/hdmi: Use single mutex unlock in error paths ALSA: hda/hdmi: fix incorrect locking in hdmi_pcm_close HID: cypress: Support Varmilo Keyboards' media hotkeys Input: i8042 - allow insmod to succeed on devices without an i8042 controller HID: hid-sensor-hub: Fix issue with devices with no report ID dmaengine: xilinx_dma: use readl_poll_timeout_atomic variant x86/xen: don't unbind uninitialized lock_kicker_irq proc: don't allow async path resolution of /proc/self components dmaengine: pl330: _prep_dma_memcpy: Fix wrong burst size scsi: libiscsi: Fix NOP race condition scsi: target: iscsi: Fix cmd abort fabric stop race perf/x86: fix sysfs type mismatches phy: tegra: xusb: Fix dangling pointer on probe failure batman-adv: set .owner to THIS_MODULE scsi: ufs: Fix race between shutdown and runtime resume flow bnxt_en: fix error return code in bnxt_init_board() video: hyperv_fb: Fix the cache type when mapping the VRAM bnxt_en: Release PCI regions when DMA mask setup fails during probe. IB/mthca: fix return value of error branch in mthca_init_cq() nfc: s3fwrn5: use signed integer for parsing GPIO numbers net: ena: set initial DMA width to avoid intel iommu issue ibmvnic: fix NULL pointer dereference in ibmvic_reset_crq efivarfs: revert "fix memory leak in efivarfs_create()" can: gs_usb: fix endianess problem with candleLight firmware platform/x86: toshiba_acpi: Fix the wrong variable assignment perf probe: Fix to die_entrypc() returns error correctly USB: core: Change %pK for __user pointers to %px usb: gadget: f_midi: Fix memleak in f_midi_alloc usb: gadget: Fix memleak in gadgetfs_fill_super x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb regulator: avoid resolve_supply() infinite recursion regulator: workaround self-referent regulators USB: core: add endpoint-blacklist quirk USB: core: Fix regression in Hercules audio card Linux 4.9.247 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I077a342073700f16f0d902b10597b7a3ded56914
142 lines
3.2 KiB
C
142 lines
3.2 KiB
C
/*
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
* Copyright (C) 2012 Jeremy Kerr <jeremy.kerr@canonical.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/efi.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/kmemleak.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/uuid.h>
|
|
|
|
#include "internal.h"
|
|
|
|
struct inode *efivarfs_get_inode(struct super_block *sb,
|
|
const struct inode *dir, int mode,
|
|
dev_t dev, bool is_removable)
|
|
{
|
|
struct inode *inode = new_inode(sb);
|
|
|
|
if (inode) {
|
|
inode->i_ino = get_next_ino();
|
|
inode->i_mode = mode;
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
|
inode->i_flags = is_removable ? 0 : S_IMMUTABLE;
|
|
switch (mode & S_IFMT) {
|
|
case S_IFREG:
|
|
inode->i_fop = &efivarfs_file_operations;
|
|
break;
|
|
case S_IFDIR:
|
|
inode->i_op = &efivarfs_dir_inode_operations;
|
|
inode->i_fop = &simple_dir_operations;
|
|
inc_nlink(inode);
|
|
break;
|
|
}
|
|
}
|
|
return inode;
|
|
}
|
|
|
|
/*
|
|
* Return true if 'str' is a valid efivarfs filename of the form,
|
|
*
|
|
* VariableName-12345678-1234-1234-1234-1234567891bc
|
|
*/
|
|
bool efivarfs_valid_name(const char *str, int len)
|
|
{
|
|
const char *s = str + len - EFI_VARIABLE_GUID_LEN;
|
|
|
|
/*
|
|
* We need a GUID, plus at least one letter for the variable name,
|
|
* plus the '-' separator
|
|
*/
|
|
if (len < EFI_VARIABLE_GUID_LEN + 2)
|
|
return false;
|
|
|
|
/* GUID must be preceded by a '-' */
|
|
if (*(s - 1) != '-')
|
|
return false;
|
|
|
|
/*
|
|
* Validate that 's' is of the correct format, e.g.
|
|
*
|
|
* 12345678-1234-1234-1234-123456789abc
|
|
*/
|
|
return uuid_is_valid(s);
|
|
}
|
|
|
|
static int efivarfs_create(struct inode *dir, struct dentry *dentry,
|
|
umode_t mode, bool excl)
|
|
{
|
|
struct inode *inode = NULL;
|
|
struct efivar_entry *var;
|
|
int namelen, i = 0, err = 0;
|
|
bool is_removable = false;
|
|
|
|
if (!efivarfs_valid_name(dentry->d_name.name, dentry->d_name.len))
|
|
return -EINVAL;
|
|
|
|
var = kzalloc(sizeof(struct efivar_entry), GFP_KERNEL);
|
|
if (!var)
|
|
return -ENOMEM;
|
|
|
|
/* length of the variable name itself: remove GUID and separator */
|
|
namelen = dentry->d_name.len - EFI_VARIABLE_GUID_LEN - 1;
|
|
|
|
uuid_le_to_bin(dentry->d_name.name + namelen + 1, &var->var.VendorGuid);
|
|
|
|
if (efivar_variable_is_removable(var->var.VendorGuid,
|
|
dentry->d_name.name, namelen))
|
|
is_removable = true;
|
|
|
|
inode = efivarfs_get_inode(dir->i_sb, dir, mode, 0, is_removable);
|
|
if (!inode) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
for (i = 0; i < namelen; i++)
|
|
var->var.VariableName[i] = dentry->d_name.name[i];
|
|
|
|
var->var.VariableName[i] = '\0';
|
|
|
|
inode->i_private = var;
|
|
kmemleak_ignore(var);
|
|
|
|
err = efivar_entry_add(var, &efivarfs_list);
|
|
if (err)
|
|
goto out;
|
|
|
|
d_instantiate(dentry, inode);
|
|
dget(dentry);
|
|
out:
|
|
if (err) {
|
|
kfree(var);
|
|
if (inode)
|
|
iput(inode);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)
|
|
{
|
|
struct efivar_entry *var = d_inode(dentry)->i_private;
|
|
|
|
if (efivar_entry_delete(var))
|
|
return -EINVAL;
|
|
|
|
drop_nlink(d_inode(dentry));
|
|
dput(dentry);
|
|
return 0;
|
|
};
|
|
|
|
const struct inode_operations efivarfs_dir_inode_operations = {
|
|
.lookup = simple_lookup,
|
|
.unlink = efivarfs_unlink,
|
|
.create = efivarfs_create,
|
|
};
|