* [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred
@ 2026-10-13 23:43 Tristan Madani
2026-10-13 23:43 ` [PATCH nf 1/5] netfilter: xt_owner: " Tristan Madani
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Tristan Madani @ 2026-10-13 23:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Christian Brauner, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netfilter-devel,
coreteam, netdev, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
Since commit 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU"),
struct file objects can have their slab slot reused while RCU readers
still hold pointers to them.
Five netfilter locations read file->f_cred through a stored sock->file
pointer under RCU without pinning the file. If the slab slot is
reused between the pointer read and the credential dereference, the
check operates on stale or unrelated credential data.
Pin the file with get_file_rcu() and release with fput() on all paths.
Tristan Madani (5):
netfilter: xt_owner: pin file with get_file_rcu() before reading
f_cred
netfilter: nft_meta: pin file with get_file_rcu() before reading
f_cred
netfilter: nfnetlink_log: pin file with get_file_rcu() before reading
f_cred
netfilter: nfnetlink_queue: pin file with get_file_rcu() before
reading f_cred
netfilter: nf_log_syslog: pin file with get_file_rcu() before reading
f_cred
net/netfilter/nf_log_syslog.c | 19 ++++++++++++-------
net/netfilter/nfnetlink_log.c | 17 +++++++++++------
net/netfilter/nfnetlink_queue.c | 17 +++++++++++------
net/netfilter/nft_meta.c | 19 ++++++++++++-------
net/netfilter/xt_owner.c | 27 +++++++++++++++---------
5 files changed, 64 insertions(+), 35 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH nf 1/5] netfilter: xt_owner: pin file with get_file_rcu() before reading f_cred
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
@ 2026-10-13 23:43 ` Tristan Madani
2026-10-13 23:43 ` [PATCH nf 2/5] netfilter: nft_meta: " Tristan Madani
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tristan Madani @ 2026-10-13 23:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Christian Brauner, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netfilter-devel,
coreteam, netdev, Tristan Madani, stable
From: Tristan Madani <tristan@talencesecurity.com>
Since commit 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU"),
struct file objects can have their slab slot reused while RCU readers
still hold pointers to them. The xt_owner match reads file->f_cred to
check fsuid/fsgid/group_info in the packet path without pinning the
file. If the file is freed and the slab slot is reused between reading
sock->file and dereferencing f_cred, the credential check will operate
on stale or unrelated credential data.
Use get_file_rcu() to take a reference on the file before accessing its
credentials, and fput() to release it on all return paths.
Fixes: 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/netfilter/xt_owner.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/net/netfilter/xt_owner.c b/net/netfilter/xt_owner.c
index 8f2e57b2a5868..6386b52147d87 100644
--- a/net/netfilter/xt_owner.c
+++ b/net/netfilter/xt_owner.c
@@ -65,8 +65,8 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)
const struct xt_owner_match_info *info = par->matchinfo;
struct sock *sk = skb_to_full_sk(skb);
struct net *net = xt_net(par);
- const struct socket *sock;
- const struct file *filp;
+ struct socket *sock;
+ struct file *filp;
if (!sk || !READ_ONCE(sk->sk_socket) || !net_eq(net, sock_net(sk)))
return (info->match ^ info->invert) == 0;
@@ -77,13 +77,17 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)
*/
return false;
- /* The sk pointer remains valid as long as the skb is. The sk_socket and
- * file pointer may become NULL if the socket is closed. Both structures
- * (including file->cred) are RCU freed which means they can be accessed
- * within a RCU read section.
+ /* The sk pointer remains valid as long as the skb is. The
+ * sk_socket and file pointer may become NULL if the socket is
+ * closed. Since struct file uses SLAB_TYPESAFE_BY_RCU, pin the
+ * file with get_file_rcu() to ensure f_cred is not from a
+ * reused slab slot.
*/
sock = READ_ONCE(sk->sk_socket);
- filp = sock ? READ_ONCE(sock->file) : NULL;
+ if (sock)
+ filp = get_file_rcu(&sock->file);
+ else
+ filp = NULL;
if (filp == NULL)
return ((info->match ^ info->invert) &
(XT_OWNER_UID | XT_OWNER_GID)) == 0;
@@ -94,8 +98,10 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)
if ((uid_gte(filp->f_cred->fsuid, uid_min) &&
uid_lte(filp->f_cred->fsuid, uid_max)) ^
- !(info->invert & XT_OWNER_UID))
+ !(info->invert & XT_OWNER_UID)) {
+ fput(filp);
return false;
+ }
}
if (info->match & XT_OWNER_GID) {
@@ -120,10 +126,13 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)
}
}
- if (match ^ !(info->invert & XT_OWNER_GID))
+ if (match ^ !(info->invert & XT_OWNER_GID)) {
+ fput(filp);
return false;
+ }
}
+ fput(filp);
return true;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH nf 2/5] netfilter: nft_meta: pin file with get_file_rcu() before reading f_cred
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
2026-10-13 23:43 ` [PATCH nf 1/5] netfilter: xt_owner: " Tristan Madani
@ 2026-10-13 23:43 ` Tristan Madani
2026-10-13 23:43 ` [PATCH nf 3/5] netfilter: nfnetlink_log: " Tristan Madani
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tristan Madani @ 2026-10-13 23:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Christian Brauner, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netfilter-devel,
coreteam, netdev, Tristan Madani, stable
From: Tristan Madani <tristan@talencesecurity.com>
Since commit 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU"),
struct file objects can have their slab slot reused while RCU readers
still hold pointers to them. The nft_meta skuid/skgid evaluation reads
file->f_cred to extract fsuid/fsgid without pinning the file. If the
file is freed and the slab slot is reused, the credential data may
belong to a different file.
Use get_file_rcu() to take a reference on the file before accessing its
credentials, and fput() to release it afterward.
Fixes: 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/netfilter/nft_meta.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 01cfbaa365250..069c01a71df16 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -135,19 +135,23 @@ nft_meta_get_eval_skugid(enum nft_meta_keys key,
const struct nft_pktinfo *pkt)
{
const struct sock *sk = skb_to_full_sk(pkt->skb);
- const struct socket *sock;
- const struct file *file;
+ struct socket *sock;
+ struct file *file;
if (!sk || !sk_fullsock(sk) || !net_eq(nft_net(pkt), sock_net(sk)))
return false;
- /* The sk pointer remains valid as long as the skb is. The sk_socket and
- * file pointer may become NULL if the socket is closed. Both structures
- * (including file->cred) are RCU freed which means they can be accessed
- * within a RCU read section.
+ /* The sk pointer remains valid as long as the skb is. The
+ * sk_socket and file pointer may become NULL if the socket is
+ * closed. Since struct file uses SLAB_TYPESAFE_BY_RCU, pin the
+ * file with get_file_rcu() to ensure f_cred is not from a
+ * reused slab slot.
*/
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
+ if (sock)
+ file = get_file_rcu(&sock->file);
+ else
+ file = NULL;
if (!file)
return false;
@@ -164,6 +168,7 @@ nft_meta_get_eval_skugid(enum nft_meta_keys key,
break;
}
+ fput(file);
return true;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH nf 3/5] netfilter: nfnetlink_log: pin file with get_file_rcu() before reading f_cred
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
2026-10-13 23:43 ` [PATCH nf 1/5] netfilter: xt_owner: " Tristan Madani
2026-10-13 23:43 ` [PATCH nf 2/5] netfilter: nft_meta: " Tristan Madani
@ 2026-10-13 23:43 ` Tristan Madani
2026-10-13 23:43 ` [PATCH nf 4/5] netfilter: nfnetlink_queue: " Tristan Madani
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tristan Madani @ 2026-10-13 23:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Christian Brauner, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netfilter-devel,
coreteam, netdev, Tristan Madani, stable
From: Tristan Madani <tristan@talencesecurity.com>
Since commit 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU"),
struct file objects can have their slab slot reused while RCU readers
still hold pointers to them. The NFLOG UID/GID metadata construction
reads file->f_cred without pinning the file, which could lead to
logging credentials from an unrelated file if the slab slot is reused.
Use get_file_rcu() to take a reference on the file before reading
credentials, and fput() to release it after extracting uid/gid values.
Fixes: 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/netfilter/nfnetlink_log.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index d923f2cb13980..8c9e297a7dc18 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -632,22 +632,27 @@ __build_packet_message(struct nfnl_log_net *log,
/* UID */
sk = skb->sk;
if (sk && sk_fullsock(sk)) {
- const struct socket *sock;
- const struct file *file;
+ struct socket *sock;
+ struct file *file;
/* The sk pointer remains valid as long as the skb is.
* The sk_socket and file pointer may become NULL
- * if the socket is closed.
- * Both structures (including file->cred) are RCU freed
- * which means they can be accessed within a RCU read section.
+ * if the socket is closed. Since struct file uses
+ * SLAB_TYPESAFE_BY_RCU, pin the file with
+ * get_file_rcu() to ensure f_cred is not from a
+ * reused slab slot.
*/
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
+ if (sock)
+ file = get_file_rcu(&sock->file);
+ else
+ file = NULL;
if (file) {
const struct cred *cred = file->f_cred;
struct user_namespace *user_ns = inst->peer_user_ns;
__be32 uid = htonl(from_kuid_munged(user_ns, cred->fsuid));
__be32 gid = htonl(from_kgid_munged(user_ns, cred->fsgid));
+ fput(file);
if (nla_put_be32(inst->skb, NFULA_UID, uid) ||
nla_put_be32(inst->skb, NFULA_GID, gid))
goto nla_put_failure;
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH nf 4/5] netfilter: nfnetlink_queue: pin file with get_file_rcu() before reading f_cred
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
` (2 preceding siblings ...)
2026-10-13 23:43 ` [PATCH nf 3/5] netfilter: nfnetlink_log: " Tristan Madani
@ 2026-10-13 23:43 ` Tristan Madani
2026-10-13 23:43 ` [PATCH nf 5/5] netfilter: nf_log_syslog: " Tristan Madani
2026-10-13 23:50 ` [PATCH nf 0/5] netfilter: " netdev-bot+sinfo
5 siblings, 0 replies; 7+ messages in thread
From: Tristan Madani @ 2026-10-13 23:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Christian Brauner, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netfilter-devel,
coreteam, netdev, Tristan Madani, stable
From: Tristan Madani <tristan@talencesecurity.com>
Since commit 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU"),
struct file objects can have their slab slot reused while RCU readers
still hold pointers to them. The NFQUEUE UID/GID metadata construction
reads file->f_cred without pinning the file, which could lead to
reporting credentials from an unrelated file if the slab slot is reused.
Use get_file_rcu() to take a reference on the file before reading
credentials, and fput() to release it after extracting the cred pointer.
Fixes: 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/netfilter/nfnetlink_queue.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index a3bc002800510..ebf9c9a8a9f98 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -566,8 +566,8 @@ nfqnl_put_packet_info(struct sk_buff *nlskb, struct sk_buff *packet,
static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)
{
- const struct socket *sock;
- const struct file *file;
+ struct socket *sock;
+ struct file *file;
const struct cred *cred;
if (!sk_fullsock(sk))
@@ -575,14 +575,19 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)
/* The sk pointer remains valid as long as the skb is.
* The sk_socket and file pointer may become NULL
- * if the socket is closed.
- * Both structures (including file->cred) are RCU freed
- * which means they can be accessed within a RCU read section.
+ * if the socket is closed. Since struct file uses
+ * SLAB_TYPESAFE_BY_RCU, pin the file with
+ * get_file_rcu() to ensure f_cred is not from a
+ * reused slab slot.
*/
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
+ if (sock)
+ file = get_file_rcu(&sock->file);
+ else
+ file = NULL;
if (file) {
cred = file->f_cred;
+ fput(file);
if (nla_put_be32(skb, NFQA_UID,
htonl(from_kuid_munged(&init_user_ns, cred->fsuid))))
goto nla_put_failure;
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH nf 5/5] netfilter: nf_log_syslog: pin file with get_file_rcu() before reading f_cred
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
` (3 preceding siblings ...)
2026-10-13 23:43 ` [PATCH nf 4/5] netfilter: nfnetlink_queue: " Tristan Madani
@ 2026-10-13 23:43 ` Tristan Madani
2026-10-13 23:50 ` [PATCH nf 0/5] netfilter: " netdev-bot+sinfo
5 siblings, 0 replies; 7+ messages in thread
From: Tristan Madani @ 2026-10-13 23:43 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Christian Brauner, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netfilter-devel,
coreteam, netdev, Tristan Madani, stable
From: Tristan Madani <tristan@talencesecurity.com>
Since commit 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU"),
struct file objects can have their slab slot reused while RCU readers
still hold pointers to them. The syslog UID/GID output reads
file->f_cred without pinning the file, which could lead to logging
credentials from an unrelated file if the slab slot is reused.
Use get_file_rcu() to take a reference on the file before reading
credentials, and fput() to release it after extracting the values.
Fixes: 0ede61d8589cc ("file: convert to SLAB_TYPESAFE_BY_RCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
net/netfilter/nf_log_syslog.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c
index c3fd398ffcd77..f41bf83190912 100644
--- a/net/netfilter/nf_log_syslog.c
+++ b/net/netfilter/nf_log_syslog.c
@@ -168,22 +168,27 @@ static struct nf_logger nf_arp_logger __read_mostly = {
static void nf_log_dump_sk_uid_gid(struct net *net, struct nf_log_buf *m,
struct sock *sk)
{
- const struct socket *sock;
- const struct file *file;
+ struct socket *sock;
+ struct file *file;
if (!sk || !sk_fullsock(sk) || !net_eq(net, sock_net(sk)))
return;
- /* The sk pointer remains valid as long as the skb is. The sk_socket and
- * file pointer may become NULL if the socket is closed. Both structures
- * (including file->cred) are RCU freed which means they can be accessed
- * within a RCU read section.
+ /* The sk pointer remains valid as long as the skb is. The
+ * sk_socket and file pointer may become NULL if the socket is
+ * closed. Since struct file uses SLAB_TYPESAFE_BY_RCU, pin the
+ * file with get_file_rcu() to ensure f_cred is not from a
+ * reused slab slot.
*/
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
+ if (sock)
+ file = get_file_rcu(&sock->file);
+ else
+ file = NULL;
if (file) {
const struct cred *cred = file->f_cred;
+ fput(file);
nf_log_buf_add(m, "UID=%u GID=%u ",
from_kuid_munged(&init_user_ns, cred->fsuid),
from_kgid_munged(&init_user_ns, cred->fsgid));
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
` (4 preceding siblings ...)
2026-10-13 23:43 ` [PATCH nf 5/5] netfilter: nf_log_syslog: " Tristan Madani
@ 2026-10-13 23:50 ` netdev-bot+sinfo
5 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-10-13 23:50 UTC (permalink / raw)
To: Tristan Madani
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
Christian Brauner, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, netfilter-devel, coreteam, netdev,
Tristan Madani
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 code inspection). If it was triggered please include
the symptoms, like the stack trace or error 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-10-13 23:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 23:43 [PATCH nf 0/5] netfilter: pin file with get_file_rcu() before reading f_cred Tristan Madani
2026-10-13 23:43 ` [PATCH nf 1/5] netfilter: xt_owner: " Tristan Madani
2026-10-13 23:43 ` [PATCH nf 2/5] netfilter: nft_meta: " Tristan Madani
2026-10-13 23:43 ` [PATCH nf 3/5] netfilter: nfnetlink_log: " Tristan Madani
2026-10-13 23:43 ` [PATCH nf 4/5] netfilter: nfnetlink_queue: " Tristan Madani
2026-10-13 23:43 ` [PATCH nf 5/5] netfilter: nf_log_syslog: " Tristan Madani
2026-10-13 23:50 ` [PATCH nf 0/5] netfilter: " netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox