From: Chris Wright <chrisw@sous-sol.org>
To: greg@kroah.com, jbarnes@virtuousgeek.org, matthew@wil.cx
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, ddutile@redhat.com,
alex.williamson@redhat.com
Subject: [PATCH 2/2] pci: allow sysfs file owner to read device dependent config space
Date: Wed, 12 May 2010 18:29:57 -0700 [thread overview]
Message-ID: <20100513012957.GB28034@sequoia.sous-sol.org> (raw)
In-Reply-To: <20100513012857.GA28034@sequoia.sous-sol.org>
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 the sysfs file owner is also considered privileged enough
to read all of the config space.
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
---
drivers/pci/pci-sysfs.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index ad44557..8a6fcc0 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -21,6 +21,7 @@
#include <linux/stat.h>
#include <linux/topology.h>
#include <linux/mm.h>
+#include <linux/fs.h>
#include <linux/capability.h>
#include <linux/pci-aspm.h>
#include <linux/slab.h>
@@ -362,12 +363,13 @@ pci_read_config(struct file *filp, struct kobject *kobj,
char *buf, loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
+ struct inode *inode = filp->f_path.dentry->d_inode;
unsigned int size = 64;
loff_t init_off = off;
u8 *data = (u8*) buf;
/* Several chips lock up trying to read undefined config space */
- if (capable(CAP_SYS_ADMIN)) {
+ if (capable(CAP_SYS_ADMIN) || is_owner_or_cap(inode)) {
size = dev->cfg_size;
} else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
size = 128;
--
1.6.5.2
next prev parent reply other threads:[~2010-05-13 2:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-13 1:28 [PATCH 1/2] sysfs: add struct file* to bin_attr callbacks Chris Wright
2010-05-13 1:29 ` Chris Wright [this message]
2010-05-13 9:59 ` [PATCH 2/2] pci: allow sysfs file owner to read device dependent config space Alan Cox
2010-05-13 15:05 ` Chris Wright
2010-05-13 17:43 ` [PATCH 2/2 v2] pci: check caps from sysfs file open " Chris Wright
2010-05-13 19:06 ` Greg KH
2010-05-13 19:16 ` Chris Wright
2010-05-13 10:56 ` [PATCH 2/2] pci: allow sysfs file owner " Avi Kivity
2010-05-13 11:02 ` Daniel P. Berrange
2010-05-14 19:09 ` Greg KH
2010-05-14 19:26 ` Jesse Barnes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100513012957.GB28034@sequoia.sous-sol.org \
--to=chrisw@sous-sol.org \
--cc=alex.williamson@redhat.com \
--cc=ddutile@redhat.com \
--cc=greg@kroah.com \
--cc=jbarnes@virtuousgeek.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=matthew@wil.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®