All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/2] ipvlan: Fix insufficient skb linear check
@ 2017-11-23  3:47 gfree.wind
  2017-11-23  3:47 ` [PATCH net 1/2] ipvlan: Fix insufficient skb linear check for arp gfree.wind
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gfree.wind @ 2017-11-23  3:47 UTC (permalink / raw)
  To: maheshb, davem, netdev; +Cc: Gao Feng

From: Gao Feng <gfree.wind@vip.163.com>

The current ipvlan codes use pskb_may_pull to get the skb linear header in
func ipvlan_get_L3_hdr, but the size isn't enough for arp and ipv6 icmp.
So it may access the unexpected momory in ipvlan_addr_lookup.

Gao Feng (2):
  ipvlan: Fix insufficient skb linear check for arp
  ipvlan: Fix insufficient skb linear check for ipv6 icmp

 drivers/net/ipvlan/ipvlan_core.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net 1/2] ipvlan: Fix insufficient skb linear check for arp
  2017-11-23  3:47 [PATCH net 0/2] ipvlan: Fix insufficient skb linear check gfree.wind
@ 2017-11-23  3:47 ` gfree.wind
  2017-11-23  3:47 ` [PATCH net 2/2] ipvlan: Fix insufficient skb linear check for ipv6 icmp gfree.wind
  2017-11-23 18:37 ` [PATCH net 0/2] ipvlan: Fix insufficient skb linear check David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: gfree.wind @ 2017-11-23  3:47 UTC (permalink / raw)
  To: maheshb, davem, netdev; +Cc: Gao Feng

From: Gao Feng <gfree.wind@vip.163.com>

In the function ipvlan_get_L3_hdr, current codes use pskb_may_pull to
make sure the skb header has enough linear room for arp header. But it
would access the arp payload in func ipvlan_addr_lookup. So it still may
access the unepxected memory.

Now use arp_hdr_len(port->dev) instead of the arp header as the param.

Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
---
 drivers/net/ipvlan/ipvlan_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c
index f2a7e92..4476425 100644
--- a/drivers/net/ipvlan/ipvlan_core.c
+++ b/drivers/net/ipvlan/ipvlan_core.c
@@ -116,7 +116,7 @@ bool ipvlan_addr_busy(struct ipvl_port *port, void *iaddr, bool is_v6)
 	return false;
 }
 
