diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-12-06 12:29:43 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-12-06 12:29:43 -0500 |
commit | 46bcf14f44d8f31ecfdc8b6708ec15a3b33316d9 (patch) | |
tree | 4d2a200387242e1ed2d95ccd367c77750379e8cc /include | |
parent | e7dfc8dbdf9a7fa1ef04c63100a71f4102b82ed3 (diff) |
filter: fix sk_filter rcu handling
Pavel Emelyanov tried to fix a race between sk_filter_(de|at)tach and
sk_clone() in commit 47e958eac280c263397
Problem is we can have several clones sharing a common sk_filter, and
these clones might want to sk_filter_attach() their own filters at the
same time, and can overwrite old_filter->rcu, corrupting RCU queues.
We can not use filter->rcu without being sure no other thread could do
the same thing.
Switch code to a more conventional ref-counting technique : Do the
atomic decrement immediately and queue one rcu call back when last
reference is released.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/net/sock.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index a6338d039857..659d968d95c5 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -1155,6 +1155,8 @@ extern void sk_common_release(struct sock *sk); | |||
1155 | /* Initialise core socket variables */ | 1155 | /* Initialise core socket variables */ |
1156 | extern void sock_init_data(struct socket *sock, struct sock *sk); | 1156 | extern void sock_init_data(struct socket *sock, struct sock *sk); |
1157 | 1157 | ||
1158 | extern void sk_filter_release_rcu(struct rcu_head *rcu); | ||
1159 | |||
1158 | /** | 1160 | /** |
1159 | * sk_filter_release - release a socket filter | 1161 | * sk_filter_release - release a socket filter |
1160 | * @fp: filter to remove | 1162 | * @fp: filter to remove |
@@ -1165,7 +1167,7 @@ extern void sock_init_data(struct socket *sock, struct sock *sk); | |||
1165 | static inline void sk_filter_release(struct sk_filter *fp) | 1167 | static inline void sk_filter_release(struct sk_filter *fp) |
1166 | { | 1168 | { |
1167 | if (atomic_dec_and_test(&fp->refcnt)) | 1169 | if (atomic_dec_and_test(&fp->refcnt)) |
1168 | kfree(fp); | 1170 | call_rcu_bh(&fp->rcu, sk_filter_release_rcu); |
1169 | } | 1171 | } |
1170 | 1172 | ||
1171 | static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp) | 1173 | static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp) |