|
Jiri Slaby |
0df23e |
From: =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= <kw@linux.com>
|
|
Jiri Slaby |
0df23e |
Date: Thu, 29 Jul 2021 23:37:54 +0000
|
|
Jiri Slaby |
0df23e |
Subject: PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure
|
|
Jiri Slaby |
0df23e |
MIME-Version: 1.0
|
|
Jiri Slaby |
0df23e |
Content-Type: text/plain; charset=UTF-8
|
|
Jiri Slaby |
0df23e |
Content-Transfer-Encoding: 8bit
|
|
Jiri Slaby |
0df23e |
Git-commit: a8bd29bd49c4156ea0ec5a97812333e2aeef44e7
|
|
Jiri Slaby |
0df23e |
Patch-mainline: 5.15-rc1
|
|
Jiri Slaby |
0df23e |
References: git-fixes
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
The pciconfig_read() syscall reads PCI configuration space using
|
|
Jiri Slaby |
0df23e |
hardware-dependent config accessors.
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
If the read fails on PCI, most accessors don't return an error; they
|
|
Jiri Slaby |
0df23e |
pretend the read was successful and got ~0 data from the device, so the
|
|
Jiri Slaby |
0df23e |
syscall returns success with ~0 data in the buffer.
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
When the accessor does return an error, pciconfig_read() normally fills the
|
|
Jiri Slaby |
0df23e |
user's buffer with ~0 and returns an error in errno. But after
|
|
Jiri Slaby |
0df23e |
e4585da22ad0 ("pci syscall.c: Switch to refcounting API"), we don't fill
|
|
Jiri Slaby |
0df23e |
the buffer with ~0 for the EPERM "user lacks CAP_SYS_ADMIN" error.
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
Userspace may rely on the ~0 data to detect errors, but after e4585da22ad0,
|
|
Jiri Slaby |
0df23e |
that would not detect CAP_SYS_ADMIN errors.
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
Restore the original behaviour of filling the buffer with ~0 when the
|
|
Jiri Slaby |
0df23e |
CAP_SYS_ADMIN check fails.
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
[bhelgaas: commit log, fold in Nathan's fix
|
|
Jiri Slaby |
0df23e |
https://lore.kernel.org/r/20210803200836.500658-1-nathan@kernel.org]
|
|
Jiri Slaby |
0df23e |
Fixes: e4585da22ad0 ("pci syscall.c: Switch to refcounting API")
|
|
Jiri Slaby |
0df23e |
Link: https://lore.kernel.org/r/20210729233755.1509616-1-kw@linux.com
|
|
Jiri Slaby |
0df23e |
Signed-off-by: Krzysztof WilczyĆski <kw@linux.com>
|
|
Jiri Slaby |
0df23e |
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
|
|
Jiri Slaby |
0df23e |
Cc: stable@vger.kernel.org
|
|
Jiri Slaby |
0df23e |
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
|
|
Jiri Slaby |
0df23e |
---
|
|
Jiri Slaby |
0df23e |
drivers/pci/syscall.c | 4 +++-
|
|
Jiri Slaby |
0df23e |
1 file changed, 3 insertions(+), 1 deletion(-)
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
--- a/drivers/pci/syscall.c
|
|
Jiri Slaby |
0df23e |
+++ b/drivers/pci/syscall.c
|
|
Jiri Slaby |
0df23e |
@@ -23,8 +23,10 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned
|
|
Jiri Slaby |
0df23e |
long err;
|
|
Jiri Slaby |
0df23e |
int cfg_ret;
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
+ err = -EPERM;
|
|
Jiri Slaby |
0df23e |
+ dev = NULL;
|
|
Jiri Slaby |
0df23e |
if (!capable(CAP_SYS_ADMIN))
|
|
Jiri Slaby |
0df23e |
- return -EPERM;
|
|
Jiri Slaby |
0df23e |
+ goto error;
|
|
Jiri Slaby |
0df23e |
|
|
Jiri Slaby |
0df23e |
err = -ENODEV;
|
|
Jiri Slaby |
0df23e |
dev = pci_get_bus_and_slot(bus, dfn);
|