Date: Tue, 3 Aug 2021 09:52:54 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: dfda6a71e7e1 - stable/13 - /dev/pci: clarify meaning of writeable file descriptor Message-ID: <202108030952.1739qs2F081509@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=dfda6a71e7e185eba840cc8924fe744836d6c232 commit dfda6a71e7e185eba840cc8924fe744836d6c232 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-07-27 00:22:14 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-08-03 09:52:36 +0000 /dev/pci: clarify meaning of writeable file descriptor (cherry picked from commit 85ae35ef37c07c32d4e923435b637cbf0df3e8a3) --- share/man/man4/pci.4 | 15 +++++++++++++-- sys/dev/pci/pci_user.c | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/share/man/man4/pci.4 b/share/man/man4/pci.4 index 18eaae1cd4d4..28a456d18179 100644 --- a/share/man/man4/pci.4 +++ b/share/man/man4/pci.4 @@ -24,12 +24,12 @@ .\" .\" $FreeBSD$ .\" -.Dd June 17, 2019 +.Dd July 27, 2021 .Dt PCI 4 .Os .Sh NAME .Nm pci -.Nd generic PCI bus driver +.Nd generic PCI/PCIe bus driver .Sh SYNOPSIS To compile the PCI bus driver into the kernel, place the following line in your @@ -53,6 +53,8 @@ The .Nm driver provides support for .Tn PCI +and +.Tn PCIe devices in the kernel and limited access to .Tn PCI devices for userland. @@ -80,6 +82,15 @@ granting access to the device. If used improperly, this driver can allow userland applications to crash a machine or cause data loss. +In particular, driver only allows operations on the opened +.Pa /dev/pci +to modify system state if the file descriptor was opened for writing. +For instance, the +.Dv PCIOCREAD +and +.Dv PCIOCBARMMAP +operations require a writeable descriptor, because reading a config register +or a BAR read access could have function-specific side-effects. .Pp The .Nm diff --git a/sys/dev/pci/pci_user.c b/sys/dev/pci/pci_user.c index c34fd715707e..640a10abfeca 100644 --- a/sys/dev/pci/pci_user.c +++ b/sys/dev/pci/pci_user.c @@ -943,7 +943,12 @@ pci_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *t io_old = NULL; #endif - if (!(flag & FWRITE)) { + /* + * Interpret read-only opened /dev/pci as a promise that no + * operation of the file descriptor could modify system state, + * including side-effects due to reading devices registers. + */ + if ((flag & FWRITE) == 0) { switch (cmd) { case PCIOCGETCONF: #ifdef COMPAT_FREEBSD32
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108030952.1739qs2F081509>