diff options
author | Chris Wright <chrisw@sous-sol.org> | 2010-05-13 13:43:07 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-05-21 12:37:32 -0400 |
commit | de139a3393958c5adc75b7df7619d7e48d9ea559 (patch) | |
tree | 85e80f289413fba3158472d28b7e0c3e153ead58 | |
parent | 2c3c8bea608866d8bd9dcf92657d57fdcac011c5 (diff) |
pci: check caps from sysfs file open to read device dependent config space
The PCI config space bin_attr read handler has a hardcoded CAP_SYS_ADMIN
check to verify privileges before allowing a user to read device
dependent config space. This is meant to protect from an unprivileged
user potentially locking up the box.
When assigning a PCI device directly to a guest with libvirt and KVM,
the sysfs config space file is chown'd to the unprivileged user that
the KVM guest will run as. The guest needs to have full access to the
device's config space since it's responsible for driving the device.
However, despite being the owner of the sysfs file, the CAP_SYS_ADMIN
check will not allow read access beyond the config header.
With this patch we check privileges against the capabilities used when
openining the sysfs file. The allows a privileged process to open the
file and hand it to an unprivileged process, and the unprivileged process
can still read all of the config space.
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/pci/pci-sysfs.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index ad44557e65c4..6309c5a2528f 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/stat.h> | 21 | #include <linux/stat.h> |
22 | #include <linux/topology.h> | 22 | #include <linux/topology.h> |
23 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
24 | #include <linux/fs.h> | ||
24 | #include <linux/capability.h> | 25 | #include <linux/capability.h> |
25 | #include <linux/pci-aspm.h> | 26 | #include <linux/pci-aspm.h> |
26 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
@@ -367,7 +368,7 @@ pci_read_config(struct file *filp, struct kobject *kobj, | |||
367 | u8 *data = (u8*) buf; | 368 | u8 *data = (u8*) buf; |
368 | 369 | ||
369 | /* Several chips lock up trying to read undefined config space */ | 370 | /* Several chips lock up trying to read undefined config space */ |
370 | if (capable(CAP_SYS_ADMIN)) { | 371 | if (cap_raised(filp->f_cred->cap_effective, CAP_SYS_ADMIN)) { |
371 | size = dev->cfg_size; | 372 | size = dev->cfg_size; |
372 | } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { | 373 | } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
373 | size = 128; | 374 | size = 128; |