* [PATCH net 0/4] netfilter: bug fixes for net
@ 2022-09-01 7:12 Florian Westphal
2022-09-01 7:12 ` [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles Florian Westphal
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Florian Westphal @ 2022-09-01 7:12 UTC (permalink / raw)
To: netdev; +Cc: davem, netfilter-devel, kuba, pabeni, edumazet, Florian Westphal
Hello,
This patchset contains netfilter related fixes for the net tree.
1. Fix IP address check in irc DCC conntrack helper, this should check
the opposite direction rather than the destination address of the
packets' direction, from David Leadbeater.
2. bridge netfilter needs to drop dst references, from Harsh Modi.
This was fine back in the day the code was originally written,
but nowadays various tunnels can pre-set metadata dsts on packets.
3. Remove nf_conntrack_helper sysctl and the modparam toggle, users
need to explicitily assign the helpers to use via nftables or
iptables. Conntrack helpers, by design, may be used to add dynamic
port redirections to internal machines, so its necessary to restrict
which hosts/peers are allowed to use them.
The auto-assign-for-everything mechanism has been in "please don't do this"
territory since 2012. From Pablo.
4. Fix a memory leak in the netdev hook error unwind path, also from Pablo.
----------------------------------------------------------------
The following changes since commit 13a9d08c296228d18289de60b83792c586e1d073:
net: lan966x: improve error handle in lan966x_fdma_rx_get_frame() (2022-08-30 23:18:17 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git
for you to fetch changes up to 0efe125cfb99e6773a7434f3463f7c2fa28f3a43:
netfilter: nf_conntrack_irc: Fix forged IP logic (2022-09-01 02:01:56 +0200)
----------------------------------------------------------------
David Leadbeater (1):
netfilter: nf_conntrack_irc: Fix forged IP logic
Harsh Modi (1):
netfilter: br_netfilter: Drop dst references before setting.
Pablo Neira Ayuso (2):
netfilter: remove nf_conntrack_helper sysctl and modparam toggles
netfilter: nf_tables: clean up hook list when offload flags check fails
include/net/netfilter/nf_conntrack.h | 2 -
include/net/netns/conntrack.h | 1 -
net/bridge/br_netfilter_hooks.c | 2 +
net/bridge/br_netfilter_ipv6.c | 1 +
net/netfilter/nf_conntrack_core.c | 7 +-
net/netfilter/nf_conntrack_helper.c | 80 +++-------------------
net/netfilter/nf_conntrack_irc.c | 5 +-
net/netfilter/nf_conntrack_netlink.c | 5 --
net/netfilter/nf_conntrack_standalone.c | 10 ---
net/netfilter/nf_tables_api.c | 4 +-
net/netfilter/nft_ct.c | 3 -
.../selftests/netfilter/nft_conntrack_helper.sh | 36 +++++++---
12 files changed, 46 insertions(+), 110 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles
2022-09-01 7:12 [PATCH net 0/4] netfilter: bug fixes for net Florian Westphal
@ 2022-09-01 7:12 ` Florian Westphal
2022-09-02 4:07 ` Jakub Kicinski
2022-09-03 4:20 ` patchwork-bot+netdevbpf
2022-09-01 7:12 ` [PATCH net 2/4] netfilter: br_netfilter: Drop dst references before setting Florian Westphal
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: Florian Westphal @ 2022-09-01 7:12 UTC (permalink / raw)
To: netdev
Cc: davem, netfilter-devel, kuba, pabeni, edumazet,
Pablo Neira Ayuso, Aaron Conole
From: Pablo Neira Ayuso <pablo@netfilter.org>
__nf_ct_try_assign_helper() remains in place but it now requires a
template to configure the helper.
A toggle to disable automatic helper assignment was added by:
a9006892643a ("netfilter: nf_ct_helper: allow to disable automatic helper assignment")
in 2012 to address the issues described in "Secure use of iptables and
connection tracking helpers". Automatic conntrack helper assignment was
disabled by:
3bb398d925ec ("netfilter: nf_ct_helper: disable automatic helper assignment")
back in 2016.
This patch removes the sysctl and modparam toggles, users now have to
rely on explicit conntrack helper configuration via ruleset.
Update tools/testing/selftests/netfilter/nft_conntrack_helper.sh to
check that auto-assignment does not happen anymore.
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_conntrack.h | 2 -
include/net/netns/conntrack.h | 1 -
net/netfilter/nf_conntrack_core.c | 7 +-
net/netfilter/nf_conntrack_helper.c | 80 +++----------------
net/netfilter/nf_conntrack_netlink.c | 5 --
net/netfilter/nf_conntrack_standalone.c | 10 ---
net/netfilter/nft_ct.c | 3 -
.../netfilter/nft_conntrack_helper.sh | 36 ++++++---
8 files changed, 37 insertions(+), 107 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index a32be8aa7ed2..6a2019aaa464 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -53,8 +53,6 @@ struct nf_conntrack_net {
/* only used when new connection is allocated: */
atomic_t count;
unsigned int expect_count;
- u8 sysctl_auto_assign_helper;
- bool auto_assign_helper_warned;
/* only used from work queues, configuration plane, and so on: */
unsigned int users4;
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
index c396a3862e80..e1290c159184 100644
--- a/include/net/netns/conntrack.h
+++ b/include/net/netns/conntrack.h
@@ -101,7 +101,6 @@ struct netns_ct {
u8 sysctl_log_invalid; /* Log invalid packets */
u8 sysctl_events;
u8 sysctl_acct;
- u8 sysctl_auto_assign_helper;
u8 sysctl_tstamp;
u8 sysctl_checksum;
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 71c2f4f95d36..1357a2729a4b 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1782,7 +1782,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
}
spin_unlock_bh(&nf_conntrack_expect_lock);
}
- if (!exp)
+ if (!exp && tmpl)
__nf_ct_try_assign_helper(ct, tmpl, GFP_ATOMIC);
/* Other CPU might have obtained a pointer to this object before it was
@@ -2068,10 +2068,6 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
ct->tuplehash[IP_CT_DIR_REPLY].tuple = *newreply;
if (ct->master || (help && !hlist_empty(&help->expectations)))
return;
-
- rcu_read_lock();
- __nf_ct_try_assign_helper(ct, NULL, GFP_ATOMIC);
- rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);
@@ -2797,7 +2793,6 @@ int nf_conntrack_init_net(struct net *net)
nf_conntrack_acct_pernet_init(net);
nf_conntrack_tstamp_pernet_init(net);
nf_conntrack_ecache_pernet_init(net);
- nf_conntrack_helper_pernet_init(net);
nf_conntrack_proto_pernet_init(net);
return 0;
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index e96b32221444..ff737a76052e 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -35,11 +35,6 @@ unsigned int nf_ct_helper_hsize __read_mostly;
EXPORT_SYMBOL_GPL(nf_ct_helper_hsize);
static unsigned int nf_ct_helper_count __read_mostly;
-static bool nf_ct_auto_assign_helper __read_mostly = false;
-module_param_named(nf_conntrack_helper, nf_ct_auto_assign_helper, bool, 0644);
-MODULE_PARM_DESC(nf_conntrack_helper,
- "Enable automatic conntrack helper assignment (default 0)");
-
static DEFINE_MUTEX(nf_ct_nat_helpers_mutex);
static struct list_head nf_ct_nat_helpers __read_mostly;
@@ -51,24 +46,6 @@ static unsigned int helper_hash(const struct nf_conntrack_tuple *tuple)
(__force __u16)tuple->src.u.all) % nf_ct_helper_hsize;
}
-static struct nf_conntrack_helper *
-__nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
-{
- struct nf_conntrack_helper *helper;
- struct nf_conntrack_tuple_mask mask = { .src.u.all = htons(0xFFFF) };
- unsigned int h;
-
- if (!nf_ct_helper_count)
- return NULL;
-
- h = helper_hash(tuple);
- hlist_for_each_entry_rcu(helper, &nf_ct_helper_hash[h], hnode) {
- if (nf_ct_tuple_src_mask_cmp(tuple, &helper->tuple, &mask))
- return helper;
- }
- return NULL;
-}
-
struct nf_conntrack_helper *
__nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum)
{
@@ -209,33 +186,11 @@ nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
}
EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);
-static struct nf_conntrack_helper *
-nf_ct_lookup_helper(struct nf_conn *ct, struct net *net)
-{
- struct nf_conntrack_net *cnet = nf_ct_pernet(net);
-
- if (!cnet->sysctl_auto_assign_helper) {
- if (cnet->auto_assign_helper_warned)
- return NULL;
- if (!__nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple))
- return NULL;
- pr_info("nf_conntrack: default automatic helper assignment "
- "has been turned off for security reasons and CT-based "
- "firewall rule not found. Use the iptables CT target "
- "to attach helpers instead.\n");
- cnet->auto_assign_helper_warned = true;
- return NULL;
- }
-
- return __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
-}
-
int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
gfp_t flags)
{
struct nf_conntrack_helper *helper = NULL;
struct nf_conn_help *help;
- struct net *net = nf_ct_net(ct);
/* We already got a helper explicitly attached. The function
* nf_conntrack_alter_reply - in case NAT is in use - asks for looking
@@ -246,23 +201,21 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
if (test_bit(IPS_HELPER_BIT, &ct->status))
return 0;
- if (tmpl != NULL) {
- help = nfct_help(tmpl);
- if (help != NULL) {
- helper = rcu_dereference(help->helper);
- set_bit(IPS_HELPER_BIT, &ct->status);
- }
+ if (WARN_ON_ONCE(!tmpl))
+ return 0;
+
+ help = nfct_help(tmpl);
+ if (help != NULL) {
+ helper = rcu_dereference(help->helper);
+ set_bit(IPS_HELPER_BIT, &ct->status);
}
help = nfct_help(ct);
if (helper == NULL) {
- helper = nf_ct_lookup_helper(ct, net);
- if (helper == NULL) {
- if (help)
- RCU_INIT_POINTER(help->helper, NULL);
- return 0;
- }
+ if (help)
+ RCU_INIT_POINTER(help->helper, NULL);
+ return 0;
}
if (help == NULL) {
@@ -545,19 +498,6 @@ void nf_nat_helper_unregister(struct nf_conntrack_nat_helper *nat)
}
EXPORT_SYMBOL_GPL(nf_nat_helper_unregister);
-void nf_ct_set_auto_assign_helper_warned(struct net *net)
-{
- nf_ct_pernet(net)->auto_assign_helper_warned = true;
-}
-EXPORT_SYMBOL_GPL(nf_ct_set_auto_assign_helper_warned);
-
-void nf_conntrack_helper_pernet_init(struct net *net)
-{
- struct nf_conntrack_net *cnet = nf_ct_pernet(net);
-
- cnet->sysctl_auto_assign_helper = nf_ct_auto_assign_helper;
-}
-
int nf_conntrack_helper_init(void)
{
nf_ct_helper_hsize = 1; /* gets rounded up to use one page */
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 04169b54f2a2..7562b215b932 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -2298,11 +2298,6 @@ ctnetlink_create_conntrack(struct net *net,
ct->status |= IPS_HELPER;
RCU_INIT_POINTER(help->helper, helper);
}
- } else {
- /* try an implicit helper assignation */
- err = __nf_ct_try_assign_helper(ct, NULL, GFP_ATOMIC);
- if (err < 0)
- goto err2;
}
err = ctnetlink_setup_nat(ct, cda);
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 05895878610c..4ffe84c5a82c 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -561,7 +561,6 @@ enum nf_ct_sysctl_index {
NF_SYSCTL_CT_LOG_INVALID,
NF_SYSCTL_CT_EXPECT_MAX,
NF_SYSCTL_CT_ACCT,
- NF_SYSCTL_CT_HELPER,
#ifdef CONFIG_NF_CONNTRACK_EVENTS
NF_SYSCTL_CT_EVENTS,
#endif
@@ -680,14 +679,6 @@ static struct ctl_table nf_ct_sysctl_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
- [NF_SYSCTL_CT_HELPER] = {
- .procname = "nf_conntrack_helper",
- .maxlen = sizeof(u8),
- .mode = 0644,
- .proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
- },
#ifdef CONFIG_NF_CONNTRACK_EVENTS
[NF_SYSCTL_CT_EVENTS] = {
.procname = "nf_conntrack_events",
@@ -1100,7 +1091,6 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
table[NF_SYSCTL_CT_CHECKSUM].data = &net->ct.sysctl_checksum;
table[NF_SYSCTL_CT_LOG_INVALID].data = &net->ct.sysctl_log_invalid;
table[NF_SYSCTL_CT_ACCT].data = &net->ct.sysctl_acct;
- table[NF_SYSCTL_CT_HELPER].data = &cnet->sysctl_auto_assign_helper;
#ifdef CONFIG_NF_CONNTRACK_EVENTS
table[NF_SYSCTL_CT_EVENTS].data = &net->ct.sysctl_events;
#endif
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index b04995c3e17f..a3f01f209a53 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -1089,9 +1089,6 @@ static int nft_ct_helper_obj_init(const struct nft_ctx *ctx,
if (err < 0)
goto err_put_helper;
- /* Avoid the bogus warning, helper will be assigned after CT init */
- nf_ct_set_auto_assign_helper_warned(ctx->net);
-
return 0;
err_put_helper:
diff --git a/tools/testing/selftests/netfilter/nft_conntrack_helper.sh b/tools/testing/selftests/netfilter/nft_conntrack_helper.sh
index bf6b9626c7dd..faa7778d7bd1 100755
--- a/tools/testing/selftests/netfilter/nft_conntrack_helper.sh
+++ b/tools/testing/selftests/netfilter/nft_conntrack_helper.sh
@@ -102,26 +102,42 @@ check_for_helper()
ip netns exec ${netns} conntrack -L -f $family -p tcp --dport $port 2> /dev/null |grep -q 'helper=ftp'
if [ $? -ne 0 ] ; then
- echo "FAIL: ${netns} did not show attached helper $message" 1>&2
- ret=1
+ if [ $autoassign -eq 0 ] ;then
+ echo "FAIL: ${netns} did not show attached helper $message" 1>&2
+ ret=1
+ else
+ echo "PASS: ${netns} did not show attached helper $message" 1>&2
+ fi
+ else
+ if [ $autoassign -eq 0 ] ;then
+ echo "PASS: ${netns} connection on port $port has ftp helper attached" 1>&2
+ else
+ echo "FAIL: ${netns} connection on port $port has ftp helper attached" 1>&2
+ ret=1
+ fi
fi
- echo "PASS: ${netns} connection on port $port has ftp helper attached" 1>&2
return 0
}
test_helper()
{
local port=$1
- local msg=$2
+ local autoassign=$2
+
+ if [ $autoassign -eq 0 ] ;then
+ msg="set via ruleset"
+ else
+ msg="auto-assign"
+ fi
sleep 3 | ip netns exec ${ns2} nc -w 2 -l -p $port > /dev/null &
sleep 1 | ip netns exec ${ns1} nc -w 2 10.0.1.2 $port > /dev/null &
sleep 1
- check_for_helper "$ns1" "ip $msg" $port
- check_for_helper "$ns2" "ip $msg" $port
+ check_for_helper "$ns1" "ip $msg" $port $autoassign
+ check_for_helper "$ns2" "ip $msg" $port $autoassign
wait
@@ -173,9 +189,9 @@ if [ $? -ne 0 ];then
fi
fi
-test_helper 2121 "set via ruleset"
-ip netns exec ${ns1} sysctl -q 'net.netfilter.nf_conntrack_helper=1'
-ip netns exec ${ns2} sysctl -q 'net.netfilter.nf_conntrack_helper=1'
-test_helper 21 "auto-assign"
+test_helper 2121 0
+ip netns exec ${ns1} sysctl -qe 'net.netfilter.nf_conntrack_helper=1'
+ip netns exec ${ns2} sysctl -qe 'net.netfilter.nf_conntrack_helper=1'
+test_helper 21 1
exit $ret
--
2.35.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net 2/4] netfilter: br_netfilter: Drop dst references before setting.
2022-09-01 7:12 [PATCH net 0/4] netfilter: bug fixes for net Florian Westphal
2022-09-01 7:12 ` [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles Florian Westphal
@ 2022-09-01 7:12 ` Florian Westphal
2022-09-01 7:12 ` [PATCH net 3/4] netfilter: nf_tables: clean up hook list when offload flags check fails Florian Westphal
2022-09-01 7:12 ` [PATCH net 4/4] netfilter: nf_conntrack_irc: Fix forged IP logic Florian Westphal
3 siblings, 0 replies; 9+ messages in thread
From: Florian Westphal @ 2022-09-01 7:12 UTC (permalink / raw)
To: netdev
Cc: davem, netfilter-devel, kuba, pabeni, edumazet, Harsh Modi,
Florian Westphal, Pablo Neira Ayuso
From: Harsh Modi <harshmodi@google.com>
The IPv6 path already drops dst in the daddr changed case, but the IPv4
path does not. This change makes the two code paths consistent.
Further, it is possible that there is already a metadata_dst allocated from
ingress that might already be attached to skbuff->dst while following
the bridge path. If it is not released before setting a new
metadata_dst, it will be leaked. This is similar to what is done in
bpf_set_tunnel_key() or ip6_route_input().
It is important to note that the memory being leaked is not the dst
being set in the bridge code, but rather memory allocated from some
other code path that is not being freed correctly before the skb dst is
overwritten.
An example of the leakage fixed by this commit found using kmemleak:
unreferenced object 0xffff888010112b00 (size 256):
comm "softirq", pid 0, jiffies 4294762496 (age 32.012s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 80 16 f1 83 ff ff ff ff ................
e1 4e f6 82 ff ff ff ff 00 00 00 00 00 00 00 00 .N..............
backtrace:
[<00000000d79567ea>] metadata_dst_alloc+0x1b/0xe0
[<00000000be113e13>] udp_tun_rx_dst+0x174/0x1f0
[<00000000a36848f4>] geneve_udp_encap_recv+0x350/0x7b0
[<00000000d4afb476>] udp_queue_rcv_one_skb+0x380/0x560
[<00000000ac064aea>] udp_unicast_rcv_skb+0x75/0x90
[<000000009a8ee8c5>] ip_protocol_deliver_rcu+0xd8/0x230
[<00000000ef4980bb>] ip_local_deliver_finish+0x7a/0xa0
[<00000000d7533c8c>] __netif_receive_skb_one_core+0x89/0xa0
[<00000000a879497d>] process_backlog+0x93/0x190
[<00000000e41ade9f>] __napi_poll+0x28/0x170
[<00000000b4c0906b>] net_rx_action+0x14f/0x2a0
[<00000000b20dd5d4>] __do_softirq+0xf4/0x305
[<000000003a7d7e15>] __irq_exit_rcu+0xc3/0x140
[<00000000968d39a2>] sysvec_apic_timer_interrupt+0x9e/0xc0
[<000000009e920794>] asm_sysvec_apic_timer_interrupt+0x16/0x20
[<000000008942add0>] native_safe_halt+0x13/0x20
Florian Westphal says: "Original code was likely fine because nothing
ever did set a skb->dst entry earlier than bridge in those days."
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Harsh Modi <harshmodi@google.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/bridge/br_netfilter_hooks.c | 2 ++
net/bridge/br_netfilter_ipv6.c | 1 +
2 files changed, 3 insertions(+)
diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index ff4779036649..f20f4373ff40 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -384,6 +384,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
/* - Bridged-and-DNAT'ed traffic doesn't
* require ip_forwarding. */
if (rt->dst.dev == dev) {
+ skb_dst_drop(skb);
skb_dst_set(skb, &rt->dst);
goto bridged_dnat;
}
@@ -413,6 +414,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
kfree_skb(skb);
return 0;
}
+ skb_dst_drop(skb);
skb_dst_set_noref(skb, &rt->dst);
}
diff --git a/net/bridge/br_netfilter_ipv6.c b/net/bridge/br_netfilter_ipv6.c
index e4e0c836c3f5..6b07f30675bb 100644
--- a/net/bridge/br_netfilter_ipv6.c
+++ b/net/bridge/br_netfilter_ipv6.c
@@ -197,6 +197,7 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, struc
kfree_skb(skb);
return 0;
}
+ skb_dst_drop(skb);
skb_dst_set_noref(skb, &rt->dst);
}
--
2.35.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net 3/4] netfilter: nf_tables: clean up hook list when offload flags check fails
2022-09-01 7:12 [PATCH net 0/4] netfilter: bug fixes for net Florian Westphal
2022-09-01 7:12 ` [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles Florian Westphal
2022-09-01 7:12 ` [PATCH net 2/4] netfilter: br_netfilter: Drop dst references before setting Florian Westphal
@ 2022-09-01 7:12 ` Florian Westphal
2022-09-01 7:12 ` [PATCH net 4/4] netfilter: nf_conntrack_irc: Fix forged IP logic Florian Westphal
3 siblings, 0 replies; 9+ messages in thread
From: Florian Westphal @ 2022-09-01 7:12 UTC (permalink / raw)
To: netdev
Cc: davem, netfilter-devel, kuba, pabeni, edumazet,
Pablo Neira Ayuso, syzbot+5fcdbfab6d6744c57418
From: Pablo Neira Ayuso <pablo@netfilter.org>
splice back the hook list so nft_chain_release_hook() has a chance to
release the hooks.
BUG: memory leak
unreferenced object 0xffff88810180b100 (size 96):
comm "syz-executor133", pid 3619, jiffies 4294945714 (age 12.690s)
hex dump (first 32 bytes):
28 64 23 02 81 88 ff ff 28 64 23 02 81 88 ff ff (d#.....(d#.....
90 a8 aa 83 ff ff ff ff 00 00 b5 0f 81 88 ff ff ................
backtrace:
[<ffffffff83a8c59b>] kmalloc include/linux/slab.h:600 [inline]
[<ffffffff83a8c59b>] nft_netdev_hook_alloc+0x3b/0xc0 net/netfilter/nf_tables_api.c:1901
[<ffffffff83a9239a>] nft_chain_parse_netdev net/netfilter/nf_tables_api.c:1998 [inline]
[<ffffffff83a9239a>] nft_chain_parse_hook+0x33a/0x530 net/netfilter/nf_tables_api.c:2073
[<ffffffff83a9b14b>] nf_tables_addchain.constprop.0+0x10b/0x950 net/netfilter/nf_tables_api.c:2218
[<ffffffff83a9c41b>] nf_tables_newchain+0xa8b/0xc60 net/netfilter/nf_tables_api.c:2593
[<ffffffff83a3d6a6>] nfnetlink_rcv_batch+0xa46/0xd20 net/netfilter/nfnetlink.c:517
[<ffffffff83a3db79>] nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:638 [inline]
[<ffffffff83a3db79>] nfnetlink_rcv+0x1f9/0x220 net/netfilter/nfnetlink.c:656
[<ffffffff83a13b17>] netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
[<ffffffff83a13b17>] netlink_unicast+0x397/0x4c0 net/netlink/af_netlink.c:1345
[<ffffffff83a13fd6>] netlink_sendmsg+0x396/0x710 net/netlink/af_netlink.c:1921
[<ffffffff83865ab6>] sock_sendmsg_nosec net/socket.c:714 [inline]
[<ffffffff83865ab6>] sock_sendmsg+0x56/0x80 net/socket.c:734
[<ffffffff8386601c>] ____sys_sendmsg+0x36c/0x390 net/socket.c:2482
[<ffffffff8386a918>] ___sys_sendmsg+0xa8/0x110 net/socket.c:2536
[<ffffffff8386aaa8>] __sys_sendmsg+0x88/0x100 net/socket.c:2565
[<ffffffff845e5955>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
[<ffffffff845e5955>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
[<ffffffff84800087>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
Fixes: d54725cd11a5 ("netfilter: nf_tables: support for multiple devices per netdev hook")
Reported-by: syzbot+5fcdbfab6d6744c57418@syzkaller.appspotmail.com
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 2ee50e23c9b7..816052089b33 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2166,8 +2166,10 @@ static int nft_basechain_init(struct nft_base_chain *basechain, u8 family,
chain->flags |= NFT_CHAIN_BASE | flags;
basechain->policy = NF_ACCEPT;
if (chain->flags & NFT_CHAIN_HW_OFFLOAD &&
- !nft_chain_offload_support(basechain))
+ !nft_chain_offload_support(basechain)) {
+ list_splice_init(&basechain->hook_list, &hook->list);
return -EOPNOTSUPP;
+ }
flow_block_init(&basechain->flow_block);
--
2.35.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net 4/4] netfilter: nf_conntrack_irc: Fix forged IP logic
2022-09-01 7:12 [PATCH net 0/4] netfilter: bug fixes for net Florian Westphal
` (2 preceding siblings ...)
2022-09-01 7:12 ` [PATCH net 3/4] netfilter: nf_tables: clean up hook list when offload flags check fails Florian Westphal
@ 2022-09-01 7:12 ` Florian Westphal
3 siblings, 0 replies; 9+ messages in thread
From: Florian Westphal @ 2022-09-01 7:12 UTC (permalink / raw)
To: netdev
Cc: davem, netfilter-devel, kuba, pabeni, edumazet, David Leadbeater,
Pablo Neira Ayuso
From: David Leadbeater <dgl@dgl.cx>
Ensure the match happens in the right direction, previously the
destination used was the server, not the NAT host, as the comment
shows the code intended.
Additionally nf_nat_irc uses port 0 as a signal and there's no valid way
it can appear in a DCC message, so consider port 0 also forged.
Fixes: 869f37d8e48f ("[NETFILTER]: nf_conntrack/nf_nat: add IRC helper port")
Signed-off-by: David Leadbeater <dgl@dgl.cx>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_irc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c
index 1796c456ac98..992decbcaa5c 100644
--- a/net/netfilter/nf_conntrack_irc.c
+++ b/net/netfilter/nf_conntrack_irc.c
@@ -194,8 +194,9 @@ static int help(struct sk_buff *skb, unsigned int protoff,
/* dcc_ip can be the internal OR external (NAT'ed) IP */
tuple = &ct->tuplehash[dir].tuple;
- if (tuple->src.u3.ip != dcc_ip &&
- tuple->dst.u3.ip != dcc_ip) {
+ if ((tuple->src.u3.ip != dcc_ip &&
+ ct->tuplehash[!dir].tuple.dst.u3.ip != dcc_ip) ||
+ dcc_port == 0) {
net_warn_ratelimited("Forged DCC command from %pI4: %pI4:%u\n",
&tuple->src.u3.ip,
&dcc_ip, dcc_port);
--
2.35.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles
2022-09-01 7:12 ` [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles Florian Westphal
@ 2022-09-02 4:07 ` Jakub Kicinski
2022-09-02 5:39 ` Florian Westphal
2022-09-03 4:20 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2022-09-02 4:07 UTC (permalink / raw)
To: Florian Westphal
Cc: netdev, davem, netfilter-devel, pabeni, edumazet,
Pablo Neira Ayuso, Aaron Conole
On Thu, 1 Sep 2022 09:12:35 +0200 Florian Westphal wrote:
> From: Pablo Neira Ayuso <pablo@netfilter.org>
>
> __nf_ct_try_assign_helper() remains in place but it now requires a
> template to configure the helper.
>
> A toggle to disable automatic helper assignment was added by:
>
> a9006892643a ("netfilter: nf_ct_helper: allow to disable automatic helper assignment")
>
> in 2012 to address the issues described in "Secure use of iptables and
> connection tracking helpers". Automatic conntrack helper assignment was
> disabled by:
>
> 3bb398d925ec ("netfilter: nf_ct_helper: disable automatic helper assignment")
>
> back in 2016.
>
> This patch removes the sysctl and modparam toggles, users now have to
> rely on explicit conntrack helper configuration via ruleset.
>
> Update tools/testing/selftests/netfilter/nft_conntrack_helper.sh to
> check that auto-assignment does not happen anymore.
From the description itself it's unclear why this is a part of a net PR.
Could you elucidate?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles
2022-09-02 4:07 ` Jakub Kicinski
@ 2022-09-02 5:39 ` Florian Westphal
2022-09-03 2:43 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Florian Westphal @ 2022-09-02 5:39 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Florian Westphal, netdev, davem, netfilter-devel, pabeni,
edumazet, Pablo Neira Ayuso, Aaron Conole
Jakub Kicinski <kuba@kernel.org> wrote:
> On Thu, 1 Sep 2022 09:12:35 +0200 Florian Westphal wrote:
> > From: Pablo Neira Ayuso <pablo@netfilter.org>
> >
> > __nf_ct_try_assign_helper() remains in place but it now requires a
> > template to configure the helper.
> >
> > A toggle to disable automatic helper assignment was added by:
> >
> > a9006892643a ("netfilter: nf_ct_helper: allow to disable automatic helper assignment")
> >
> > in 2012 to address the issues described in "Secure use of iptables and
> > connection tracking helpers". Automatic conntrack helper assignment was
> > disabled by:
> >
> > 3bb398d925ec ("netfilter: nf_ct_helper: disable automatic helper assignment")
> >
> > back in 2016.
> >
> > This patch removes the sysctl and modparam toggles, users now have to
> > rely on explicit conntrack helper configuration via ruleset.
> >
> > Update tools/testing/selftests/netfilter/nft_conntrack_helper.sh to
> > check that auto-assignment does not happen anymore.
>
> From the description itself it's unclear why this is a part of a net PR.
> Could you elucidate?
Yes, there is improper checking in the irc dcc helper, its possible to
trigger the 'please do dynamic port forward' from outside by embedding
a 'DCC' in a PING request; if the client echos that back a expectation/
port forward gets added.
A fix for this will come in the next net PR, however, one part of the
issue is that point-blank-autassign is problematic and that helpers
should only be enabled for addresses that need it.
If you like I can resend the PR with an updated cover letter, or resend
with the dcc helper fix included as well.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles
2022-09-02 5:39 ` Florian Westphal
@ 2022-09-03 2:43 ` Jakub Kicinski
0 siblings, 0 replies; 9+ messages in thread
From: Jakub Kicinski @ 2022-09-03 2:43 UTC (permalink / raw)
To: Florian Westphal
Cc: netdev, davem, netfilter-devel, pabeni, edumazet,
Pablo Neira Ayuso, Aaron Conole
On Fri, 2 Sep 2022 07:39:28 +0200 Florian Westphal wrote:
> > From the description itself it's unclear why this is a part of a net PR.
> > Could you elucidate?
>
> Yes, there is improper checking in the irc dcc helper, its possible to
> trigger the 'please do dynamic port forward' from outside by embedding
> a 'DCC' in a PING request; if the client echos that back a expectation/
> port forward gets added.
I see, thanks!
> A fix for this will come in the next net PR, however, one part of the
> issue is that point-blank-autassign is problematic and that helpers
> should only be enabled for addresses that need it.
>
> If you like I can resend the PR with an updated cover letter, or resend
> with the dcc helper fix included as well.
No need, I'll fold more of your explanation into the merge commit,
should be good enough.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles
2022-09-01 7:12 ` [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles Florian Westphal
2022-09-02 4:07 ` Jakub Kicinski
@ 2022-09-03 4:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-03 4:20 UTC (permalink / raw)
To: Florian Westphal
Cc: netdev, davem, netfilter-devel, kuba, pabeni, edumazet, pablo, aconole
Hello:
This series was applied to netdev/net.git (master)
by Pablo Neira Ayuso <pablo@netfilter.org>:
On Thu, 1 Sep 2022 09:12:35 +0200 you wrote:
> From: Pablo Neira Ayuso <pablo@netfilter.org>
>
> __nf_ct_try_assign_helper() remains in place but it now requires a
> template to configure the helper.
>
> A toggle to disable automatic helper assignment was added by:
>
> [...]
Here is the summary with links:
- [net,1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles
https://git.kernel.org/netdev/net/c/b118509076b3
- [net,2/4] netfilter: br_netfilter: Drop dst references before setting.
https://git.kernel.org/netdev/net/c/d047283a7034
- [net,3/4] netfilter: nf_tables: clean up hook list when offload flags check fails
https://git.kernel.org/netdev/net/c/77972a36ecc4
- [net,4/4] netfilter: nf_conntrack_irc: Fix forged IP logic
https://git.kernel.org/netdev/net/c/0efe125cfb99
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-09-03 4:20 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 7:12 [PATCH net 0/4] netfilter: bug fixes for net Florian Westphal
2022-09-01 7:12 ` [PATCH net 1/4] netfilter: remove nf_conntrack_helper sysctl and modparam toggles Florian Westphal
2022-09-02 4:07 ` Jakub Kicinski
2022-09-02 5:39 ` Florian Westphal
2022-09-03 2:43 ` Jakub Kicinski
2022-09-03 4:20 ` patchwork-bot+netdevbpf
2022-09-01 7:12 ` [PATCH net 2/4] netfilter: br_netfilter: Drop dst references before setting Florian Westphal
2022-09-01 7:12 ` [PATCH net 3/4] netfilter: nf_tables: clean up hook list when offload flags check fails Florian Westphal
2022-09-01 7:12 ` [PATCH net 4/4] netfilter: nf_conntrack_irc: Fix forged IP logic Florian Westphal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.