mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: alex.bou9@gmail.com, akpm@linux-foundation.org,
	 mporter@kernel.crashing.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] rapidio: Use file_ns_capable() when checking config space read access
Date: Thu, 19 Nov 2026 04:08:00 +0000	[thread overview]
Message-ID: <20261119-rio-v1-1-3cf63c5198ff@gmail.com> (raw)

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)





                 reply	other threads:[~2026-11-19  4:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119-rio-v1-1-3cf63c5198ff@gmail.com \
    --to=devnull+shyckless.gmail.com@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex.bou9@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mporter@kernel.crashing.org \
    --cc=shyckless@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®