Skip to contentSkip to conversation

bonding: fix ICMPv6 header handling when receiving IPv6 messages

PATCH Superseded Hangbin Liu 4 participants 15 messages Nov 9, 2022 – Nov 18, 2022

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")

---
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
index e84c49bf4d0c..2c6356232668 100644
@@ -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
Acked-by on v3 1/1
#1 lore raw
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 before netif_receive_skb() and bond_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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")
Quoted 34 lines

---
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
index e84c49bf4d0c..2c6356232668 100644
@@ -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
#2 lore raw
In reply to Hangbin Liu
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 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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")

---
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 +0 -0
index e84c49bf4d0c..2c6356232668 100644
@@ -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 -2
  	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)

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;
#3 lore raw
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 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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")

---
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 +1 -1
index e84c49bf4d0c..2c6356232668 100644
@@ -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]

#4 lore raw
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 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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")

---
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 +1 -1
index e84c49bf4d0c..2c6356232668 100644
@@ -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
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]

#5 lore raw
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 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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")

---
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 +1 -1
index e84c49bf4d0c..2c6356232668 100644
@@ -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 of skb_header_pointer()
because chances are high we will need the whole thing in skb->head later.

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
inlines skb_header_pointer(), so it doesn't have this issue.

        -J
Quoted 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]

#6 lore raw
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 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.

Fixes 4e24be018eb9 ("bonding: add new parameter ns_targets")

---
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 +1 -1
index e84c49bf4d0c..2c6356232668 100644
@@ -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 of skb_header_pointer()
because chances are high we will need the whole thing in skb->head later.

Quoted 5 lines

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.

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 from bond_handle_frame().

        -J
Quoted 7 lines
Quoted 7 lines

The equivalent function for ARP, bond_arp_rcv(), more or less
inlines skb_header_pointer(), so it doesn't have this issue.

        -J
Quoted 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]

#7 lore raw
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 of skb_header_pointer()
because chances are high we will need the whole thing in skb->head later.

Quoted 7 lines
Quoted 5 lines

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.

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

#8 lore raw
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 of skb_header_pointer()
because chances are high we will need the whole thing in skb->head later.

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.

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]

#9 lore raw
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
index 2c6356232668..ae4c30a25b76 100644
@@ -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

#10 lore raw
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
index 2c6356232668..ae4c30a25b76 100644
@@ -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]

#11 lore raw
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
in bond_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

#12 lore raw
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
in bond_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
index 1cd4e71916f80876ca56eb778f8423aa04c80684..c4bdc707c62c4a29c3e16ec4ad523feae00447cb 100644
@@ -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),

#13 lore raw
In reply to Hangbin Liu
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
in bond_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]

#14 lore raw
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
in bond_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).

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