From: Tristan Madani <tristmd@gmail.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>, Jiri Pirko <jiri@resnulli.us>
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Christian Brauner <brauner@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
Tristan Madani <tristan@talencesecurity.com>
Subject: [PATCH net] net/sched: cls_flow: pin file with get_file_rcu before reading f_cred
Date: Wed, 11 Nov 2026 15:31:06 +0000 [thread overview]
Message-ID: <20261111153106.580776-1-tristmd@gmail.com> (raw)
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
next reply other threads:[~2026-11-11 15:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 15:31 Tristan Madani [this message]
2026-11-11 15:37 ` netdev-bot+sinfo
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=20261111153106.580776-1-tristmd@gmail.com \
--to=tristmd@gmail.com \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tristan@talencesecurity.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®