rapidio: Use file_ns_capable() when checking config space read access
Subsystems (2)
PATCH 1/1 rapidio: Use file_ns_capable() when checking config space read access
From: Suyuan Wang <[email protected]>
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.
---
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(-)
drivers/rapidio/rio-sysfs.c +1 -1
@@ -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)
Andrew Morton
tree notice+ rapidio-use-file_ns_capable-when-checking-config-space-read-access.patch added to mm-nonmm-unstable branch
The patch titled Subject: rapidio: use file_ns_capable() when checking config space read access has been added to the -mm mm-nonmm-unstable branch. Its filename is…
The patch titled
Subject: rapidio: use file_ns_capable() when checking config space read access
has been added to the -mm mm-nonmm-unstable branch. Its filename is
rapidio-use-file_ns_capable-when-checking-config-space-read-access.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/rapidio-use-file_ns_capable-when-checking-config-space-read-access.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Suyuan Wang <[email protected]>
Subject: rapidio: use file_ns_capable() when checking config space read access
Date: Thu, 19 Nov 2026 04:08:00 +0000
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.
drivers/rapidio/rio-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rapidio/rio-sysfs.c renamed from drivers/rapidio/rio-sysfs.c~rapidio-use-file_ns_capable-when-checking-config-space-read-access +1 -1
@@ -123,7 +123,7 @@ rio_read_config(struct file *filp, strucu8 *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)
_
Patches currently in -mm which might be from [email protected] are
rapidio-use-file_ns_capable-when-checking-config-space-read-access.patch