netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Where is this patch buried?
@ 2021-02-08  8:12 Schmid, Carsten
  2021-02-08  8:49 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Schmid, Carsten @ 2021-02-08  8:12 UTC (permalink / raw)
  To: Greg KH; +Cc: netdev

Hi Greg,

in kernel 4.14 i have seen a NULL pointer deref in
[65064.613465] RIP: 0010:ip_route_output_key_hash_rcu+0x755/0x850
(i have a core dump and detailed analysis)

That looks like this patch could have prevented it:

https://www.spinics.net/lists/stable-commits/msg133055.html

this one was queued for 4.14, but i can't find it in git tree?
Any idea who/what buried this one?

In 4.19 it is present.

Because our customer uses 4.14 (going to 4.14.212 in a few days) i kindly want to ask why this patch hasn't entered 4.14.

Best regards
Carsten
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

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

* Re: Where is this patch buried?
  2021-02-08  8:12 Where is this patch buried? Schmid, Carsten
@ 2021-02-08  8:49 ` Greg KH
  2021-02-08  9:24   ` AW: " Schmid, Carsten
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2021-02-08  8:49 UTC (permalink / raw)
  To: Schmid, Carsten; +Cc: netdev

On Mon, Feb 08, 2021 at 08:12:29AM +0000, Schmid, Carsten wrote:
> Hi Greg,
> 
> in kernel 4.14 i have seen a NULL pointer deref in
> [65064.613465] RIP: 0010:ip_route_output_key_hash_rcu+0x755/0x850
> (i have a core dump and detailed analysis)
> 
> That looks like this patch could have prevented it:
> 
> https://www.spinics.net/lists/stable-commits/msg133055.html
> 
> this one was queued for 4.14, but i can't find it in git tree?
> Any idea who/what buried this one?
> 
> In 4.19 it is present.
> 
> Because our customer uses 4.14 (going to 4.14.212 in a few days) i kindly want to ask why this patch hasn't entered 4.14.

Because it breaks the build?  Try it yourself and see what happens :)

I will gladly take a working backport if you can submit it.

thanks,

greg k-h

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

* AW: Where is this patch buried?
  2021-02-08  8:49 ` Greg KH
@ 2021-02-08  9:24   ` Schmid, Carsten
  2021-02-08  9:48     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Schmid, Carsten @ 2021-02-08  9:24 UTC (permalink / raw)
  To: Greg KH; +Cc: netdev, weiwan, idosch, jesse, kafai, dsahern, davem

[-- Attachment #1: Type: text/plain, Size: 1430 bytes --]

>> Hi Greg,
>>
>> in kernel 4.14 i have seen a NULL pointer deref in
>> [65064.613465] RIP: 0010:ip_route_output_key_hash_rcu+0x755/0x850
>> (i have a core dump and detailed analysis)
>>
>> That looks like this patch could have prevented it:
>>
>> https://www.spinics.net/lists/stable-commits/msg133055.html
>>
>> this one was queued for 4.14, but i can't find it in git tree?
>> Any idea who/what buried this one?
>>
>> In 4.19 it is present.
>>
>> Because our customer uses 4.14 (going to 4.14.212 in a few days) i kindly want to
>> ask why this patch hasn't entered 4.14.
>
> Because it breaks the build?  Try it yourself and see what happens :)

yep. rt_add_uncached_list is implemented _after_ the call :-(

>
> I will gladly take a working backport if you can submit it.
>
Please find it attached - i needed to move rt_add_uncached_list before
the rt_cache_route, nothing else changed.
This is for 4.14 only, as other kernels do have this patch.

I can't reproduce the crash at will, but at least i could compile and flash it on my target.
And the target comes up .. hopefully the testing in other/newer kernels
done by the developers of the patch is also valid for 4.14.

> thanks,
>
> greg k-h

Thanks,
Carsten
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ipv4-fix-race-condition-between-route-lookup-and-inv.patch --]
[-- Type: text/x-patch; name="0001-ipv4-fix-race-condition-between-route-lookup-and-inv.patch", Size: 4140 bytes --]

From 667f814207fc0aa9b3e620c733d1754ec522c447 Mon Sep 17 00:00:00 2001
From: Wei Wang <weiwan@google.com>
Date: Wed, 16 Oct 2019 12:03:15 -0700
Subject: [PATCH] ipv4: fix race condition between route lookup and
 invalidation

[ upstream commit 5018c59607a511cdee743b629c76206d9c9e6d7b ]

Jesse and Ido reported the following race condition:
<CPU A, t0> - Received packet A is forwarded and cached dst entry is
taken from the nexthop ('nhc->nhc_rth_input'). Calls skb_dst_set()

