* [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
@ 2019-12-06 3:39 Cong Wang
2019-12-06 10:42 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Cong Wang @ 2019-12-06 3:39 UTC (permalink / raw)
To: netdev; +Cc: Cong Wang, Lorenzo Bianconi
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 <lorenzo.bianconi@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
net/ipv4/gre_demux.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
index 44bfeecac33e..5fd6e8ed02b5 100644
--- a/net/ipv4/gre_demux.c
+++ b/net/ipv4/gre_demux.c
@@ -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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
2019-12-06 3:39 [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull() Cong Wang
@ 2019-12-06 10:42 ` Simon Horman
2019-12-06 11:55 ` Lorenzo Bianconi
2019-12-06 11:49 ` Lorenzo Bianconi
2019-12-07 19:54 ` David Miller
2 siblings, 1 reply; 7+ messages in thread
From: Simon Horman @ 2019-12-06 10:42 UTC (permalink / raw)
To: Cong Wang; +Cc: netdev, Lorenzo Bianconi
Hi Cong,
On Thu, Dec 05, 2019 at 07:39:02PM -0800, Cong Wang wrote:
> 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 <lorenzo.bianconi@redhat.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> net/ipv4/gre_demux.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
> index 44bfeecac33e..5fd6e8ed02b5 100644
> --- a/net/ipv4/gre_demux.c
> +++ b/net/ipv4/gre_demux.c
> @@ -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?
> tpi->key = cpu_to_be32(get_session_id(ershdr));
> }
>
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
2019-12-06 3:39 [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull() Cong Wang
2019-12-06 10:42 ` Simon Horman
@ 2019-12-06 11:49 ` Lorenzo Bianconi
2019-12-06 17:08 ` William Tu
2019-12-07 19:54 ` David Miller
2 siblings, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2019-12-06 11:49 UTC (permalink / raw)
To: Cong Wang; +Cc: Network Development
>
> 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 <lorenzo.bianconi@redhat.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
> net/ipv4/gre_demux.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
> index 44bfeecac33e..5fd6e8ed02b5 100644
> --- a/net/ipv4/gre_demux.c
> +++ b/net/ipv4/gre_demux.c
> @@ -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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
2019-12-06 10:42 ` Simon Horman
@ 2019-12-06 11:55 ` Lorenzo Bianconi
2019-12-07 17:04 ` Simon Horman
0 siblings, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2019-12-06 11:55 UTC (permalink / raw)
To: Simon Horman; +Cc: Cong Wang, Network Development
>
> Hi Cong,
>
> On Thu, Dec 05, 2019 at 07:39:02PM -0800, Cong Wang wrote:
> > 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 <lorenzo.bianconi@redhat.com>
> > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> > ---
> > net/ipv4/gre_demux.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
> > index 44bfeecac33e..5fd6e8ed02b5 100644
> > --- a/net/ipv4/gre_demux.c
> > +++ b/net/ipv4/gre_demux.c
> > @@ -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?
>
Hi Simon,
I guess the two conditions are mutually exclusive since tpi->proto is
initialized with greh->protocol. Am I missing something?
Regards,
Lorenzo
> > tpi->key = cpu_to_be32(get_session_id(ershdr));
> > }
> >
> > --
> > 2.21.0
> >
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
2019-12-06 11:49 ` Lorenzo Bianconi
@ 2019-12-06 17:08 ` William Tu
0 siblings, 0 replies; 7+ messages in thread
From: William Tu @ 2019-12-06 17:08 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: Cong Wang, Network Development
On Fri, Dec 6, 2019 at 3:50 AM Lorenzo Bianconi
<lorenzo.bianconi@redhat.com> wrote:
>
> >
> > 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 <lorenzo.bianconi@redhat.com>
> > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
>
> Acked-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>
LGTM.
Acked-by: William Tu <u9012063@gmail.com>
From the spec, ERSPAN has fixed size GRE header, so I think
WCCPv2 should not exist in ERSPAN.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
2019-12-06 11:55 ` Lorenzo Bianconi
@ 2019-12-07 17:04 ` Simon Horman
0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2019-12-07 17:04 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: Cong Wang, Network Development
On Fri, Dec 06, 2019 at 01:55:25PM +0200, Lorenzo Bianconi wrote:
> >
> > Hi Cong,
> >
> > On Thu, Dec 05, 2019 at 07:39:02PM -0800, Cong Wang wrote:
> > > 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 <lorenzo.bianconi@redhat.com>
> > > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> > > ---
> > > net/ipv4/gre_demux.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
> > > index 44bfeecac33e..5fd6e8ed02b5 100644
> > > --- a/net/ipv4/gre_demux.c
> > > +++ b/net/ipv4/gre_demux.c
> > > @@ -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?
> >
>
> 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.
Reviewed-by: Simon Horman <simon.horman@netronome.com>
> > > tpi->key = cpu_to_be32(get_session_id(ershdr));
> > > }
> > >
> > > --
> > > 2.21.0
> > >
> >
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull()
2019-12-06 3:39 [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull() Cong Wang
2019-12-06 10:42 ` Simon Horman
2019-12-06 11:49 ` Lorenzo Bianconi
@ 2019-12-07 19:54 ` David Miller
2 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2019-12-07 19:54 UTC (permalink / raw)
To: xiyou.wangcong; +Cc: netdev, lorenzo.bianconi
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Thu, 5 Dec 2019 19:39:02 -0800
> 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 <lorenzo.bianconi@redhat.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-12-07 19:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 3:39 [Patch net] gre: refetch erspan header from skb->data after pskb_may_pull() Cong Wang
2019-12-06 10:42 ` Simon Horman
2019-12-06 11:55 ` Lorenzo Bianconi
2019-12-07 17:04 ` Simon Horman
2019-12-06 11:49 ` Lorenzo Bianconi
2019-12-06 17:08 ` William Tu
2019-12-07 19:54 ` 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.