Skip to contentSkip to conversation

netfilter: x_tables: disable 32bit compat interface in user namespaces

PATCH In review Florian Westphal 2 participants 3 messages Apr 29

Subsystems (3)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: x_tables: disable 32bit compat interface in user namespaces

This feature is required to use 32bit arp/ip/ip6/ebtables binaries on 64bit kernels. I don't think there are many users left.

Support has been a compile-time option since 2021 and defaults to off since 2023.

The XTABLES_COMPAT config option is already off in many distributions including Debian and Fedora.

Give a few more months before complete removal but disable support in user namespaces already.

Assisted-by Claude Code:claude-sonnet-4-6

---
Alternatively this could be ripped out instantly, if thats preferred. This provides a mix, it would still allow such a system to work in init userns.

 include/linux/netfilter/x_tables.h | 17 +++++++++++++++++
 net/bridge/netfilter/ebtables.c    |  4 ++++
 net/ipv4/netfilter/arp_tables.c    |  4 ++++
 net/ipv4/netfilter/ip_tables.c     |  4 ++++
 net/ipv6/netfilter/ip6_tables.c    |  4 ++++
 5 files changed, 33 insertions(+)
include/linux/netfilter/x_tables.h +17 -0
index 77c778d84d4c..4c5b3eba5a6e 100644
@@ -524,4 +524,21 @@ int xt_compat_check_entry_offsets(const void *base, const char *elems,
 				  unsigned int next_offset);
 
 #endif /* CONFIG_NETFILTER_XTABLES_COMPAT */
+
+static inline bool xt_compat_check(void)
+{
+#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
+	if (!in_compat_syscall())
+		return true;
+
+	pr_warn_once("%s %s\n",
+		     "xtables 32bit compat interface no longer supported",
+		     "in namespaces and will be removed soon.");
+
+	if (!capable(CAP_NET_ADMIN))
+		return false;
+#endif
+	return true;
+}
+
 #endif /* _X_TABLES_H */
net/bridge/netfilter/ebtables.c +4 -0
index aea3e19875c6..92461c7e1e18 100644
@@ -2449,6 +2449,8 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
 	struct ebt_table *t;
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
@@ -2514,6 +2516,8 @@ static int do_ebt_set_ctl(struct sock *sk, int cmd, sockptr_t arg,
 	struct net *net = sock_net(sk);
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
net/ipv4/netfilter/arp_tables.c +4 -0
index 1cdd9c28ab2d..acb346731d89 100644
@@ -1416,6 +1416,8 @@ static int do_arpt_set_ctl(struct sock *sk, int cmd, sockptr_t arg,
 {
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
@@ -1444,6 +1446,8 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
 {
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
net/ipv4/netfilter/ip_tables.c +4 -0
index 23c8deff8095..e34647da90e9 100644
@@ -1622,6 +1622,8 @@ do_ipt_set_ctl(struct sock *sk, int cmd, sockptr_t arg, unsigned int len)
 {
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
@@ -1651,6 +1653,8 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
 {
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
net/ipv6/netfilter/ip6_tables.c +4 -0
index d585ac3c1113..0c037f025210 100644
@@ -1631,6 +1631,8 @@ do_ip6t_set_ctl(struct sock *sk, int cmd, sockptr_t arg, unsigned int len)
 {
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
@@ -1660,6 +1662,8 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
 {
 	int ret;
 
+	if (!xt_compat_check())
+		return -EPERM;
 	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
 		return -EPERM;
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 2 lines · Florian Westphal

This feature is required to use 32bit arp/ip/ip6/ebtables binaries on 64bit kernels. I don't think there are many users left.

This breaks the setup in a Debian x32 systemd-nspawn container with xtables-legacy-multi.

author maintainer
#2 lore raw
Quoted 5 lines · Jan Engelhardt
Quoted 2 lines

This feature is required to use 32bit arp/ip/ip6/ebtables binaries on 64bit kernels. I don't think there are many users left.

This breaks the setup in a Debian x32 systemd-nspawn container with xtables-legacy-multi.

Thats the intent.