All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets
@ 2017-01-25 16:26 Paul Durrant
  2017-01-25 16:51 ` Eric Dumazet
  2017-01-25 16:51 ` Eric Dumazet
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Durrant @ 2017-01-25 16:26 UTC (permalink / raw)
  To: netdev, xen-devel; +Cc: Paul Durrant, Boris Ostrovsky, Juergen Gross

Sowmini points out two vulnerabilities in xen-netfront:

a) The code assumes that skb->len is at least ETH_HLEN.
b) The code assumes that at least ETH_HLEN octets are in the linear
   port of the socket buffer.

This patch adds tests for both of these, and in the case of the latter
pulls sufficient bytes into the linear area.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reported-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Tested-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
---
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
---
 drivers/net/xen-netfront.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 40f26b6..0478809 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -567,6 +567,10 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	u16 queue_index;
 	struct sk_buff *nskb;
 
+	/* Basic sanity check */
+	if (unlikely(skb->len < ETH_HLEN))
+		goto drop;
+
 	/* Drop the packet if no queues are set up */
 	if (num_queues < 1)
 		goto drop;
@@ -609,6 +613,11 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	}
 
 	len = skb_headlen(skb);
+	if (unlikely(len < ETH_HLEN)) {
+		if (!__pskb_pull_tail(skb, ETH_HLEN - len))
+			goto drop;
+		len = ETH_HLEN;
+	}
 
 	spin_lock_irqsave(&queue->tx_lock, flags);
 
-- 
2.1.4

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

* Re: [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets
  2017-01-25 16:26 [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets Paul Durrant
  2017-01-25 16:51 ` Eric Dumazet
@ 2017-01-25 16:51 ` Eric Dumazet
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2017-01-25 16:51 UTC (permalink / raw)
  To: Paul Durrant; +Cc: netdev, xen-devel, Boris Ostrovsky, Juergen Gross

On Wed, 2017-01-25 at 16:26 +0000, Paul Durrant wrote:
> Sowmini points out two vulnerabilities in xen-netfront:
> 
> a) The code assumes that skb->len is at least ETH_HLEN.
> b) The code assumes that at least ETH_HLEN octets are in the linear
>    port of the socket buffer.
> 
> This patch adds tests for both of these, and in the case of the latter
> pulls sufficient bytes into the linear area.
> 
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> Reported-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
> Tested-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
> ---
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: Juergen Gross <jgross@suse.com>
> ---
>  drivers/net/xen-netfront.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index 40f26b6..0478809 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -567,6 +567,10 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
>  	u16 queue_index;
>  	struct sk_buff *nskb;
>  
> +	/* Basic sanity check */
> +	if (unlikely(skb->len < ETH_HLEN))
> +		goto drop;
> +
>  	/* Drop the packet if no queues are set up */
>  	if (num_queues < 1)
>  		goto drop;
> @@ -609,6 +613,11 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
>  	}
>  
>  	len = skb_headlen(skb);
> +	if (unlikely(len < ETH_HLEN)) {
> +		if (!__pskb_pull_tail(skb, ETH_HLEN - len))
> +			goto drop;
> +		len = ETH_HLEN;
> +	}

Looks like duplicated code, and buggy, considering the code above

page = virt_to_page(skb->data);
offset = offset_in_page(skb->data);

Your patch might end up with skb->data/head being reallocated, and use
after free would happen.

What about something like that ?

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 40f26b69beb11459f0566fc1d1d739aa75e643bf..99a67fe4de86d3141169143b0820d00968cb09f2 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -583,6 +583,8 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 			skb->len);
 		goto drop;
 	}
