From: Cong Wang <xiyou.wangcong@gmail.com>
To: netdev@vger.kernel.org
Cc: andreyknvl@google.com, edumazet@google.com,
Cong Wang <xiyou.wangcong@gmail.com>
Subject: [Patch net] ipv4: restore rt->fi for reference counting
Date: Thu, 4 May 2017 14:54:17 -0700 [thread overview]
Message-ID: <1493934857-6693-1-git-send-email-xiyou.wangcong@gmail.com> (raw)
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 <andreyknvl@google.com>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
include/net/route.h | 1 +
net/ipv4/route.c | 18 +++++++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/net/route.h b/include/net/route.h
index 2cc0e14..4335eb7 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -69,6 +69,7 @@ struct rtable {
struct list_head rt_uncached;
struct uncached_list *rt_uncached_list;
+ struct fib_info *fi; /* for refcnt to shared metrics */
};
static inline bool rt_is_input_route(const struct rtable *rt)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 655d9ee..f647310 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1387,6 +1387,11 @@ static void ipv4_dst_destroy(struct dst_entry *dst)
{
struct rtable *rt = (struct rtable *) dst;
+ if (rt->fi) {
+ fib_info_put(rt->fi);
+ rt->fi = NULL;
+ }
+
if (!list_empty(&rt->rt_uncached)) {
struct uncached_list *ul = rt->rt_uncached_list;
@@ -1424,6 +1429,16 @@ static bool rt_cache_valid(const struct rtable *rt)
!rt_is_expired(rt);
}
+static void rt_init_metrics(struct rtable *rt, struct fib_info *fi)
+{
+ if (fi->fib_metrics != (u32 *)dst_default_metrics) {
+ fib_info_hold(fi);
+ rt->fi = fi;
+ }
+
+ dst_init_metrics(&rt->dst, fi->fib_metrics, true);
+}
+
static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
const struct fib_result *res,
struct fib_nh_exception *fnhe,
@@ -1438,7 +1453,7 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
rt->rt_gateway = nh->nh_gw;
rt->rt_uses_gateway = 1;
}
- dst_init_metrics(&rt->dst, fi->fib_metrics, true);
+ rt_init_metrics(rt, fi);
#ifdef CONFIG_IP_ROUTE_CLASSID
rt->dst.tclassid = nh->nh_tclassid;
#endif
@@ -1490,6 +1505,7 @@ struct rtable *rt_dst_alloc(struct net_device *dev,
rt->rt_gateway = 0;
rt->rt_uses_gateway = 0;
rt->rt_table_id = 0;
+ rt->fi = NULL;
INIT_LIST_HEAD(&rt->rt_uncached);
rt->dst.output = ip_output;
--
2.5.5
next reply other threads:[~2017-05-04 21:54 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 21:54 Cong Wang [this message]
2017-05-07 18:53 ` [Patch net] ipv4: restore rt->fi for reference counting Eric Dumazet
2017-05-08 18:35 ` David Miller
2017-05-09 0:01 ` Eric Dumazet
2017-05-09 1:22 ` David Miller
2017-05-09 2:18 ` Eric Dumazet
2017-05-09 2:35 ` David Miller
2017-05-09 16:44 ` Cong Wang
2017-05-09 16:56 ` Eric Dumazet
2017-05-09 20:56 ` Cong Wang
2017-05-09 22:07 ` Cong Wang
2017-05-09 22:52 ` Eric Dumazet
2017-05-09 22:54 ` Eric Dumazet
2017-05-09 23:09 ` Eric Dumazet
2017-05-09 23:35 ` Cong Wang
2017-05-09 23:50 ` Eric Dumazet
2017-05-10 16:32 ` Cong Wang
2017-05-09 23:51 ` Eric Dumazet
2017-05-10 16:40 ` Cong Wang
2017-05-10 7:38 ` Julian Anastasov
2017-05-10 17:00 ` Cong Wang
2017-05-10 19:51 ` Julian Anastasov
2017-05-12 0:07 ` Cong Wang
2017-05-12 1:22 ` Cong Wang
2017-05-12 4:55 ` Eric Dumazet
2017-05-12 17:49 ` Cong Wang
2017-05-12 6:39 ` Julian Anastasov
2017-05-12 17:27 ` Cong Wang
2017-05-12 20:58 ` Cong Wang
2017-05-12 21:13 ` Cong Wang
2017-05-12 21:27 ` Julian Anastasov
2017-05-15 18:34 ` Cong Wang
2017-05-15 20:37 ` Julian Anastasov
2017-05-15 22:13 ` Cong Wang
2017-05-16 7:46 ` Julian Anastasov
2017-05-16 17:53 ` Cong Wang
2017-05-16 18:16 ` Cong Wang
[not found] ` <1495572267.6465.79.camel@edumazet-glaptop3.roam.corp.google.com>
[not found] ` <CAM_iQpX0X3h4Sf+bHUXdJgBqUTxNat0FBT0PeRpLYWju9ci59Q@mail.gmail.com>
[not found] ` <CANn89i+mPR+7-AVO2Dsd=KfO=COOVY42AKjwEs=0=GUCML6HUQ@mail.gmail.com>
[not found] ` <CAM_iQpUfLmN3yWsCfpx4ZTptBnuYFNuY5CjBKdwoDpvH5K8P=w@mail.gmail.com>
[not found] ` <1495665921.6465.95.camel@edumazet-glaptop3.roam.corp.google.com>
2017-05-25 21:27 ` [PATCH net] ipv4: add reference counting to metrics Eric Dumazet
2017-05-25 22:25 ` Julian Anastasov
2017-05-26 17:08 ` Cong Wang
2017-05-26 17:13 ` Eric Dumazet
2017-05-26 17:26 ` Cong Wang
2017-05-26 18:58 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1493934857-6693-1-git-send-email-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=andreyknvl@google.com \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).