Skip to content

Commit

Permalink
net: tunnels should use rcu_dereference
Browse files Browse the repository at this point in the history
tunnel4_handlers, tunnel64_handlers, tunnel6_handlers and
tunnel46_handlers are protected by RCU, but we dont use appropriate rcu
primitives to scan them. rcu_lock() is already held by caller.

Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Sep 1, 2010
1 parent 0642701 commit 875168a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions net/ipv4/tunnel4.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,19 @@ int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family)
}
EXPORT_SYMBOL(xfrm4_tunnel_deregister);

#define for_each_tunnel_rcu(head, handler) \
for (handler = rcu_dereference(head); \
handler != NULL; \
handler = rcu_dereference(handler->next)) \

static int tunnel4_rcv(struct sk_buff *skb)
{
struct xfrm_tunnel *handler;

if (!pskb_may_pull(skb, sizeof(struct iphdr)))
goto drop;

for (handler = tunnel4_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel4_handlers, handler)
if (!handler->handler(skb))
return 0;

Expand All @@ -99,7 +104,7 @@ static int tunnel64_rcv(struct sk_buff *skb)
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
goto drop;

for (handler = tunnel64_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel64_handlers, handler)
if (!handler->handler(skb))
return 0;

Expand All @@ -115,7 +120,7 @@ static void tunnel4_err(struct sk_buff *skb, u32 info)
{
struct xfrm_tunnel *handler;

for (handler = tunnel4_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel4_handlers, handler)
if (!handler->err_handler(skb, info))
break;
}
Expand All @@ -125,7 +130,7 @@ static void tunnel64_err(struct sk_buff *skb, u32 info)
{
struct xfrm_tunnel *handler;

for (handler = tunnel64_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel64_handlers, handler)
if (!handler->err_handler(skb, info))
break;
}
Expand Down
11 changes: 8 additions & 3 deletions net/ipv6/tunnel6.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,19 @@ int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family)

EXPORT_SYMBOL(xfrm6_tunnel_deregister);

#define for_each_tunnel_rcu(head, handler) \
for (handler = rcu_dereference(head); \
handler != NULL; \
handler = rcu_dereference(handler->next)) \

static int tunnel6_rcv(struct sk_buff *skb)
{
struct xfrm6_tunnel *handler;

if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
goto drop;

for (handler = tunnel6_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel6_handlers, handler)
if (!handler->handler(skb))
return 0;

Expand All @@ -113,7 +118,7 @@ static int tunnel46_rcv(struct sk_buff *skb)
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
goto drop;

for (handler = tunnel46_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel46_handlers, handler)
if (!handler->handler(skb))
return 0;

Expand All @@ -129,7 +134,7 @@ static void tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
{
struct xfrm6_tunnel *handler;

for (handler = tunnel6_handlers; handler; handler = handler->next)
for_each_tunnel_rcu(tunnel6_handlers, handler)
if (!handler->err_handler(skb, opt, type, code, offset, info))
break;
}
Expand Down

0 comments on commit 875168a

Please sign in to comment.