All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop}
@ 2020-10-02 19:53 Guillaume Nault
  2020-10-04 14:00 ` Davide Caratti
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Guillaume Nault @ 2020-10-02 19:53 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: netdev, Martin Varghese, Davide Caratti

Openvswitch allows to drop a packet's Ethernet header, therefore
skb_mpls_push() and skb_mpls_pop() might be called with ethernet=true
and mac_len=0. In that case the pointer passed to skb_mod_eth_type()
doesn't point to an Ethernet header and the new Ethertype is written at
unexpected locations.

Fix this by verifying that mac_len is big enough to contain an Ethernet
header.

Fixes: fa4e0f8855fc ("net/sched: fix corrupted L2 header with MPLS 'push' and 'pop' actions")
Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
Notes:
  - Found by code inspection.
  - Using commit fa4e0f8855fc for the Fixes tag because mac_len is
    needed for the test. The problem probably exists since openvswitch
    can pop the Ethernet header though.

 net/core/skbuff.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 6faf73d6a0f7..2b48cb0cc684 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5622,7 +5622,7 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
 	lse->label_stack_entry = mpls_lse;
 	skb_postpush_rcsum(skb, lse, MPLS_HLEN);
 
-	if (ethernet)
+	if (ethernet && mac_len >= ETH_HLEN)
 		skb_mod_eth_type(skb, eth_hdr(skb), mpls_proto);
 	skb->protocol = mpls_proto;
 
@@ -5662,7 +5662,7 @@ int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
 	skb_reset_mac_header(skb);
 	skb_set_network_header(skb, mac_len);
 
-	if (ethernet) {
+	if (ethernet && mac_len >= ETH_HLEN) {
 		struct ethhdr *hdr;
 
 		/* use mpls_hdr() to get ethertype to account for VLANs. */
-- 
2.21.3


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

* Re: [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop}
  2020-10-02 19:53 [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop} Guillaume Nault
@ 2020-10-04 14:00 ` Davide Caratti
  2020-10-04 14:50 ` Varghese, Martin (Nokia - IN/Bangalore)
  2020-10-04 22:10 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Davide Caratti @ 2020-10-04 14:00 UTC (permalink / raw)
  To: Guillaume Nault, David Miller, Jakub Kicinski; +Cc: netdev, Martin Varghese

On Fri, 2020-10-02 at 21:53 +0200, Guillaume Nault wrote:
> Openvswitch allows to drop a packet's Ethernet header, therefore
> skb_mpls_push() and skb_mpls_pop() might be called with ethernet=true
> and mac_len=0. In that case the pointer passed to skb_mod_eth_type()
> doesn't point to an Ethernet header and the new Ethertype is written at
> unexpected locations.
> 
> Fix this by verifying that mac_len is big enough to contain an Ethernet
> header.
> 
> Fixes: fa4e0f8855fc ("net/sched: fix corrupted L2 header with MPLS 'push' and 'pop' actions")
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
> Notes:
>   - Found by code inspection.
>   - Using commit fa4e0f8855fc for the Fixes tag because mac_len is
>     needed for the test. The problem probably exists since openvswitch
>     can pop the Ethernet header though.
> 
>  net/core/skbuff.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)


Acked-by: Davide Caratti <dcaratti@redhat.com>

thanks!

-- 
davide



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

* RE: [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop}
  2020-10-02 19:53 [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop} Guillaume Nault
  2020-10-04 14:00 ` Davide Caratti
@ 2020-10-04 14:50 ` Varghese, Martin (Nokia - IN/Bangalore)
  2020-10-04 21:29   ` David Miller
  2020-10-04 22:10 ` David Miller
  2 siblings, 1 reply; 5+ messages in thread
From: Varghese, Martin (Nokia - IN/Bangalore) @ 2020-10-04 14:50 UTC (permalink / raw)
  To: Guillaume Nault, David Miller, Jakub Kicinski; +Cc: netdev, Davide Caratti

On Fri, 2020-10-02 at 21:53 +0200, Guillaume Nault wrote:
> Openvswitch allows to drop a packet's Ethernet header, therefore
>skb_mpls_push() and skb_mpls_pop() might be called with ethernet=true and mac_len=0. In that case the pointer passed to skb_mod_eth_type()     >doesn't point to an Ethernet header and the new Ethertype is written at unexpected locations.

>Fix this by verifying that mac_len is big enough to contain an Ethernet header.

>Fixes: fa4e0f8855fc ("net/sched: fix corrupted L2 header with MPLS 'push' and 'pop' actions")
>Signed-off-by: Guillaume Nault <gnault@redhat.com>

Is this check redundant. I believe Openvswitch already takes care of it ?


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

* Re: [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop}
  2020-10-04 14:50 ` Varghese, Martin (Nokia - IN/Bangalore)
@ 2020-10-04 21:29   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2020-10-04 21:29 UTC (permalink / raw)
  To: martin.varghese; +Cc: gnault, kuba, netdev, dcaratti

From: "Varghese, Martin (Nokia - IN/Bangalore)" <martin.varghese@nokia.com>
Date: Sun, 4 Oct 2020 14:50:58 +0000

> Is this check redundant. I believe Openvswitch already takes care of it ?

Openvswitch isn't the only user of these skb_mpls_*() helpers.

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

* Re: [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop}
  2020-10-02 19:53 [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop} Guillaume Nault
  2020-10-04 14:00 ` Davide Caratti
  2020-10-04 14:50 ` Varghese, Martin (Nokia - IN/Bangalore)
@ 2020-10-04 22:10 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2020-10-04 22:10 UTC (permalink / raw)
  To: gnault; +Cc: kuba, netdev, martin.varghese, dcaratti

From: Guillaume Nault <gnault@redhat.com>
Date: Fri, 2 Oct 2020 21:53:08 +0200

> Openvswitch allows to drop a packet's Ethernet header, therefore
> skb_mpls_push() and skb_mpls_pop() might be called with ethernet=true
> and mac_len=0. In that case the pointer passed to skb_mod_eth_type()
> doesn't point to an Ethernet header and the new Ethertype is written at
> unexpected locations.
> 
> Fix this by verifying that mac_len is big enough to contain an Ethernet
> header.
> 
> Fixes: fa4e0f8855fc ("net/sched: fix corrupted L2 header with MPLS 'push' and 'pop' actions")
> Signed-off-by: Guillaume Nault <gnault@redhat.com>

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2020-10-04 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 19:53 [PATCH net] net/core: check length before updating Ethertype in skb_mpls_{push,pop} Guillaume Nault
2020-10-04 14:00 ` Davide Caratti
2020-10-04 14:50 ` Varghese, Martin (Nokia - IN/Bangalore)
2020-10-04 21:29   ` David Miller
2020-10-04 22:10 ` 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.