bonding: fix ICMPv6 header handling when receiving IPv6 messages
Subsystems (3)
PATCH v3 1/1 bonding: fix ICMPv6 header handling when receiving IPv6 messages
Currently, we get icmp6hdr via function icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header before netif_receive_skb() and bond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.
Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
---
v3: fix _hdr parameter warning reported by kernel test robot
v2: use skb_header_pointer() to get icmp6hdr as Jay suggested.
--- drivers/net/bonding/bond_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +7 -2
@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr; +struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP ) + goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;
Signature · 1 line
2.38.1
Quoted 5 lines · Hangbin Liu
Currently, we get icmp6hdr via function
icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header beforenetif_receive_skb()andbond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.
Quoted 8 lines
Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
Reported-by Liang Li <[email protected]>Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")Acked-by Jonathan Toppins <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Hangbin Liu <[email protected]>
Quoted 34 lines
---
v3: fix_hdrparameter warning reported by kernel test robot
v2: useskb_header_pointer()to get icmp6hdr as Jay suggested.
---drivers/net/bonding/bond_main.c| 9 +++++++--1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +7
-2@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr; +struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP ) + goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;Signature · 1 line
2.38.1
Quoted 27 lines · Hangbin Liu
Currently, we get icmp6hdr via function
icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header beforenetif_receive_skb()andbond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
Reported-by Liang Li <[email protected]>Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")Acked-by Jonathan Toppins <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Hangbin Liu <[email protected]>---
v3: fix_hdrparameter warning reported by kernel test robot
v2: useskb_header_pointer()to get icmp6hdr as Jay suggested.--- drivers/net/bonding/bond_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +0
-0@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3240
Quoted 10 lines
drivers/net/bonding/bond_main.c +3
-2struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr; +struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP )
What makes sure IPv6 header is in skb->head (linear part of the skb) ?
Quoted 7 lines
drivers/net/bonding/bond_main.c +4
-0+ goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;
Quoted 34 lines · Eric Dumazet
Quoted 31 lines · Hangbin Liu
Currently, we get icmp6hdr via function
icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header beforenetif_receive_skb()andbond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
Reported-by Liang Li <[email protected]>Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")Acked-by Jonathan Toppins <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Hangbin Liu <[email protected]>---
v3: fix_hdrparameter warning reported by kernel test robot
v2: useskb_header_pointer()to get icmp6hdr as Jay suggested.--- drivers/net/bonding/bond_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +1
-1@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr;
Quoted 8 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3240
Quoted 5 lines
drivers/net/bonding/bond_main.c +2
-1+struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP )What makes sure IPv6 header is in
skb->head(linear part of the skb) ?
Ah, missed that; skb_header_pointer() will take care of that
(copying if necessary, not that it pulls the header), but it has to be called first.
This isn't a problem new to this patch, the original code
doesn't pull or copy the header, either.
The equivalent function for ARP, bond_arp_rcv(), more or less
inlines skb_header_pointer(), so it doesn't have this issue.
-J
Quoted 7 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3247
Quoted 7 lines
drivers/net/bonding/bond_main.c +4
-0+ goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;
---
-Jay Vosburgh, [email protected]
Quoted 46 lines · Jay Vosburgh
Quoted 34 lines · Eric Dumazet
Quoted 31 lines · Hangbin Liu
Currently, we get icmp6hdr via function
icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header beforenetif_receive_skb()andbond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
Reported-by Liang Li <[email protected]>Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")Acked-by Jonathan Toppins <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Hangbin Liu <[email protected]>---
v3: fix_hdrparameter warning reported by kernel test robot
v2: useskb_header_pointer()to get icmp6hdr as Jay suggested.--- drivers/net/bonding/bond_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +1
-1@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr;Quoted 8 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3240
Quoted 5 lines
drivers/net/bonding/bond_main.c +2
-1+struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP )What makes sure IPv6 header is in
skb->head(linear part of the skb) ?
Quoted 6 lines
Ah, missed that;
skb_header_pointer()will take care of that
(copying if necessary, not that it pulls the header), but it has to be called first.This isn't a problem new to this patch, the original code
doesn't pull or copy the header, either.
Quite frankly I would simply use
if (pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr))
instead of skb_header_pointer()
because chances are high we will need the whole thing in skb->head later.
Quoted 16 lines
The equivalent function for ARP,
bond_arp_rcv(), more or less
inlinesskb_header_pointer(), so it doesn't have this issue.-JQuoted 7 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3247
Quoted 7 lines
drivers/net/bonding/bond_main.c +4
-0+ goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;---
-Jay Vosburgh, [email protected]
Quoted 51 lines · Eric Dumazet
Quoted 50 lines · Jay Vosburgh
Quoted 34 lines · Eric Dumazet
Quoted 31 lines · Hangbin Liu
Currently, we get icmp6hdr via function
icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header beforenetif_receive_skb()andbond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
Reported-by Liang Li <[email protected]>Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")Acked-by Jonathan Toppins <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Hangbin Liu <[email protected]>---
v3: fix_hdrparameter warning reported by kernel test robot
v2: useskb_header_pointer()to get icmp6hdr as Jay suggested.--- drivers/net/bonding/bond_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +1
-1@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr;Quoted 8 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3240
Quoted 5 lines
drivers/net/bonding/bond_main.c +2
-1+struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP )What makes sure IPv6 header is in
skb->head(linear part of the skb) ?Ah, missed that;
skb_header_pointer()will take care of that
(copying if necessary, not that it pulls the header), but it has to be called first.
Quoted 8 lines
Quoted 2 lines
This isn't a problem new to this patch, the original code
doesn't pull or copy the header, either.Quite frankly I would simply use
if (
pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr))instead ofskb_header_pointer()
because chances are high we will need the whole thing inskb->headlater.
Well, it was set up this way with skb_header_pointer() instead
of pskb_may_pull() by you in de063b7040dc ("bonding: remove packet cloning in recv_probe()") so the bonding rx_handler wouldn't change or clone the skb. Now, I'm not sure if we should follow your advice to go against your advice.
Also, we'd have to un-const the skb parameter through the call
chain from bond_handle_frame().
-J
Quoted 7 lines
Quoted 7 lines
The equivalent function for ARP,
bond_arp_rcv(), more or less
inlinesskb_header_pointer(), so it doesn't have this issue.-JQuoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3247
Quoted 6 lines
drivers/net/bonding/bond_main.c +4
-0+ goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;
---
-Jay Vosburgh, [email protected]
Quoted 63 lines · Jay Vosburgh
Quoted 51 lines · Eric Dumazet
Quoted 50 lines · Jay Vosburgh
Quoted 34 lines · Eric Dumazet
Quoted 31 lines · Hangbin Liu
Currently, we get icmp6hdr via function
icmp6_hdr(), which needs the skb transport header to be set first. But there is no rule to ask driver set transport header beforenetif_receive_skb()andbond_handle_frame(). So we will not able to get correct icmp6hdr on some drivers.Fix this by checking the skb length manually and getting icmp6 header based on the IPv6 header offset.
Reported-by Liang Li <[email protected]>Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")Acked-by Jonathan Toppins <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Hangbin Liu <[email protected]>---
v3: fix_hdrparameter warning reported by kernel test robot
v2: useskb_header_pointer()to get icmp6hdr as Jay suggested.--- drivers/net/bonding/bond_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +1
-1@@ -3231,12 +3231,17 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave) {struct slave *curr_active_slave, *curr_arp_slave; -struct icmp6hdr *hdr =icmp6_hdr (skb);struct in6_addr *saddr, *daddr; +const struct icmp6hdr *hdr;Quoted 8 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3240
Quoted 5 lines
drivers/net/bonding/bond_main.c +2
-1+struct icmp6hdr _hdr;if (skb->pkt_type ==PACKET_OTHERHOST || skb->pkt_type ==PACKET_LOOPBACK || - hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) +ipv6_hdr (skb)->nexthdr !=NEXTHDR_ICMP )What makes sure IPv6 header is in
skb->head(linear part of the skb) ?Ah, missed that;
skb_header_pointer()will take care of that
(copying if necessary, not that it pulls the header), but it has to be called first.Quoted 8 lines
Quoted 2 lines
This isn't a problem new to this patch, the original code
doesn't pull or copy the header, either.Quite frankly I would simply use
if (
pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr))instead ofskb_header_pointer()
because chances are high we will need the whole thing inskb->headlater.
Quoted 5 lines
Well, it was set up this way with
skb_header_pointer()instead
ofpskb_may_pull()by you inde063b7040dc("bonding: remove packet cloning inrecv_probe()") so the bondingrx_handlerwouldn't change or clone the skb. Now, I'm not sure if we should follow your advice to go against your advice.
Ah... I forgot about this, thanks for reminding me it ;)
Quoted 22 lines
Also, we'd have to un-const the skb parameter through the call
chain frombond_handle_frame().-JQuoted 7 lines
Quoted 7 lines
The equivalent function for ARP,
bond_arp_rcv(), more or less
inlinesskb_header_pointer(), so it doesn't have this issue.-JQuoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/bonding/bond_main.c static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond, · line 3247
Quoted 6 lines
drivers/net/bonding/bond_main.c +4
-0+ goto out; + + hdr =skb_header_pointer (skb,sizeof (struct ipv6hdr ),sizeof (_hdr), &_hdr); +if (!hdr || hdr->icmp6_type !=NDISC_NEIGHBOUR_ADVERTISEMENT ) goto out; saddr = &ipv6_hdr (skb)->saddr;---
-Jay Vosburgh, [email protected]
Quoted 9 lines · Eric Dumazet
Quoted 8 lines · Jay Vosburgh
Quoted 5 lines · Eric Dumazet
Quite frankly I would simply use
if (
pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr))instead ofskb_header_pointer()
because chances are high we will need the whole thing inskb->headlater.
Quoted 7 lines
Quoted 5 lines
Well, it was set up this way with
skb_header_pointer()instead
ofpskb_may_pull()by you inde063b7040dc("bonding: remove packet cloning inrecv_probe()") so the bondingrx_handlerwouldn't change or clone the skb. Now, I'm not sure if we should follow your advice to go against your advice.Ah... I forgot about this, thanks for reminding me it ;)
Hi David,
The patch state[1] is Changes Requested, but I think Eric has no object on this patch now. Should I keep waiting, or re-send the patch?
[1] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Thanks
Hangbin
Quoted 16 lines · Hangbin Liu
Quoted 15 lines · Eric Dumazet
Quoted 13 lines · Jay Vosburgh
Quoted 5 lines · Eric Dumazet
Quite frankly I would simply use
if (
pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr))instead ofskb_header_pointer()
because chances are high we will need the whole thing inskb->headlater.Well, it was set up this way with
skb_header_pointer()instead
ofpskb_may_pull()by you inde063b7040dc("bonding: remove packet cloning inrecv_probe()") so the bondingrx_handlerwouldn't change or clone the skb. Now, I'm not sure if we should follow your advice to go against your advice.
Quoted 8 lines
Quoted 1 line
Ah... I forgot about this, thanks for reminding me it ;)
Hi David,
The patch state[1] is Changes Requested, but I think Eric has no object on this patch now. Should I keep waiting, or re-send the patch?
[1] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
The excerpt above is confirming that using skb_header_pointer()
is the correct implementation to use.
However, the patch needs to change to call skb_header_pointer()
sooner, to insure that the IPv6 header is available. I've copied the relevant part of the discussion below:
Quoted 4 lines
Quoted 4 lines
struct slave
*curr_active_slave,*curr_arp_slave;(quoted diff) +1
-1- struct icmp6hdr *hdr = icmp6_hdr(skb); struct in6_addr *saddr, *daddr; + const struct icmp6hdr *hdr;
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +2
-1+ struct icmp6hdr _hdr; if (skb->pkt_type == PACKET_OTHERHOST || skb->pkt_type == PACKET_LOOPBACK || - hdr->icmp6_type != NDISC_NEIGHBOUR_ADVERTISEMENT) + ipv6_hdr(skb)->nexthdr != NEXTHDR_ICMP)What makes sure IPv6 header is in
skb->head(linear part of the skb) ?
The above comment is from Eric. I had also mentioned that this
particular problem already existed in the code being patched.
-J
---
-Jay Vosburgh, [email protected]
Quoted 27 lines · Jay Vosburgh
Quoted 6 lines
Hi David,
The patch state[1] is Changes Requested, but I think Eric has no object on this patch now. Should I keep waiting, or re-send the patch?
[1] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
The excerpt above is confirming that using
skb_header_pointer()
is the correct implementation to use.However, the patch needs to change to call
skb_header_pointer()
sooner, to insure that the IPv6 header is available. I've copied the relevant part of the discussion below:Quoted 4 lines
Quoted 4 lines
struct slave
*curr_active_slave,*curr_arp_slave;(quoted diff) +1
-1- struct icmp6hdr *hdr = icmp6_hdr(skb); struct in6_addr *saddr, *daddr; + const struct icmp6hdr *hdr;Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +2
-1+ struct icmp6hdr _hdr; if (skb->pkt_type == PACKET_OTHERHOST || skb->pkt_type == PACKET_LOOPBACK || - hdr->icmp6_type != NDISC_NEIGHBOUR_ADVERTISEMENT) + ipv6_hdr(skb)->nexthdr != NEXTHDR_ICMP)What makes sure IPv6 header is in
skb->head(linear part of the skb) ?
Quoted 2 lines
The above comment is from Eric. I had also mentioned that this
particular problem already existed in the code being patched.
Yes, I also saw your comments. I was thinking to fix this issue separately. i.e. in bond_rcv_validate(). With this we can check both IPv6 header and ARP header. e.g.
drivers/net/bonding/bond_main.c +4 -2
@@ -3278,8 +3278,10 @@ int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond, {#if IS_ENABLED (CONFIG_IPV6 )bool is_ipv6 = skb->protocol ==__cpu_to_be16 (ETH_P_IPV6 ); +struct ipv6hdr ip6_hdr;#endif bool is_arp = skb->protocol ==__cpu_to_be16 (ETH_P_ARP ); +struct arphdr arp_hdr;slave_dbg (bond->dev, slave->dev,"%s: skb->dev %s\n" , __func__, skb->dev->name);
@@ -3293,10 +3295,10 @@ int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond, !slave_do_arp_validate_only(bond)) slave->last_rx = jiffies;return RX_HANDLER_ANOTHER ; - }else if (is_arp) { + }else if (is_arp &&skb_header_pointer (skb,0 ,sizeof (arp_hdr), &arp_hdr)) {return bond_arp_rcv (skb, bond, slave);#if IS_ENABLED (CONFIG_IPV6 ) - } else if (is_ipv6) { + } else if (is_ipv6 && skb_header_pointer(skb, 0, sizeof(ip6_hdr), &ip6_hdr)) {return bond_na_rcv (skb, bond, slave);#endif }else {
What do you think?
Thanks
Hangbin
Quoted 1 line · Hangbin Liu
On Wed, Nov 16, 2022 at 07:16:14AM -0800, Jay Vosburgh wrote:
[...]
Quoted 36 lines
Quoted 2 lines
The above comment is from Eric. I had also mentioned that this
particular problem already existed in the code being patched.Yes, I also saw your comments. I was thinking to fix this issue separately. i.e. in
bond_rcv_validate(). With this we can check both IPv6 header and ARP header. e.g.drivers/net/bonding/bond_main.c +4
-2@@ -3278,8 +3278,10 @@ int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond, {#if IS_ENABLED (CONFIG_IPV6 )bool is_ipv6 = skb->protocol ==__cpu_to_be16 (ETH_P_IPV6 ); +struct ipv6hdr ip6_hdr;#endif bool is_arp = skb->protocol ==__cpu_to_be16 (ETH_P_ARP ); +struct arphdr arp_hdr;slave_dbg (bond->dev, slave->dev,"%s: skb->dev %s\n" , __func__, skb->dev->name);@@ -3293,10 +3295,10 @@ int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond, !slave_do_arp_validate_only(bond)) slave->last_rx = jiffies;return RX_HANDLER_ANOTHER ; - }else if (is_arp) { + }else if (is_arp &&skb_header_pointer (skb,0 ,sizeof (arp_hdr), &arp_hdr)) {return bond_arp_rcv (skb, bond, slave);#if IS_ENABLED (CONFIG_IPV6 ) - } else if (is_ipv6) { + } else if (is_ipv6 && skb_header_pointer(skb, 0, sizeof(ip6_hdr), &ip6_hdr)) {return bond_na_rcv (skb, bond, slave);#endif }else {
Quoted 1 line
What do you think?
I don't see how this solves the icmp6_hdr() / ipv6_hdr() problem
in bond_na_rcv(); skb_header_pointer() doesn't do a pull, it just copies into the supplied struct (if necessary).
-J
---
-Jay Vosburgh, [email protected]
Quoted 7 lines · Jay Vosburgh
Quoted 7 lines
#if
IS_ENABLED(CONFIG_IPV6)drivers/net/bonding/bond_main.c +1
-1- }else if (is_ipv6) { + }else if (is_ipv6 &&skb_header_pointer (skb,0 ,sizeof (ip6_hdr), &ip6_hdr)) {return bond_na_rcv(skb, bond, slave); #endif } else {
Quoted 5 lines
Quoted 1 line
What do you think?
I don't see how this solves the
icmp6_hdr()/ipv6_hdr()problem
inbond_na_rcv();skb_header_pointer()doesn't do a pull, it just copies into the supplied struct (if necessary).
Hmm... Maybe I didn't get what you and Eric means. If we can copy the supplied buffer success, doesn't this make sure IPv6 header is in skb?
Thanks
Hangbin
Quoted 8 lines · Hangbin Liu
Quoted 7 lines · Jay Vosburgh
Quoted 7 lines
#if
IS_ENABLED(CONFIG_IPV6)(quoted diff) +1
-1- } else if (is_ipv6) { + } else if (is_ipv6 && skb_header_pointer(skb, 0, sizeof(ip6_hdr), &ip6_hdr)) {return bond_na_rcv(skb, bond, slave); #endif } else {
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
What do you think?
I don't see how this solves the
icmp6_hdr()/ipv6_hdr()problem
inbond_na_rcv();skb_header_pointer()doesn't do a pull, it just copies into the supplied struct (if necessary).Hmm... Maybe I didn't get what you and Eric means. If we can copy the supplied buffer success, doesn't this make sure IPv6 header is in skb?
Please try :
drivers/net/bonding/bond_main.c +0 -0
@@ -3224,16 +3224,24 @@ static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond,
struct slave *slave)
{
struct slave *curr_active_slave, *curr_arp_slave; - struct icmp6hdr *hdr = icmp6_hdr(skb); struct in6_addr *saddr, *daddr;
+ struct {
+ struct ipv6hdr ip6;
+ struct icmp6hdr icmp6;
+ } *combined, _combined;
if (skb->pkt_type == PACKET_OTHERHOST ||
- skb->pkt_type == PACKET_LOOPBACK ||
- hdr->icmp6_type != NDISC_NEIGHBOUR_ADVERTISEMENT)
+ skb->pkt_type == PACKET_LOOPBACK)
+ goto out;
+
+ combined = skb_header_pointer(skb, 0, sizeof(_combined), &_combined); + if (!combined ||
+ combined->ip6.nexthdr != NEXTHDR_ICMP ||
+ combined->icmp6.icmp6_type != NDISC_NEIGHBOUR_ADVERTISEMENT) goto out;
- saddr = &ipv6_hdr(skb)->saddr;
- daddr = &ipv6_hdr(skb)->daddr;
+ saddr = &combined->ip6.saddr;
+ daddr = &combined->ip6.daddr;
slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI6c tip %pI6c\n", __func__, slave->dev->name, bond_slave_state(slave),
Quoted 8 lines · Hangbin Liu
Quoted 7 lines · Jay Vosburgh
Quoted 7 lines
#if
IS_ENABLED(CONFIG_IPV6)drivers/net/bonding/bond_main.c +1
-1- }else if (is_ipv6) { + }else if (is_ipv6 &&skb_header_pointer (skb,0 ,sizeof (ip6_hdr), &ip6_hdr)) {return bond_na_rcv(skb, bond, slave); #endif } else {
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
What do you think?
I don't see how this solves the
icmp6_hdr()/ipv6_hdr()problem
inbond_na_rcv();skb_header_pointer()doesn't do a pull, it just copies into the supplied struct (if necessary).Hmm... Maybe I didn't get what you and Eric means. If we can copy the supplied buffer success, doesn't this make sure IPv6 header is in skb?
The header is in the skb, but it may not be in the linear part
of the skb, i.e., the header is wholly or partially in a skb frag, not in the area covered by skb->data ... skb->tail. The various *_hdr() macros only look in the linear area, not the frags, and don't check to see if the linear area contains the entire header.
skb_header_pointer() is smart enough to check, and if the
requested data is entirely within the linear area, it returns a pointer to there; if not, it copies from the frags into the supplied struct and returns a pointer to that. What it doesn't do is a pull (move data from a frag into the linear area), so merely calling skb_header_pointer() doesn't affect the layout of what's in the skb (which is the point, bonding uses it here to avoid changing the skb).
There may be better explanations out there, but
http://vger.kernel.org/~davem/skb_data.html
covers the basics. Look for the references to "paged data." -J
---
-Jay Vosburgh, [email protected]
Quoted 33 lines · Jay Vosburgh
Quoted 8 lines · Hangbin Liu
Quoted 7 lines · Jay Vosburgh
Quoted 7 lines
#if
IS_ENABLED(CONFIG_IPV6)drivers/net/bonding/bond_main.c +1
-1- }else if (is_ipv6) { + }else if (is_ipv6 &&skb_header_pointer (skb,0 ,sizeof (ip6_hdr), &ip6_hdr)) {return bond_na_rcv(skb, bond, slave); #endif } else {Quoted 8 lines
Quoted 5 lines
Quoted 1 line
What do you think?
I don't see how this solves the
icmp6_hdr()/ipv6_hdr()problem
inbond_na_rcv();skb_header_pointer()doesn't do a pull, it just copies into the supplied struct (if necessary).Hmm... Maybe I didn't get what you and Eric means. If we can copy the supplied buffer success, doesn't this make sure IPv6 header is in skb?
The header is in the skb, but it may not be in the linear part
of the skb, i.e., the header is wholly or partially in a skb frag, not in the area covered byskb->data...skb->tail. The various*_hdr()macros only look in the linear area, not the frags, and don't check to see if the linear area contains the entire header.
skb_header_pointer()is smart enough to check, and if the
requested data is entirely within the linear area, it returns a pointer to there; if not, it copies from the frags into the supplied struct and returns a pointer to that. What it doesn't do is a pull (move data from a frag into the linear area), so merely callingskb_header_pointer()doesn't affect the layout of what's in the skb (which is the point, bonding uses it here to avoid changing the skb).
Quoted 5 lines
There may be better explanations out there, but
http://vger.kernel.org/~davem/skb_data.html
covers the basics. Look for the references to "paged data."
Hi Jay,
Thanks a lot for your explanation. I thought you mean there may no IPv6 header in skb. Now I know the problem is using ipv6_hdr() for non-liner skb. I will update the patch with Eric suggested.
Thanks
Hangbin