ipv6: add rcu grace period before freeing fib6_node
We currently keep rt->rt6i_node pointing to the fib6_node for the route. And some functions make use of this pointer to dereference the fib6_node from rt structure, e.g. rt6_check(). However, as there is neither refcount nor rcu taken when dereferencing rt->rt6i_node, it could potentially cause crashes as rt->rt6i_node could be set to NULL by other CPUs when doing a route deletion. This patch introduces an rcu grace period before freeing fib6_node and makes sure the functions that dereference it takes rcu_read_lock(). Note: there is no "Fixes" tag because this bug was there in a very early stage. Signed-off-by: Wei Wang <weiwan@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
0c8d2d95b8
commit
c5cff8561d
@@ -70,6 +70,7 @@ struct fib6_node {
|
||||
__u16 fn_flags;
|
||||
int fn_sernum;
|
||||
struct rt6_info *rr_ptr;
|
||||
struct rcu_head rcu;
|
||||
};
|
||||
|
||||
#ifndef CONFIG_IPV6_SUBTREES
|
||||
@@ -167,13 +168,40 @@ static inline void rt6_update_expires(struct rt6_info *rt0, int timeout)
|
||||
rt0->rt6i_flags |= RTF_EXPIRES;
|
||||
}
|
||||
|
||||
/* Function to safely get fn->sernum for passed in rt
|
||||
* and store result in passed in cookie.
|
||||
* Return true if we can get cookie safely
|
||||
* Return false if not
|
||||
*/
|
||||
static inline bool rt6_get_cookie_safe(const struct rt6_info *rt,
|
||||
u32 *cookie)
|
||||
{
|
||||
struct fib6_node *fn;
|
||||
bool status = false;
|
||||
|
||||
rcu_read_lock();
|
||||
fn = rcu_dereference(rt->rt6i_node);
|
||||
|
||||
if (fn) {
|
||||
*cookie = fn->fn_sernum;
|
||||
status = true;
|
||||
}
|
||||
|
||||
rcu_read_unlock();
|
||||
return status;
|
||||
}
|
||||
|
||||
static inline u32 rt6_get_cookie(const struct rt6_info *rt)
|
||||
{
|
||||
u32 cookie = 0;
|
||||
|
||||
if (rt->rt6i_flags & RTF_PCPU ||
|
||||
(unlikely(!list_empty(&rt->rt6i_uncached)) && rt->dst.from))
|
||||
rt = (struct rt6_info *)(rt->dst.from);
|
||||
|
||||
return rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
|
||||
rt6_get_cookie_safe(rt, &cookie);
|
||||
|
||||
return cookie;
|
||||
}
|
||||
|
||||
static inline void ip6_rt_put(struct rt6_info *rt)
|
||||
|
Reference in New Issue
Block a user