Skip to contentSkip to conversation

gre: refetch erspan header from skb->data after pskb_may_pull()

PATCH In review Cong Wang 5 participants 7 messages Dec 6, 2019 – Dec 7, 2019

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 gre: refetch erspan header from skb->data after pskb_may_pull()

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>
---
 net/ipv4/gre_demux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_demux.c +1 -1
index 44bfeecac33e..5fd6e8ed02b5 100644
@@ -127,7 +127,7 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 		if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))
 			return -EINVAL;
 
-		ershdr = (struct erspan_base_hdr *)options;
+		ershdr = (struct erspan_base_hdr *)(skb->data + nhs + hdr_len);
 		tpi->key = cpu_to_be32(get_session_id(ershdr));
 	}
 
Signature · 1 line
2.21.0
#1 lore raw

Hi Cong,

Quoted 21 lines · Cong Wang

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>
---
 net/ipv4/gre_demux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_demux.c +0 -0
index 44bfeecac33e..5fd6e8ed02b5 100644

net/ipv4/gre_demux.c int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, · line 130

Quoted 5 lines
net/ipv4/gre_demux.c +1 -1
@@ -127,7 +127,7 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 		if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))
 			return -EINVAL;
 
-		ershdr = (struct erspan_base_hdr *)options;
+		ershdr = (struct erspan_base_hdr *)(skb->data + nhs + hdr_len);

It seems to me that in the case of WCCPv2 hdr_len will be 4 bytes longer than where options would be advanced to. Is that a problem here?

Quoted 6 lines
net/ipv4/gre_demux.c +0 -0
 		tpi->key = cpu_to_be32(get_session_id(ershdr));
 	}
 
Signature · 1 line
2.21.0
#2 lore raw
Quoted 28 lines

Hi Cong,

Quoted 24 lines · Cong Wang

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>
---
 net/ipv4/gre_demux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_demux.c +0 -0
index 44bfeecac33e..5fd6e8ed02b5 100644
@@ -127,7 +127,7 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
              if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))
                      return -EINVAL;
 
Quoted 6 lines

net/ipv4/gre_demux.c int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, · line 130

Quoted 2 lines
net/ipv4/gre_demux.c +1 -1
-             ershdr = (struct erspan_base_hdr *)options;
+             ershdr = (struct erspan_base_hdr *)(skb->data + nhs + hdr_len);

It seems to me that in the case of WCCPv2 hdr_len will be 4 bytes longer than where options would be advanced to. Is that a problem here?

Hi Simon,

I guess the two conditions are mutually exclusive since tpi->proto is initialized with greh->protocol. Am I missing something?

Regards,
Lorenzo

Quoted 7 lines
Quoted 6 lines
net/ipv4/gre_demux.c +0 -1
              tpi->key = cpu_to_be32(get_session_id(ershdr));
      }
 
--

2.21.0

Reviewed-by
#3 lore raw
Quoted 35 lines · Lorenzo Bianconi
Quoted 28 lines

Hi Cong,

Quoted 24 lines · Cong Wang

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>
---
 net/ipv4/gre_demux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_demux.c +0 -0
index 44bfeecac33e..5fd6e8ed02b5 100644
@@ -127,7 +127,7 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
              if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))
                      return -EINVAL;
 
Quoted 6 lines

net/ipv4/gre_demux.c int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, · line 130

Quoted 2 lines
net/ipv4/gre_demux.c +1 -1
-             ershdr = (struct erspan_base_hdr *)options;
+             ershdr = (struct erspan_base_hdr *)(skb->data + nhs + hdr_len);

It seems to me that in the case of WCCPv2 hdr_len will be 4 bytes longer than where options would be advanced to. Is that a problem here?

Quoted 4 lines

Hi Simon,

I guess the two conditions are mutually exclusive since tpi->proto is initialized with greh->protocol. Am I missing something?

Thanks Lorenzo,

I see that now and agree that this patch is correct.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
net/ipv4/gre_demux.c +0 -1
              tpi->key = cpu_to_be32(get_session_id(ershdr));
      }
 
--

2.21.0

Acked-by on v1 1/1
#4 lore raw
In reply to Cong Wang
Quoted 8 lines

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Quoted 5 lines

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>
Quoted 20 lines
---
 net/ipv4/gre_demux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_demux.c +1 -2
index 44bfeecac33e..5fd6e8ed02b5 100644
@@ -127,7 +127,7 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
                if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))
                        return -EINVAL;
 
-               ershdr = (struct erspan_base_hdr *)options;
+               ershdr = (struct erspan_base_hdr *)(skb->data + nhs + hdr_len);
                tpi->key = cpu_to_be32(get_session_id(ershdr));
        }
 
--

2.21.0

Acked-by
#5 lore raw
Quoted 9 lines · Lorenzo Bianconi
Quoted 9 lines

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Quoted 8 lines
Quoted 5 lines

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>

LGTM.

From the spec, ERSPAN has fixed size GRE header, so I think WCCPv2 should not exist in ERSPAN.

maintainer
#6 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Thu, 5 Dec 2019 19:39:02 -0800

Quoted 7 lines

After pskb_may_pull() we should always refetch the header pointers from the skb->data in case it got reallocated.

In gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched before pskb_may_pull().

Quoted 5 lines

Found this during code review of a KMSAN bug report.

Fixes cb73ee40b1b3 ("net: ip_gre: use erspan key field for tunnel lookup")
Cc Lorenzo Bianconi <[email protected]>

Applied and queued up for -stable, thanks.