+	if (!pskb_may_pull(skb, ETH_HLEN))
+		goto drop;
 
 	slots = xennet_count_skb_slots(skb);
 	if (unlikely(slots > MAX_XEN_SKB_FRAGS + 1)) {

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

* Re: [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets
  2017-01-25 16:26 [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets Paul Durrant
@ 2017-01-25 16:51 ` Eric Dumazet
  2017-01-25 16:51 ` Eric Dumazet
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2017-01-25 16:51 UTC (permalink / raw)
  To: Paul Durrant; +Cc: Juergen Gross, netdev, Boris Ostrovsky, xen-devel

On Wed, 2017-01-25 at 16:26 +0000, Paul Durrant wrote:
> Sowmini points out two vulnerabilities in xen-netfront:
> 
> a) The code assumes that skb->len is at least ETH_HLEN.
> b) The code assumes that at least ETH_HLEN octets are in the linear
>    port of the socket buffer.
> 
> This patch adds tests for both of these, and in the case of the latter
> pulls sufficient bytes into the linear area.
> 
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> Reported-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
> Tested-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
> ---
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: Juergen Gross <jgross@suse.com>
> ---
>  drivers/net/xen-netfront.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index 40f26b6..0478809 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -567,6 +567,10 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
>  	u16 queue_index;
>  	struct sk_buff *nskb;
>  
> +	/* Basic sanity check */
> +	if (unlikely(skb->len < ETH_HLEN))
> +		goto drop;
> +
>  	/* Drop the packet if no queues are set up */
>  	if (num_queues < 1)
>  		goto drop;
> @@ -609,6 +613,11 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
>  	}
>  
>  	len = skb_headlen(skb);
> +	if (unlikely(len < ETH_HLEN)) {
> +		if (!__pskb_pull_tail(skb, ETH_HLEN - len))
> +			goto drop;
> +		len = ETH_HLEN;
> +	}

Looks like duplicated code, and buggy, considering the code above

page = virt_to_page(skb->data);
offset = offset_in_page(skb->data);

Your patch might end up with skb->data/head being reallocated, and use
after free would happen.

What about something like that ?

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 40f26b69beb11459f0566fc1d1d739aa75e643bf..99a67fe4de86d3141169143b0820d00968cb09f2 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -583,6 +583,8 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 			skb->len);
 		goto drop;
 	}
+	if (!pskb_may_pull(skb, ETH_HLEN))
+		goto drop;
 
 	slots = xennet_count_skb_slots(skb);
 	if (unlikely(slots > MAX_XEN_SKB_FRAGS + 1)) {



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets
@ 2017-01-25 16:26 Paul Durrant
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Durrant @ 2017-01-25 16:26 UTC (permalink / raw)
  To: netdev, xen-devel; +Cc: Juergen Gross, Boris Ostrovsky, Paul Durrant

Sowmini points out two vulnerabilities in xen-netfront:

a) The code assumes that skb->len is at least ETH_HLEN.
b) The code assumes that at least ETH_HLEN octets are in the linear
   port of the socket buffer.

This patch adds tests for both of these, and in the case of the latter
pulls sufficient bytes into the linear area.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reported-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Tested-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
---
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
---
 drivers/net/xen-netfront.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 40f26b6..0478809 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -567,6 +567,10 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	u16 queue_index;
 	struct sk_buff *nskb;
 
+	/* Basic sanity check */
+	if (unlikely(skb->len < ETH_HLEN))
+		goto drop;
+
 	/* Drop the packet if no queues are set up */
 	if (num_queues < 1)
 		goto drop;
@@ -609,6 +613,11 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	}
 
 	len = skb_headlen(skb);
+	if (unlikely(len < ETH_HLEN)) {
+		if (!__pskb_pull_tail(skb, ETH_HLEN - len))
+			goto drop;
+		len = ETH_HLEN;
+	}
 
 	spin_lock_irqsave(&queue->tx_lock, flags);
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2017-01-25 16:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-25 16:26 [PATCH net-next] xen-netfront: reject short packets and handle non-linear packets Paul Durrant
2017-01-25 16:51 ` Eric Dumazet
2017-01-25 16:51 ` Eric Dumazet
  -- strict thread matches above, loose matches on Subject: below --
2017-01-25 16:26 Paul Durrant

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.