gre: refetch erspan header from skb->data after pskb_may_pull()
Subsystems (2)
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.
--- net/ipv4/gre_demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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); tpi->key =cpu_to_be32 (get_session_id (ershdr)); }
Signature · 1 line
2.21.0
Hi Cong,
Quoted 21 lines · Cong Wang
After
pskb_may_pull()we should always refetch the header pointers from theskb->datain case it got reallocated.In
gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched beforepskb_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]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/gre_demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/gre_demux.c +0
-0
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
-0tpi->key =cpu_to_be32 (get_session_id (ershdr)); }Signature · 1 line
2.21.0
Quoted 28 lines
Hi Cong,
Quoted 24 lines · Cong Wang
After
pskb_may_pull()we should always refetch the header pointers from theskb->datain case it got reallocated.In
gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched beforepskb_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]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/gre_demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/gre_demux.c +0
-0@@ -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_lenwill 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
-1tpi->key =cpu_to_be32 (get_session_id (ershdr)); } --2.21.0
Simon Horman
Reviewed-byQuoted 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 theskb->datain case it got reallocated.In
gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched beforepskb_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]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/gre_demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/gre_demux.c +0
-0@@ -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_lenwill 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->protois initialized withgreh->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
-1tpi->key =cpu_to_be32 (get_session_id (ershdr)); } --2.21.0
Quoted 8 lines
After
pskb_may_pull()we should always refetch the header pointers from theskb->datain case it got reallocated.In
gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched beforepskb_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]>Signed-off-by Cong Wang <[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@@ -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
William Tu
Acked-byQuoted 9 lines · Lorenzo Bianconi
Quoted 9 lines
After
pskb_may_pull()we should always refetch the header pointers from theskb->datain case it got reallocated.In
gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched beforepskb_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]>Signed-off-by Cong Wang <[email protected]>Acked-by Lorenzo Bianconi <[email protected]>
LGTM.
From the spec, ERSPAN has fixed size GRE header, so I think WCCPv2 should not exist in ERSPAN.
David Miller
maintainerFrom: 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 theskb->datain case it got reallocated.In
gre_parse_header(), the erspan header is still fetched from the 'options' pointer which is fetched beforepskb_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]>Signed-off-by Cong Wang <[email protected]>
Applied and queued up for -stable, thanks.