From 2e62782dac95dc946eab90cf433f4d66ca0b39a3 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 3 Aug 2018 18:35:20 +0000 Subject: [PATCH] Require write access when mmapping BAR. This actually makes the rights requirements for accessing PCI config space and BARs using /dev/pci same. Since unchanged /dev/pci mode only allows write open for root, default configuration de-facto limits the BAR read to root only. In particular, state-changing reads of the registers are limited to root. Discussed with: se Suggested and reviewed by: jhb (kernel part) Sponsored by: The FreeBSD Foundation MFC after: 12 days Differential revision: https://reviews.freebsd.org/D16580 --- sys/dev/pci/pci_user.c | 1 - usr.sbin/pciconf/pciconf.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sys/dev/pci/pci_user.c b/sys/dev/pci/pci_user.c index 6f8f27972185..4053e193b012 100644 --- a/sys/dev/pci/pci_user.c +++ b/sys/dev/pci/pci_user.c @@ -809,7 +809,6 @@ pci_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *t #endif case PCIOCGETBAR: case PCIOCLISTVPD: - case PCIOCBARMMAP: break; default: return (EPERM); diff --git a/usr.sbin/pciconf/pciconf.c b/usr.sbin/pciconf/pciconf.c index 66d47ecae618..47b8f96422de 100644 --- a/usr.sbin/pciconf/pciconf.c +++ b/usr.sbin/pciconf/pciconf.c @@ -1085,7 +1085,7 @@ dump_bar(const char *name, const char *reg, const char *bar_start, pbm.pbm_flags = 0; pbm.pbm_memattr = VM_MEMATTR_UNCACHEABLE; /* XXX */ - fd = open(_PATH_DEVPCI, O_RDONLY, 0); + fd = open(_PATH_DEVPCI, O_RDWR, 0); if (fd < 0) err(1, "%s", _PATH_DEVPCI);