[lkml]   [2017]   [Aug]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 3.16 119/134] ipv4: restore rt->fi for reference counting
On Fri, Aug 18, 2017 at 6:13 AM, Ben Hutchings <> wrote:
> 3.16.47-rc1 review patch. If anyone has any objections, please let me know.
> ------------------
> From: WANG Cong <>
> commit 82486aa6f1b9bc8145e6d0fa2bc0b44307f3b875 upstream.
> IPv4 dst could use fi->fib_metrics to store metrics but fib_info
> itself is refcnt'ed, so without taking a refcnt fi and
> fi->fib_metrics could be freed while dst metrics still points to
> it. This triggers use-after-free as reported by Andrey twice.
> This patch reverts commit 2860583fe840 ("ipv4: Kill rt->fi") to
> restore this reference counting. It is a quick fix for -net and
> -stable, for -net-next, as Eric suggested, we can consider doing
> reference counting for metrics itself instead of relying on fib_info.
> IPv6 is very different, it copies or steals the metrics from mx6_config
> in fib6_commit_metrics() so probably doesn't need a refcnt.
> Decnet has already done the refcnt'ing, see dn_fib_semantic_match().
> Fixes: 2860583fe840 ("ipv4: Kill rt->fi")
> Reported-by: Andrey Konovalov <>
> Tested-by: Andrey Konovalov <>
> Signed-off-by: Cong Wang <>
> Acked-by: Eric Dumazet <>
> Signed-off-by: David S. Miller <>
> [bwh: Backported to 3.16:
> - Update all 5 places where rtable is initialised
> - Open-code fib_info_hold()
> - Adjust context]
> Signed-off-by: Ben Hutchings <>
> ---

I thought we refined this later with :

commit 3fb07daff8e99243366a081e5129560734de4ada
Author: Eric Dumazet <>
Date: Thu May 25 14:27:35 2017 -0700

ipv4: add reference counting to metrics

Andrey Konovalov reported crashes in ipv4_mtu()

I could reproduce the issue with KASAN kernels, between and :

1) 20 concurrent netperf -t TCP_RR -H -l 1000 &

2) At the same time run following loop :
while :
ip ro add dev eth0 src mtu 1500
ip ro del dev eth0 src mtu 1500

Cong Wang attempted to add back rt->fi in commit
82486aa6f1b9 ("ipv4: restore rt->fi for reference counting")
but this proved to add some issues that were complex to solve.

Instead, I suggested to add a refcount to the metrics themselves,
being a standalone object (in particular, no reference to other objects)

I tried to make this patch as small as possible to ease its backport,
instead of being super clean. Note that we believe that only ipv4 dst
need to take care of the metric refcount. But if this is wrong,
this patch adds the basic infrastructure to extend this to other

Many thanks to Julian Anastasov for reviewing this patch, and Cong Wang
for his efforts on this problem.

Fixes: 2860583fe840 ("ipv4: Kill rt->fi")
Signed-off-by: Eric Dumazet <>
Reported-by: Andrey Konovalov <>
Reviewed-by: Julian Anastasov <>
Acked-by: Cong Wang <>
Signed-off-by: David S. Miller <>

And then :

commit 187e5b3ac84d3421d2de3aca949b2791fbcad554
Author: Eric Dumazet <>
Date: Tue Aug 15 05:26:17 2017 -0700

ipv4: fix NULL dereference in free_fib_info_rcu()

If fi->fib_metrics could not be allocated in fib_create_info()
we attempt to dereference a NULL pointer in free_fib_info_rcu() :

m = fi->fib_metrics;
if (m != &dst_default_metrics && atomic_dec_and_test(&m->refcnt))

Before my recent patch, we used to call kfree(NULL) and nothing wrong

Instead of using RCU to defer freeing while we are under memory stress,
it seems better to take immediate action.

This was reported by syzkaller team.

Fixes: 3fb07daff8e9 ("ipv4: add reference counting to metrics")
Signed-off-by: Eric Dumazet <>
Reported-by: Dmitry Vyukov <>
Signed-off-by: David S. Miller <>

 \ /
  Last update: 2017-08-18 15:53    [W:0.353 / U:3.732 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site