Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Tristan Madani
Fri, 27 Nov 2026 00:16
[PATCH v2 nf 1/5] netfilter: xt_owner: 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
93 lines
14013 bytes
14013 bytes
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
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