-static void *ipvlan_get_L3_hdr(struct sk_buff *skb, int *type)
+static void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int *type)
 {
 	void *lyr3h = NULL;
 
@@ -124,7 +124,7 @@ static void *ipvlan_get_L3_hdr(struct sk_buff *skb, int *type)
 	case htons(ETH_P_ARP): {
 		struct arphdr *arph;
 
-		if (unlikely(!pskb_may_pull(skb, sizeof(*arph))))
+		if (unlikely(!pskb_may_pull(skb, arp_hdr_len(port->dev))))
 			return NULL;
 
 		arph = arp_hdr(skb);
@@ -510,7 +510,7 @@ static int ipvlan_xmit_mode_l3(struct sk_buff *skb, struct net_device *dev)
 	struct ipvl_addr *addr;
 	int addr_type;
 
-	lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
+	lyr3h = ipvlan_get_L3_hdr(ipvlan->port, skb, &addr_type);
 	if (!lyr3h)
 		goto out;
 
@@ -539,7 +539,7 @@ static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev)
 
 	if (!ipvlan_is_vepa(ipvlan->port) &&
 	    ether_addr_equal(eth->h_dest, eth->h_source)) {
-		lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
+		lyr3h = ipvlan_get_L3_hdr(ipvlan->port, skb, &addr_type);
 		if (lyr3h) {
 			addr = ipvlan_addr_lookup(ipvlan->port, lyr3h, addr_type, true);
 			if (addr) {
@@ -606,7 +606,7 @@ static bool ipvlan_external_frame(struct sk_buff *skb, struct ipvl_port *port)
 	int addr_type;
 
 	if (ether_addr_equal(eth->h_source, skb->dev->dev_addr)) {
-		lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
+		lyr3h = ipvlan_get_L3_hdr(port, skb, &addr_type);
 		if (!lyr3h)
 			return true;
 
@@ -627,7 +627,7 @@ static rx_handler_result_t ipvlan_handle_mode_l3(struct sk_buff **pskb,
 	struct sk_buff *skb = *pskb;
 	rx_handler_result_t ret = RX_HANDLER_PASS;
 
-	lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
+	lyr3h = ipvlan_get_L3_hdr(port, skb, &addr_type);
 	if (!lyr3h)
 		goto out;
 
@@ -666,7 +666,7 @@ static rx_handler_result_t ipvlan_handle_mode_l2(struct sk_buff **pskb,
 	} else {
 		struct ipvl_addr *addr;
 
-		lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
+		lyr3h = ipvlan_get_L3_hdr(port, skb, &addr_type);
 		if (!lyr3h)
 			return ret;
 
@@ -717,7 +717,7 @@ static struct ipvl_addr *ipvlan_skb_to_addr(struct sk_buff *skb,
 	if (!port || port->mode != IPVLAN_MODE_L3S)
 		goto out;
 
-	lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
+	lyr3h = ipvlan_get_L3_hdr(port, skb, &addr_type);
 	if (!lyr3h)
 		goto out;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net 2/2] ipvlan: Fix insufficient skb linear check for ipv6 icmp
  2017-11-23  3:47 [PATCH net 0/2] ipvlan: Fix insufficient skb linear check gfree.wind
  2017-11-23  3:47 ` [PATCH net 1/2] ipvlan: Fix insufficient skb linear check for arp gfree.wind
@ 2017-11-23  3:47 ` gfree.wind
  2017-11-23 18:37 ` [PATCH net 0/2] ipvlan: Fix insufficient skb linear check David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: gfree.wind @ 2017-11-23  3:47 UTC (permalink / raw)
  To: maheshb, davem, netdev; +Cc: Gao Feng

From: Gao Feng <gfree.wind@vip.163.com>

In the function ipvlan_get_L3_hdr, current codes use pskb_may_pull to
make sure the skb header has enough linear room for ipv6 header. But it
would use the latter memory directly without linear check when it is icmp.
So it still may access the unepxected memory in ipvlan_addr_lookup.

Now invoke the pskb_may_pull again if it is ipv6 icmp.

Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
---
 drivers/net/ipvlan/ipvlan_core.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c
index 4476425..11c1e79 100644
--- a/drivers/net/ipvlan/ipvlan_core.c
+++ b/drivers/net/ipvlan/ipvlan_core.c
@@ -165,8 +165,26 @@ static void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int
 		/* Only Neighbour Solicitation pkts need different treatment */
 		if (ipv6_addr_any(&ip6h->saddr) &&
 		    ip6h->nexthdr == NEXTHDR_ICMP) {
+			struct icmp6hdr	*icmph;
+
+			if (unlikely(!pskb_may_pull(skb, sizeof(*ip6h) + sizeof(*icmph))))
+				return NULL;
+
+			ip6h = ipv6_hdr(skb);
+			icmph = (struct icmp6hdr *)(ip6h + 1);
+
+			if (icmph->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
+				/* Need to access the ipv6 address in body */
+				if (unlikely(!pskb_may_pull(skb, sizeof(*ip6h) + sizeof(*icmph)
+						+ sizeof(struct in6_addr))))
+					return NULL;
+
+				ip6h = ipv6_hdr(skb);
+				icmph = (struct icmp6hdr *)(ip6h + 1);
+			}
+
 			*type = IPVL_ICMPV6;
-			lyr3h = ip6h + 1;
+			lyr3h = icmph;
 		}
 		break;
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net 0/2] ipvlan: Fix insufficient skb linear check
  2017-11-23  3:47 [PATCH net 0/2] ipvlan: Fix insufficient skb linear check gfree.wind
  2017-11-23  3:47 ` [PATCH net 1/2] ipvlan: Fix insufficient skb linear check for arp gfree.wind
  2017-11-23  3:47 ` [PATCH net 2/2] ipvlan: Fix insufficient skb linear check for ipv6 icmp gfree.wind
@ 2017-11-23 18:37 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-11-23 18:37 UTC (permalink / raw)
  To: gfree.wind; +Cc: maheshb, netdev

From: gfree.wind@vip.163.com
Date: Thu, 23 Nov 2017 11:47:10 +0800

> From: Gao Feng <gfree.wind@vip.163.com>
> 
> The current ipvlan codes use pskb_may_pull to get the skb linear header in
> func ipvlan_get_L3_hdr, but the size isn't enough for arp and ipv6 icmp.
> So it may access the unexpected momory in ipvlan_addr_lookup.

Series applied, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-23 18:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23  3:47 [PATCH net 0/2] ipvlan: Fix insufficient skb linear check gfree.wind
2017-11-23  3:47 ` [PATCH net 1/2] ipvlan: Fix insufficient skb linear check for arp gfree.wind
2017-11-23  3:47 ` [PATCH net 2/2] ipvlan: Fix insufficient skb linear check for ipv6 icmp gfree.wind
2017-11-23 18:37 ` [PATCH net 0/2] ipvlan: Fix insufficient skb linear check David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.