netfilter: arp_tables: fix IEEE1394 ARP payload mangling
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: arp_tables: fix IEEE1394 ARP payload mangling
sashiko.dev noticed that similar bug pattern exists in arpt_mangle:
"IEEE1394 ARP payloads omit the target hardware address, advancing arpptr by hln after the source IP address skips over the actual target IP address."
Apply similar fix: check dev->type. If we're asked to mangle what doesn't exist, drop the packet.
---
Collides with a inflight patch.
I'll rebase or discard depending on what netdev@ does.
net/ipv4/netfilter/arpt_mangle.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
net/ipv4/netfilter/arpt_mangle.c +22 -1
@@ -13,6 +13,7 @@ static unsigned int target(struct sk_buff *skb, const struct xt_action_param *par) { const struct arpt_mangle *mangle = par->targinfo; +bool has_tgt_devaddr = true;const struct arphdr *arp;unsigned char *arpptr;int pln, hln;
@@ -39,13 +40,33 @@ target(struct sk_buff *skb, const struct xt_action_param *par)memcpy (arpptr, &mangle->u_s.src_ip, pln); } arpptr += pln; + +if (IS_ENABLED (CONFIG_FIREWIRE_NET )) { +const struct net_device *dev = skb->dev; + +if (!dev) { +/* can't munge without arphrd type. */ +if (mangle->flags & (ARPT_MANGLE_TDEV |ARPT_MANGLE_TIP )) +return NF_DROP ; +return mangle->target; + } + +if (dev->type ==ARPHRD_IEEE1394 ) + has_tgt_devaddr = false; + } +if (mangle->flags &ARPT_MANGLE_TDEV ) { +if (!has_tgt_devaddr) +return NF_DROP ; +if (ARPT_DEV_ADDR_LEN_MAX < hln || (arpptr + hln >skb_tail_pointer (skb)))return NF_DROP ;memcpy (arpptr, mangle->tgt_devaddr, hln); } - arpptr += hln; +if (has_tgt_devaddr) + arpptr += hln; +if (mangle->flags &ARPT_MANGLE_TIP ) {if (ARPT_MANGLE_ADDR_LEN_MAX < pln || (arpptr + pln >skb_tail_pointer (skb)))
Signature · 1 line
2.52.0
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 7 lines · Florian Westphal
sashiko.dev noticed that similar bug pattern exists in
arpt_mangle:
"IEEE1394 ARP payloads omit the target hardware address, advancing arpptr by hln after the source IP address skips over the actual target IP address."Apply similar fix: check
dev->type. If we're asked to mangle what doesn't exist, drop the packet.
I included a fix for this in:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I forgot to mangle the patch title though to:
netfilter: arp_tables: fix IEEE1394 ARP payload parsing
Quoted 4 lines
Fixes 6752c8db8e0c ("firewire net, ipv4 arp: Extend hardware address and remove driver-level packet inspection.")Signed-off-by Florian Westphal <[email protected]>---
Collides with a inflight patch.
Are you referring to the patch I made?
Quoted 56 lines
I'll rebase or discard depending on what netdev@ does.
net/ipv4/netfilter/arpt_mangle.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)net/ipv4/netfilter/arpt_mangle.c +22
-1@@ -13,6 +13,7 @@ static unsigned int target(struct sk_buff *skb, const struct xt_action_param *par) { const struct arpt_mangle *mangle = par->targinfo; +bool has_tgt_devaddr = true;const struct arphdr *arp;unsigned char *arpptr;int pln, hln;@@ -39,13 +40,33 @@ target(struct sk_buff *skb, const struct xt_action_param *par)memcpy (arpptr, &mangle->u_s.src_ip, pln); } arpptr += pln; + +if (IS_ENABLED (CONFIG_FIREWIRE_NET )) { +const struct net_device *dev = skb->dev; + +if (!dev) { +/* can't munge without arphrd type. */ +if (mangle->flags & (ARPT_MANGLE_TDEV |ARPT_MANGLE_TIP )) +return NF_DROP ; +return mangle->target; + } + +if (dev->type ==ARPHRD_IEEE1394 ) + has_tgt_devaddr = false; + } +if (mangle->flags &ARPT_MANGLE_TDEV ) { +if (!has_tgt_devaddr) +return NF_DROP ; +if (ARPT_DEV_ADDR_LEN_MAX < hln || (arpptr + hln >skb_tail_pointer (skb)))return NF_DROP ;memcpy (arpptr, mangle->tgt_devaddr, hln); } - arpptr += hln; +if (has_tgt_devaddr) + arpptr += hln; +if (mangle->flags &ARPT_MANGLE_TIP ) {if (ARPT_MANGLE_ADDR_LEN_MAX < pln || (arpptr + pln >skb_tail_pointer (skb)))Signature · 1 line
2.52.0
Florian Westphal
maintainerQuoted 8 lines · Pablo Neira Ayuso
Hi Florian,
Quoted 5 lines · Florian Westphal
sashiko.dev noticed that similar bug pattern exists in
arpt_mangle:
"IEEE1394 ARP payloads omit the target hardware address, advancing arpptr by hln after the source IP address skips over the actual target IP address."
Quoted 6 lines
Quoted 2 lines
Apply similar fix: check
dev->type. If we're asked to mangle what doesn't exist, drop the packet.I included a fix for this in:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I saw that *after* I had made this patch.
Quoted 3 lines
Quoted 1 line
Collides with a inflight patch.
Are you referring to the patch I made?
Yes.