<t1> - Given Jesse has busy routers ("ingesting full BGP routing tables
from multiple ISPs"), route is added / deleted and rt_cache_flush() is
called

<CPU B, t2> - Received packet B tries to use the same cached dst entry
from t0, but rt_cache_valid() is no longer true and it is replaced in
rt_cache_route() by the newer one. This calls dst_dev_put() on the
original dst entry which assigns the blackhole netdev to 'dst->dev'

<CPU A, t3> - dst_input(skb) is called on packet A and it is dropped due
to 'dst->dev' being the blackhole netdev

There are 2 issues in the v4 routing code:
1. A per-netns counter is used to do the validation of the route. That
means whenever a route is changed in the netns, users of all routes in
the netns needs to redo lookup. v6 has an implementation of only
updating fn_sernum for routes that are affected.
2. When rt_cache_valid() returns false, rt_cache_route() is called to
throw away the current cache, and create a new one. This seems
unnecessary because as long as this route does not change, the route
cache does not need to be recreated.

To fully solve the above 2 issues, it probably needs quite some code
changes and requires careful testing, and does not suite for net branch.

So this patch only tries to add the deleted cached rt into the uncached
list, so user could still be able to use it to receive packets until
it's done.

Fixes: 95c47f9cf5e0 ("ipv4: call dst_dev_put() properly")
Signed-off-by: Wei Wang <weiwan@google.com>
Reported-by: Ido Schimmel <idosch@idosch.org>
Reported-by: Jesse Hathaway <jesse@mbuki-mvuki.org>
Tested-by: Jesse Hathaway <jesse@mbuki-mvuki.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Cc: David Ahern <dsahern@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Carsten Schmid <carsten_schmid@mentor.com>
---
 net/ipv4/route.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index c25b3be78e02..7eb8f3048c86 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1432,6 +1432,24 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
 	return ret;
 }
 
+struct uncached_list {
+	spinlock_t		lock;
+	struct list_head	head;
+};
+
+static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt_uncached_list);
+
+static void rt_add_uncached_list(struct rtable *rt)
+{
+	struct uncached_list *ul = raw_cpu_ptr(&rt_uncached_list);
+
+	rt->rt_uncached_list = ul;
+
+	spin_lock_bh(&ul->lock);
+	list_add_tail(&rt->rt_uncached, &ul->head);
+	spin_unlock_bh(&ul->lock);
+}
+
 static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt)
 {
 	struct rtable *orig, *prev, **p;
@@ -1451,7 +1469,7 @@ static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt)
 	prev = cmpxchg(p, orig, rt);
 	if (prev == orig) {
 		if (orig) {
-			dst_dev_put(&orig->dst);
+			rt_add_uncached_list(orig);
 			dst_release(&orig->dst);
 		}
 	} else {
@@ -1462,24 +1480,6 @@ static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt)
 	return ret;
 }
 
-struct uncached_list {
-	spinlock_t		lock;
-	struct list_head	head;
-};
-
-static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt_uncached_list);
-
-static void rt_add_uncached_list(struct rtable *rt)
-{
-	struct uncached_list *ul = raw_cpu_ptr(&rt_uncached_list);
-
-	rt->rt_uncached_list = ul;
-
-	spin_lock_bh(&ul->lock);
-	list_add_tail(&rt->rt_uncached, &ul->head);
-	spin_unlock_bh(&ul->lock);
-}
-
 static void ipv4_dst_destroy(struct dst_entry *dst)
 {
 	struct dst_metrics *p = (struct dst_metrics *)DST_METRICS_PTR(dst);
-- 
2.17.1


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

* Re: Where is this patch buried?
  2021-02-08  9:24   ` AW: " Schmid, Carsten
@ 2021-02-08  9:48     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-02-08  9:48 UTC (permalink / raw)
  To: Schmid, Carsten; +Cc: netdev, weiwan, idosch, jesse, kafai, dsahern, davem

On Mon, Feb 08, 2021 at 09:24:11AM +0000, Schmid, Carsten wrote:
> >> Hi Greg,
> >>
> >> in kernel 4.14 i have seen a NULL pointer deref in
> >> [65064.613465] RIP: 0010:ip_route_output_key_hash_rcu+0x755/0x850
> >> (i have a core dump and detailed analysis)
> >>
> >> That looks like this patch could have prevented it:
> >>
> >> https://www.spinics.net/lists/stable-commits/msg133055.html
> >>
> >> this one was queued for 4.14, but i can't find it in git tree?
> >> Any idea who/what buried this one?
> >>
> >> In 4.19 it is present.
> >>
> >> Because our customer uses 4.14 (going to 4.14.212 in a few days) i kindly want to
> >> ask why this patch hasn't entered 4.14.
> >
> > Because it breaks the build?  Try it yourself and see what happens :)
> 
> yep. rt_add_uncached_list is implemented _after_ the call :-(
> 
> >
> > I will gladly take a working backport if you can submit it.
> >
> Please find it attached - i needed to move rt_add_uncached_list before
> the rt_cache_route, nothing else changed.
> This is for 4.14 only, as other kernels do have this patch.
> 
> I can't reproduce the crash at will, but at least i could compile and flash it on my target.
> And the target comes up .. hopefully the testing in other/newer kernels
> done by the developers of the patch is also valid for 4.14.

Thanks, now queued up.

greg k-h

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

end of thread, other threads:[~2021-02-08  9:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08  8:12 Where is this patch buried? Schmid, Carsten
2021-02-08  8:49 ` Greg KH
2021-02-08  9:24   ` AW: " Schmid, Carsten
2021-02-08  9:48     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).