* [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head()
@ 2018-07-13 5:40 Prashant Bhole
2018-07-13 20:45 ` Gregory Rose
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Prashant Bhole @ 2018-07-13 5:40 UTC (permalink / raw)
To: David S . Miller
Cc: Prashant Bhole, Alexey Kuznetsov, Hideaki YOSHIFUJI, William Tu, netdev
A KASAN:use-after-free bug was found related to ip6-erspan
while running selftests/net/ip6_gre_headroom.sh
It happens because of following sequence:
- ipv6hdr pointer is obtained from skb
- skb_cow_head() is called, skb->head memory is reallocated
- old data is accessed using ipv6hdr pointer
skb_cow_head() call was added in e41c7c68ea77 ("ip6erspan: make sure
enough headroom at xmit."), but looking at the history there was a
chance of similar bug because gre_handle_offloads() and pskb_trim()
can also reallocate skb->head memory. Fixes tag points to commit
which introduced possibility of this bug.
This patch moves ipv6hdr pointer assignment after skb_cow_head() call.
Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
---
net/ipv6/ip6_gre.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 367177786e34..fc7dd3a04360 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -927,7 +927,6 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
struct net_device *dev)
{
- struct ipv6hdr *ipv6h = ipv6_hdr(skb);
struct ip6_tnl *t = netdev_priv(dev);
struct dst_entry *dst = skb_dst(skb);
struct net_device_stats *stats;
@@ -1012,6 +1011,8 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
goto tx_err;
}
} else {
+ struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+
switch (skb->protocol) {
case htons(ETH_P_IP):
memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head()
2018-07-13 5:40 [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head() Prashant Bhole
@ 2018-07-13 20:45 ` Gregory Rose
2018-07-13 22:39 ` William Tu
2018-07-16 20:40 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Gregory Rose @ 2018-07-13 20:45 UTC (permalink / raw)
To: Prashant Bhole, David S . Miller
Cc: Alexey Kuznetsov, Hideaki YOSHIFUJI, William Tu, netdev
On 7/12/2018 10:40 PM, Prashant Bhole wrote:
> A KASAN:use-after-free bug was found related to ip6-erspan
> while running selftests/net/ip6_gre_headroom.sh
>
> It happens because of following sequence:
> - ipv6hdr pointer is obtained from skb
> - skb_cow_head() is called, skb->head memory is reallocated
> - old data is accessed using ipv6hdr pointer
>
> skb_cow_head() call was added in e41c7c68ea77 ("ip6erspan: make sure
> enough headroom at xmit."), but looking at the history there was a
> chance of similar bug because gre_handle_offloads() and pskb_trim()
> can also reallocate skb->head memory. Fixes tag points to commit
> which introduced possibility of this bug.
>
> This patch moves ipv6hdr pointer assignment after skb_cow_head() call.
>
> Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
> Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Good catch.
LGTM
Reviewed-by: Greg Rose <gvrose8192@gmail.com>
> ---
> net/ipv6/ip6_gre.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index 367177786e34..fc7dd3a04360 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -927,7 +927,6 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
> static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
> struct net_device *dev)
> {
> - struct ipv6hdr *ipv6h = ipv6_hdr(skb);
> struct ip6_tnl *t = netdev_priv(dev);
> struct dst_entry *dst = skb_dst(skb);
> struct net_device_stats *stats;
> @@ -1012,6 +1011,8 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
> goto tx_err;
> }
> } else {
> + struct ipv6hdr *ipv6h = ipv6_hdr(skb);
> +
> switch (skb->protocol) {
> case htons(ETH_P_IP):
> memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head()
2018-07-13 5:40 [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head() Prashant Bhole
2018-07-13 20:45 ` Gregory Rose
@ 2018-07-13 22:39 ` William Tu
2018-07-16 20:40 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: William Tu @ 2018-07-13 22:39 UTC (permalink / raw)
To: Prashant Bhole
Cc: David S . Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI,
Linux Kernel Network Developers
On Thu, Jul 12, 2018 at 10:40 PM, Prashant Bhole
<bhole_prashant_q7@lab.ntt.co.jp> wrote:
> A KASAN:use-after-free bug was found related to ip6-erspan
> while running selftests/net/ip6_gre_headroom.sh
>
> It happens because of following sequence:
> - ipv6hdr pointer is obtained from skb
> - skb_cow_head() is called, skb->head memory is reallocated
> - old data is accessed using ipv6hdr pointer
>
> skb_cow_head() call was added in e41c7c68ea77 ("ip6erspan: make sure
> enough headroom at xmit."), but looking at the history there was a
> chance of similar bug because gre_handle_offloads() and pskb_trim()
> can also reallocate skb->head memory. Fixes tag points to commit
> which introduced possibility of this bug.
>
> This patch moves ipv6hdr pointer assignment after skb_cow_head() call.
>
> Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
> Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
> ---
Thanks for the fix.
Acked-by: William Tu <u9012063@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head()
2018-07-13 5:40 [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head() Prashant Bhole
2018-07-13 20:45 ` Gregory Rose
2018-07-13 22:39 ` William Tu
@ 2018-07-16 20:40 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-16 20:40 UTC (permalink / raw)
To: bhole_prashant_q7; +Cc: kuznet, yoshfuji, u9012063, netdev
From: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Date: Fri, 13 Jul 2018 14:40:50 +0900
> A KASAN:use-after-free bug was found related to ip6-erspan
> while running selftests/net/ip6_gre_headroom.sh
>
> It happens because of following sequence:
> - ipv6hdr pointer is obtained from skb
> - skb_cow_head() is called, skb->head memory is reallocated
> - old data is accessed using ipv6hdr pointer
>
> skb_cow_head() call was added in e41c7c68ea77 ("ip6erspan: make sure
> enough headroom at xmit."), but looking at the history there was a
> chance of similar bug because gre_handle_offloads() and pskb_trim()
> can also reallocate skb->head memory. Fixes tag points to commit
> which introduced possibility of this bug.
>
> This patch moves ipv6hdr pointer assignment after skb_cow_head() call.
>
> Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
> Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
This bug goes back to 4.16, therefore applied to 'net' and queued up
for -stable.
Please do not submit bug fixes against 'net-next' in this situation
in the future.
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-16 21:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-13 5:40 [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head() Prashant Bhole
2018-07-13 20:45 ` Gregory Rose
2018-07-13 22:39 ` William Tu
2018-07-16 20:40 ` 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.