Skip to contentSkip to conversation

ebtables dnat rule gets system frozen

PATCH Applied Tom Yan 3 participants 4 messages Nov 3, 2019 – Nov 4, 2019

Subsystems (3)
lore
Share & tools
lore

Tom Yan

author
#0 lore raw

Kernel version being 5.3.8, after adding a dnat rule (to the OUTPUT chain) with ebtables-nft in iptables 1.8.3, my system is frozen as soon as I ping anything. I couldn't catch anything with dmesg -w. Can anyone reproduce the same issue? I am on Arch Linux.

maintainer
#1 lore raw
Quoted 4 lines · Tom Yan

Kernel version being 5.3.8, after adding a dnat rule (to the OUTPUT chain) with ebtables-nft in iptables 1.8.3, my system is frozen as soon as I ping anything. I couldn't catch anything with dmesg -w. Can anyone reproduce the same issue? I am on Arch Linux.

Yes, investigating.

maintainer
#2 lore raw

PATCH 1/1 bridge: ebtables: don't crash when using dnat target in output chains

In reply to Tom Yan

xt_in() returns NULL in the output hook, skip the pkt_type change for that case, redirection only makes sense in broute/prerouting hooks.

Cc Linus Lüssing <[email protected]>
Fixes cf3cb246e277d ("bridge: ebtables: fix reception of frames DNAT-ed to bridge device/port")
---
 net/bridge/netfilter/ebt_dnat.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
net/bridge/netfilter/ebt_dnat.c +15 -4
index ed91ea31978a..12a4f4d93681 100644
@@ -20,7 +20,6 @@ static unsigned int
 ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par)
 {
 	const struct ebt_nat_info *info = par->targinfo;
-	struct net_device *dev;
 
 	if (skb_ensure_writable(skb, ETH_ALEN))
 		return EBT_DROP;
@@ -33,10 +32,22 @@ ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par)
 		else
 			skb->pkt_type = PACKET_MULTICAST;
 	} else {
-		if (xt_hooknum(par) != NF_BR_BROUTING)
-			dev = br_port_get_rcu(xt_in(par))->br->dev;
-		else
+		const struct net_device *dev;
+
+		switch (xt_hooknum(par)) {
+		case NF_BR_BROUTING:
 			dev = xt_in(par);
+			break;
+		case NF_BR_PRE_ROUTING:
+			dev = br_port_get_rcu(xt_in(par))->br->dev;
+			break;
+		default:
+			dev = NULL;
+			break;
+		}
+
+		if (!dev) /* NF_BR_LOCAL_OUT */
+			return info->target;
 
 		if (ether_addr_equal(info->mac, dev->dev_addr))
 			skb->pkt_type = PACKET_HOST;
Signature · 1 line
2.23.0
maintainer Applied
#3 lore raw

Re: [PATCH nf] bridge: ebtables: don't crash when using dnat target in output chains

Quoted 2 lines · Florian Westphal

xt_in() returns NULL in the output hook, skip the pkt_type change for that case, redirection only makes sense in broute/prerouting hooks.

Applied, thanks.