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
92 lines
2.2 KiB
C
92 lines
2.2 KiB
C
#include <linux/sched.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/pid_namespace.h>
|
|
#include "internal.h"
|
|
|
|
/*
|
|
* /proc/self:
|
|
*/
|
|
static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
|
|
int buflen)
|
|
{
|
|
struct pid_namespace *ns = dentry->d_sb->s_fs_info;
|
|
pid_t tgid = task_tgid_nr_ns(current, ns);
|
|
char tmp[PROC_NUMBUF];
|
|
if (!tgid)
|
|
return -ENOENT;
|
|
sprintf(tmp, "%d", tgid);
|
|
return readlink_copy(buffer, buflen, tmp);
|
|
}
|
|
|
|
static const char *proc_self_get_link(struct dentry *dentry,
|
|
struct inode *inode,
|
|
struct delayed_call *done)
|
|
{
|
|
struct pid_namespace *ns = inode->i_sb->s_fs_info;
|
|
pid_t tgid = task_tgid_nr_ns(current, ns);
|
|
char *name;
|
|
|
|
/*
|
|
* Not currently supported. Once we can inherit all of struct pid,
|
|
* we can allow this.
|
|
*/
|
|
if (current->flags & PF_KTHREAD)
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
if (!tgid)
|
|
return ERR_PTR(-ENOENT);
|
|
/* 11 for max length of signed int in decimal + NULL term */
|
|
name = kmalloc(12, dentry ? GFP_KERNEL : GFP_ATOMIC);
|
|
if (unlikely(!name))
|
|
return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD);
|
|
sprintf(name, "%d", tgid);
|
|
set_delayed_call(done, kfree_link, name);
|
|
return name;
|
|
}
|
|
|
|
static const struct inode_operations proc_self_inode_operations = {
|
|
.readlink = proc_self_readlink,
|
|
.get_link = proc_self_get_link,
|
|
};
|
|
|
|
static unsigned self_inum;
|
|
|
|
int proc_setup_self(struct super_block *s)
|
|
{
|
|
struct inode *root_inode = d_inode(s->s_root);
|
|
struct pid_namespace *ns = s->s_fs_info;
|
|
struct dentry *self;
|
|
|
|
inode_lock(root_inode);
|
|
self = d_alloc_name(s->s_root, "self");
|
|
if (self) {
|
|
struct inode *inode = new_inode(s);
|
|
if (inode) {
|
|
inode->i_ino = self_inum;
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
|
inode->i_mode = S_IFLNK | S_IRWXUGO;
|
|
inode->i_uid = GLOBAL_ROOT_UID;
|
|
inode->i_gid = GLOBAL_ROOT_GID;
|
|
inode->i_op = &proc_self_inode_operations;
|
|
d_add(self, inode);
|
|
} else {
|
|
dput(self);
|
|
self = ERR_PTR(-ENOMEM);
|
|
}
|
|
} else {
|
|
self = ERR_PTR(-ENOMEM);
|
|
}
|
|
inode_unlock(root_inode);
|
|
if (IS_ERR(self)) {
|
|
pr_err("proc_fill_super: can't allocate /proc/self\n");
|
|
return PTR_ERR(self);
|
|
}
|
|
ns->proc_self = self;
|
|
return 0;
|
|
}
|
|
|
|
void __init proc_self_init(void)
|
|
{
|
|
proc_alloc_inum(&self_inum);
|
|
}
|