Thread View: linux.kernel.netdev
4 messages
4 total messages
Started by Tristan Madani
Wed, 11 Nov 2026 15:31
[PATCH net] net/sched: cls_flow: pin file with get_file_rcu before reading f_cred
Author: Tristan Madani
Date: Wed, 11 Nov 2026 15:31
Date: Wed, 11 Nov 2026 15:31
70 lines
12861 bytes
12861 bytes
From: Tristan Madani <tristan@talencesecurity.com>
flow_get_skuid() and flow_get_skgid() read sk->sk_socket->file->f_cred
without holding a reference to the file. Since the file slab uses
SLAB_TYPESAFE_BY_RCU, a concurrent close() may free and recycle the file
object, causing stale credential data to be read through f_cred.
Pin the file with get_file_rcu() before accessing its credentials and
release with fput() afterwards.
Fixes: 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/sched/cls_flow.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
index a9ac3acf6eda0..233ca13299930 100644
--- a/net/sched/cls_flow.c
+++ b/net/sched/cls_flow.c
@@ -17,6 +17,7 @@
#include <linux/ipv6.h>
#include <linux/if_vlan.h>
#include <linux/slab.h>
+#include <linux/fs.h>
#include <linux/module.h>
#include <net/inet_sock.h>
@@ -208,10 +209,16 @@ static u32 flow_get_rtclassid(const struct sk_buff *skb)
static u32 flow_get_skuid(const struct sk_buff *skb)
{
struct sock *sk = skb_to_full_sk(skb);
+ struct file *filp;
- if (sk && sk->sk_socket && sk->sk_socket->file) {
- kuid_t skuid = sk->sk_socket->file->f_cred->fsuid;
+ if (!sk || !sk->sk_socket)
+ return 0;
+
+ filp = get_file_rcu(&sk->sk_socket->file);
+ if (filp) {
+ kuid_t skuid = filp->f_cred->fsuid;
+ fput(filp);
return from_kuid(&init_user_ns, skuid);
}
return 0;
@@ -220,10 +227,16 @@ static u32 flow_get_skuid(const struct sk_buff *skb)
static u32 flow_get_skgid(const struct sk_buff *skb)
{
struct sock *sk = skb_to_full_sk(skb);
+ struct file *filp;
+
+ if (!sk || !sk->sk_socket)
+ return 0;
- if (sk && sk->sk_socket && sk->sk_socket->file) {
- kgid_t skgid = sk->sk_socket->file->f_cred->fsgid;
+ filp = get_file_rcu(&sk->sk_socket->file);
+ if (filp) {
+ kgid_t skgid = filp->f_cred->fsgid;
+ fput(filp);
return from_kgid(&init_user_ns, skgid);
}
return 0;
--
2.47.3
Re: [PATCH net] net/sched: cls_flow: pin file with get_file_rcu before reading f_cred
Author: netdev-bot+sinfo
Date: Wed, 11 Nov 2026 15:37
Date: Wed, 11 Nov 2026 15:37
22 lines
8804 bytes
8804 bytes
Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan. - Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then. The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH net] net/sched: cls_flow: pin file with get_file_rcu before reading f_cred
Author: Tristan Madani
Date: Fri, 13 Nov 2026 22:09
Date: Fri, 13 Nov 2026 22:09
16 lines
11606 bytes
11606 bytes
These were found by manual code inspection. After commit 0ede61d8589cc
("file: convert to SLAB_TYPESAFE_BY_RCU"), I audited callers that read
file->f_cred under RCU without pinning the file with get_file_rcu().
The issue has not been triggered in practice. It is a theoretical race
where a struct file slab slot is freed and reused while netfilter code
still reads f_cred through the old pointer, but the race window is
narrow (a few loads in softirq context).
The same bug class was independently confirmed and fixed in eventpoll
(commits a10fbbe74e1c7, 0d8cd9537c641 in v7.3), which validates that
SLAB_TYPESAFE_BY_RCU file reuse is a real concern for unpinned readers.
Thanks,
Tristan
Re: [PATCH net] net/sched: cls_flow: pin file with get_file_rcu before reading f_cred
Author: Jakub Kicinski
Date: Sun, 15 Nov 2026 19:08
Date: Sun, 15 Nov 2026 19:08
19 lines
8827 bytes
8827 bytes
On Wed, 11 Nov 2026 15:31:06 +0000 Tristan Madani wrote: > flow_get_skuid() and flow_get_skgid() read sk->sk_socket->file->f_cred > without holding a reference to the file. Since the file slab uses > SLAB_TYPESAFE_BY_RCU, a concurrent close() may free and recycle the file > object, causing stale credential data to be read through f_cred. Missing annotations. Please also make sure you include the answer to the questions from the bug discovery bot in the commit message of v2. Otherwise it will ask you again. net/sched/cls_flow.c:217:32: warning: incorrect type in argument 1 (different address spaces) net/sched/cls_flow.c:217:32: expected struct file [noderef] __rcu **f net/sched/cls_flow.c:217:32: got struct file ** net/sched/cls_flow.c:235:32: warning: incorrect type in argument 1 (different address spaces) net/sched/cls_flow.c:235:32: expected struct file [noderef] __rcu **f net/sched/cls_flow.c:235:32: got struct file ** -- pw-bot: cr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads