From: Fernando Fernandez Mancera <fman…@suse.de>
Packets generated at synproxy_send_tcp() and synproxy_send_tcp_ipv6()
are handled by ip_local_out() and ip6_local_out) which traverse
LOCAL_OUT and POST_ROUTING. As SYNPROXY hooks are registered on
POST_ROUTING, a payload mangling rule at OUTPUT with priority raw can
rewrite the generated ACK to SYN|ACK before conntrack sees it.
This leaves the conntrack state in SYN_RECV state and synproxy sends two
more ACKs repeating the cycle until the IRQ stack guard page is hit:
BUG: IRQ stack guard page was hit
Oops: stack guard page: 0000 [#1] SMP NOPTI
synproxy_send_tcp
ipv4_synproxy_hook
nf_hook_slow
ip_output
ipv4_synproxy_hook
...
Fix this by applying the per-CPU xmit recursion limit. Note that this
cannot be triggered with iptables as it is not possible to modify the
TCP flags from raw priority.
Fixes: ad49d86e07a4 ("netfilter: nf_tables: Add synproxy support")
Signed-off-by: Fernando Fernandez Mancera <fman…@suse.de>
Signed-off-by: Pablo Neira Ayuso <pab…@netfilter.org>
---
net/netfilter/nf_synproxy_core.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index 401ce5a13f3f..9dd681596c70 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -21,6 +21,7 @@
#include <net/netfilter/nf_conntrack_synproxy.h>
#include <net/netfilter/nf_conntrack_zones.h>
#include <net/netfilter/nf_synproxy.h>
+#include <net/netfilter/nf_recursion.h>
static DEFINE_MUTEX(synproxy_mutex);
@@ -439,7 +440,16 @@ synproxy_send_tcp(struct net *net,
nf_conntrack_get(nfct);
}
+ local_bh_disable();
+ if (nf_dev_xmit_recursion()) {
+ local_bh_enable();
+ goto free_nskb;
+ }
+
+ nf_dev_xmit_recursion_inc();
ip_local_out(net, nskb->sk, nskb);
+ nf_dev_xmit_recursion_dec();
+ local_bh_enable();
return;
free_nskb:
@@ -858,7 +868,16 @@ synproxy_send_tcp_ipv6(struct net *net,
nf_conntrack_get(nfct);
}
+ local_bh_disable();
+ if (nf_dev_xmit_recursion()) {
+ local_bh_enable();
+ goto free_nskb;
+ }
+
+ nf_dev_xmit_recursion_inc();
ip6_local_out(net, nskb->sk, nskb);
+ nf_dev_xmit_recursion_dec();
+ local_bh_enable();
return;
free_nskb:
--
2.47.3