* [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred
@ 2026-11-27 0:16 Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 1/5] netfilter: xt_owner: " Tristan Madani
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Tristan Madani @ 2026-11-27 0:16 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, coreteam,
netfilter-devel, netdev, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
Five netfilter callsites read file->f_cred through the
sk->sk_socket->file chain under RCU without pinning the file reference.
Since commit 0ede61d8589c ("file: convert to SLAB_TYPESAFE_BY_RCU"),
the file slab slot can be freed and reallocated within an RCU grace
period, so these readers may observe stale credential data from a
recycled file object.
This series pins the file with get_file_active() before reading f_cred
and releases it with fput() afterwards, matching the pattern used by
the recently merged cls_flow fix (commit 59cf9e6f48e5a).
Changes in v2:
- Switch from get_file_rcu() to get_file_active() per API change
(get_file_rcu was removed; get_file_active is the current API)
- Reference merged cls_flow fix (59cf9e6f48e5a) which uses the
same pattern for the same bug class
Tristan Madani (5):
netfilter: xt_owner: pin file with get_file_active before reading
f_cred
netfilter: nft_meta: pin file with get_file_active before reading
f_cred
netfilter: nfnetlink_log: pin file with get_file_active before reading
f_cred
netfilter: nfnetlink_queue: pin file with get_file_active before
reading f_cred
netfilter: nf_log_syslog: pin file with get_file_active before reading
f_cred
net/netfilter/nf_log_syslog.c | 28 +++++++++++++-------------
net/netfilter/nfnetlink_log.c | 35 ++++++++++++++++-----------------
net/netfilter/nfnetlink_queue.c | 35 ++++++++++++++++-----------------
net/netfilter/nft_meta.c | 16 +++++++--------
net/netfilter/xt_owner.c | 27 ++++++++++++++-----------
5 files changed, 72 insertions(+), 69 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 nf 1/5] netfilter: xt_owner: pin file with get_file_active before reading f_cred
2026-11-27 0:16 [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred Tristan Madani
@ 2026-11-27 0:16 ` Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 2/5] netfilter: nft_meta: " Tristan Madani
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tristan Madani @ 2026-11-27 0:16 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, coreteam,
netfilter-devel, netdev, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
owner_mt() reads 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_active() before accessing its credentials
and release with fput() afterwards.
Found by manual code inspection; not triggered at runtime.
Fixes: 0ede61d8589c ("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, 16 insertions(+), 11 deletions(-)
diff --git a/net/netfilter/xt_owner.c b/net/netfilter/xt_owner.c
index 8f2e57b2a5868..75fcff0ce21aa 100644
--- a/net/netfilter/xt_owner.c
+++ b/net/netfilter/xt_owner.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/file.h>
+#include <linux/fs.h>
#include <linux/cred.h>
#include <net/sock.h>
@@ -65,8 +66,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,14 +78,13 @@ 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.
- */
sock = READ_ONCE(sk->sk_socket);
- filp = sock ? READ_ONCE(sock->file) : NULL;
- if (filp == NULL)
+ if (!sock)
+ return ((info->match ^ info->invert) &
+ (XT_OWNER_UID | XT_OWNER_GID)) == 0;
+
+ filp = get_file_active(&sock->file);
+ if (!filp)
return ((info->match ^ info->invert) &
(XT_OWNER_UID | XT_OWNER_GID)) == 0;
@@ -94,8 +94,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 +122,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] 6+ messages in thread
* [PATCH v2 nf 2/5] netfilter: nft_meta: pin file with get_file_active before reading f_cred
2026-11-27 0:16 [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 1/5] netfilter: xt_owner: " Tristan Madani
@ 2026-11-27 0:16 ` Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 3/5] netfilter: nfnetlink_log: " Tristan Madani
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Tristan Madani @ 2026-11-27 0:16 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, coreteam,
netfilter-devel, netdev, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
nft_meta_get_eval_skugid() reads 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_active() before accessing its credentials
and release with fput() afterwards.
Found by manual code inspection; not triggered at runtime.
Fixes: 0ede61d8589c ("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 | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 01cfbaa365250..abf0bbce9bfda 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -17,6 +17,7 @@
#include <linux/random.h>
#include <linux/smp.h>
#include <linux/static_key.h>
+#include <linux/fs.h>
#include <net/dst.h>
#include <net/ip.h>
#include <net/sock.h>
@@ -135,19 +136,17 @@ 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.
- */
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
+ if (!sock)
+ return false;
+
+ file = get_file_active(&sock->file);
if (!file)
return false;
@@ -164,6 +163,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] 6+ messages in thread
* [PATCH v2 nf 3/5] netfilter: nfnetlink_log: pin file with get_file_active before reading f_cred
2026-11-27 0:16 [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 1/5] netfilter: xt_owner: " Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 2/5] netfilter: nft_meta: " Tristan Madani
@ 2026-11-27 0:16 ` Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 4/5] netfilter: nfnetlink_queue: " Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 5/5] netfilter: nf_log_syslog: " Tristan Madani
4 siblings, 0 replies; 6+ messages in thread
From: Tristan Madani @ 2026-11-27 0:16 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, coreteam,
netfilter-devel, netdev, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
__build_packet_message() reads 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_active() before accessing its credentials
and release with fput() afterwards.
Found by manual code inspection; not triggered at runtime.
Fixes: 0ede61d8589c ("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 | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index d923f2cb13980..d4fe9a12088f4 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -28,6 +28,7 @@
#include <linux/spinlock.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
+#include <linux/fs.h>
#include <linux/security.h>
#include <linux/list.h>
#include <linux/slab.h>
@@ -632,25 +633,23 @@ __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;
-
- /* 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.
- */
+ struct socket *sock;
+ struct file *file;
+
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->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));
- if (nla_put_be32(inst->skb, NFULA_UID, uid) ||
- nla_put_be32(inst->skb, NFULA_GID, gid))
- goto nla_put_failure;
+ if (sock) {
+ file = get_file_active(&sock->file);
+ 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] 6+ messages in thread
* [PATCH v2 nf 4/5] netfilter: nfnetlink_queue: pin file with get_file_active before reading f_cred
2026-11-27 0:16 [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred Tristan Madani
` (2 preceding siblings ...)
2026-11-27 0:16 ` [PATCH v2 nf 3/5] netfilter: nfnetlink_log: " Tristan Madani
@ 2026-11-27 0:16 ` Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 5/5] netfilter: nf_log_syslog: " Tristan Madani
4 siblings, 0 replies; 6+ messages in thread
From: Tristan Madani @ 2026-11-27 0:16 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, coreteam,
netfilter-devel, netdev, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
nfqnl_put_sk_uidgid() reads 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_active() before accessing its credentials
and release with fput() afterwards.
Found by manual code inspection; not triggered at runtime.
Fixes: 0ede61d8589c ("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 | 35 ++++++++++++++++-----------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index a8aa7ad832c3f..7a31267ae38f6 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -22,6 +22,7 @@
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/proc_fs.h>
+#include <linux/fs.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_ipv6.h>
#include <linux/netfilter_bridge.h>
@@ -578,29 +579,27 @@ 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;
- const struct cred *cred;
+ struct socket *sock;
+ struct file *file;
if (!sk_fullsock(sk))
return 0;
- /* 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.
- */
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
- if (file) {
- cred = file->f_cred;
- if (nla_put_be32(skb, NFQA_UID,
- htonl(from_kuid_munged(&init_user_ns, cred->fsuid))))
- goto nla_put_failure;
- if (nla_put_be32(skb, NFQA_GID,
- htonl(from_kgid_munged(&init_user_ns, cred->fsgid))))
- goto nla_put_failure;
+ if (sock) {
+ file = get_file_active(&sock->file);
+ if (file) {
+ const struct cred *cred = file->f_cred;
+ __be32 uid = htonl(from_kuid_munged(&init_user_ns,
+ cred->fsuid));
+ __be32 gid = htonl(from_kgid_munged(&init_user_ns,
+ cred->fsgid));
+
+ fput(file);
+ if (nla_put_be32(skb, NFQA_UID, uid) ||
+ nla_put_be32(skb, NFQA_GID, gid))
+ goto nla_put_failure;
+ }
}
return 0;
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 nf 5/5] netfilter: nf_log_syslog: pin file with get_file_active before reading f_cred
2026-11-27 0:16 [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred Tristan Madani
` (3 preceding siblings ...)
2026-11-27 0:16 ` [PATCH v2 nf 4/5] netfilter: nfnetlink_queue: " Tristan Madani
@ 2026-11-27 0:16 ` Tristan Madani
4 siblings, 0 replies; 6+ messages in thread
From: Tristan Madani @ 2026-11-27 0:16 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, coreteam,
netfilter-devel, netdev, linux-kernel, stable, Tristan Madani
From: Tristan Madani <tristan@talencesecurity.com>
nf_log_dump_sk_uid_gid() reads 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_active() before accessing its credentials
and release with fput() afterwards.
Found by manual code inspection; not triggered at runtime.
Fixes: 0ede61d8589c ("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 | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c
index c3fd398ffcd77..dd15409100eba 100644
--- a/net/netfilter/nf_log_syslog.c
+++ b/net/netfilter/nf_log_syslog.c
@@ -6,6 +6,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>
+#include <linux/fs.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/skbuff.h>
@@ -168,25 +169,24 @@ 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.
- */
sock = READ_ONCE(sk->sk_socket);
- file = sock ? READ_ONCE(sock->file) : NULL;
- if (file) {
- const struct cred *cred = file->f_cred;
-
- 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));
+ if (sock) {
+ file = get_file_active(&sock->file);
+ if (file) {
+ uid_t uid = from_kuid_munged(&init_user_ns,
+ file->f_cred->fsuid);
+ gid_t gid = from_kgid_munged(&init_user_ns,
+ file->f_cred->fsgid);
+
+ fput(file);
+ nf_log_buf_add(m, "UID=%u GID=%u ", uid, gid);
+ }
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-27 0:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 0:16 [PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 1/5] netfilter: xt_owner: " Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 2/5] netfilter: nft_meta: " Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 3/5] netfilter: nfnetlink_log: " Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 4/5] netfilter: nfnetlink_queue: " Tristan Madani
2026-11-27 0:16 ` [PATCH v2 nf 5/5] netfilter: nf_log_syslog: " Tristan Madani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox