* [PATCH] rapidio: Use file_ns_capable() when checking config space read access
@ 2026-11-19 4:08 Suyuan Wang via B4 Relay
0 siblings, 0 replies; only message in thread
From: Suyuan Wang via B4 Relay @ 2026-11-19 4:08 UTC (permalink / raw)
To: alex.bou9, akpm, mporter; +Cc: linux-kernel
From: Suyuan Wang <stevewong@hust.edu.cn>
rio_read_config() limits reads to the first 256 bytes unless
capable(CAP_SYS_ADMIN) succeeds. That checks the credentials of the
task doing the read, not those of the task that opened the file.
The config attribute is mode 0644, so any user can open it. If such a
descriptor is later read by a task that has CAP_SYS_ADMIN, the read
covers the full maintenance space. The allowed range follows whoever
happens to read the descriptor instead of the credentials it was
opened with.
Use file_ns_capable() with init_user_ns so the check is made against
the credentials saved in the file at open() time. A descriptor opened
without CAP_SYS_ADMIN then stays limited to 256 bytes whoever reads it,
and a privileged opener can still hand the descriptor to another task.
This matches pci_read_config() in PCI sysfs, and the PCI procfs change
in commit f82f53e75eff ("PCI/proc: Use file_ns_capable() when checking
config space read access").
Found with a static analysis tool and checked by hand.
Fixes: 394b701ce4fb ("[PATCH] RapidIO support: core base")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on x86_64 (W=1, no new warnings). I don't have RapidIO
hardware; the fix is by inspection.
---
drivers/rapidio/rio-sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index 0949c869b2f1..a85b73939a9e 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -123,7 +123,7 @@ rio_read_config(struct file *filp, struct kobject *kobj,
u8 *data = (u8 *) buf;
/* Several chips lock up trying to read undefined config space */
- if (capable(CAP_SYS_ADMIN))
+ if (file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN))
size = RIO_MAINT_SPACE_SZ;
if (off >= size)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 4:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 4:08 [PATCH] rapidio: Use file_ns_capable() when checking config space read access Suyuan Wang via B4 Relay
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®