[PATCH] rapidio: Use file_ns_capable() when checking config space read access

From: Suyuan Wang via B4 Relay

Date: Wed Nov 18 2026 - 23:08:09 EST


From: Suyuan Wang <stevewong@xxxxxxxxxxx>

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@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
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)