Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Tristan Madani
Fri, 27 Nov 2026 00:16
[PATCH v2 nf 0/5] netfilter: pin file with get_file_active before reading f_cred
Author: Tristan Madani
Date: Fri, 27 Nov 2026 00:16
Date: Fri, 27 Nov 2026 00:16
41 lines
12524 bytes
12524 bytes
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
[PATCH v2 nf 2/5] netfilter: nft_meta: pin file with get_file_active before reading f_cred
Author: Tristan Madani
Date: Fri, 27 Nov 2026 00:16
Date: Fri, 27 Nov 2026 00:16
68 lines
13109 bytes
13109 bytes
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
[PATCH v2 nf 3/5] netfilter: nfnetlink_log: pin file with get_file_active before reading f_cred
Author: Tristan Madani
Date: Fri, 27 Nov 2026 00:16
Date: Fri, 27 Nov 2026 00:16
76 lines
13703 bytes
13703 bytes
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
[PATCH v2 nf 4/5] netfilter: nfnetlink_queue: pin file with get_file_active before reading f_cred
Author: Tristan Madani
Date: Fri, 27 Nov 2026 00:16
Date: Fri, 27 Nov 2026 00:16
80 lines
13688 bytes
13688 bytes
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
[PATCH v2 nf 5/5] netfilter: nf_log_syslog: pin file with get_file_active before reading f_cred
Author: Tristan Madani
Date: Fri, 27 Nov 2026 00:16
Date: Fri, 27 Nov 2026 00:16
73 lines
13468 bytes
13468 bytes
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
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