aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2010-05-10 12:47:57 -0400
committerPatrick McHardy <kaber@trash.net>2010-05-10 12:47:57 -0400
commitb56f2d55c6c22b0c5774b3b22e336fb6cc5f4094 (patch)
treec6c208c4ea554307b35f26d6ec9eb63a0a28c626 /net
parent1e4b1057121bc756b91758a434b504d2010f6088 (diff)
netfilter: use rcu_dereference_protected()
Restore the rcu_dereference() calls in conntrack/expectation notifier and logger registration/unregistration, but use the _protected variant, which will be required by the upcoming __rcu annotations. Based on patch by Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'net')
-rw-r--r--net/netfilter/nf_conntrack_ecache.c22
-rw-r--r--net/netfilter/nf_log.c10
2 files changed, 26 insertions, 6 deletions
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index a94ac3ad02cb..cdcc7649476b 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -82,9 +82,12 @@ EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
82int nf_conntrack_register_notifier(struct nf_ct_event_notifier *new) 82int nf_conntrack_register_notifier(struct nf_ct_event_notifier *new)
83{ 83{
84 int ret = 0; 84 int ret = 0;
85 struct nf_ct_event_notifier *notify;
85 86
86 mutex_lock(&nf_ct_ecache_mutex); 87 mutex_lock(&nf_ct_ecache_mutex);
87 if (nf_conntrack_event_cb != NULL) { 88 notify = rcu_dereference_protected(nf_conntrack_event_cb,
89 lockdep_is_held(&nf_ct_ecache_mutex));
90 if (notify != NULL) {
88 ret = -EBUSY; 91 ret = -EBUSY;
89 goto out_unlock; 92 goto out_unlock;
90 } 93 }
@@ -100,8 +103,12 @@ EXPORT_SYMBOL_GPL(nf_conntrack_register_notifier);
100 103
101void nf_conntrack_unregister_notifier(struct nf_ct_event_notifier *new) 104void nf_conntrack_unregister_notifier(struct nf_ct_event_notifier *new)
102{ 105{
106 struct nf_ct_event_notifier *notify;
107
103 mutex_lock(&nf_ct_ecache_mutex); 108 mutex_lock(&nf_ct_ecache_mutex);
104 BUG_ON(nf_conntrack_event_cb != new); 109 notify = rcu_dereference_protected(nf_conntrack_event_cb,
110 lockdep_is_held(&nf_ct_ecache_mutex));
111 BUG_ON(notify != new);
105 rcu_assign_pointer(nf_conntrack_event_cb, NULL); 112 rcu_assign_pointer(nf_conntrack_event_cb, NULL);
106 mutex_unlock(&nf_ct_ecache_mutex); 113 mutex_unlock(&nf_ct_ecache_mutex);
107} 114}
@@ -110,9 +117,12 @@ EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
110int nf_ct_expect_register_notifier(struct nf_exp_event_notifier *new) 117int nf_ct_expect_register_notifier(struct nf_exp_event_notifier *new)
111{ 118{
112 int ret = 0; 119 int ret = 0;
120 struct nf_exp_event_notifier *notify;
113 121
114 mutex_lock(&nf_ct_ecache_mutex); 122 mutex_lock(&nf_ct_ecache_mutex);
115 if (nf_expect_event_cb != NULL) { 123 notify = rcu_dereference_protected(nf_expect_event_cb,
124 lockdep_is_held(&nf_ct_ecache_mutex));
125 if (notify != NULL) {
116 ret = -EBUSY; 126 ret = -EBUSY;
117 goto out_unlock; 127 goto out_unlock;
118 } 128 }
@@ -128,8 +138,12 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_register_notifier);
128 138
129void nf_ct_expect_unregister_notifier(struct nf_exp_event_notifier *new) 139void nf_ct_expect_unregister_notifier(struct nf_exp_event_notifier *new)
130{ 140{
141 struct nf_exp_event_notifier *notify;
142
131 mutex_lock(&nf_ct_ecache_mutex); 143 mutex_lock(&nf_ct_ecache_mutex);
132 BUG_ON(nf_expect_event_cb != new); 144 notify = rcu_dereference_protected(nf_expect_event_cb,
145 lockdep_is_held(&nf_ct_ecache_mutex));
146 BUG_ON(notify != new);
133 rcu_assign_pointer(nf_expect_event_cb, NULL); 147 rcu_assign_pointer(nf_expect_event_cb, NULL);
134 mutex_unlock(&nf_ct_ecache_mutex); 148 mutex_unlock(&nf_ct_ecache_mutex);
135} 149}
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index 908f59935fbb..7df37fd786bc 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -35,6 +35,7 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger)
35/* return EEXIST if the same logger is registred, 0 on success. */ 35/* return EEXIST if the same logger is registred, 0 on success. */
36int nf_log_register(u_int8_t pf, struct nf_logger *logger) 36int nf_log_register(u_int8_t pf, struct nf_logger *logger)
37{ 37{
38 const struct nf_logger *llog;
38 int i; 39 int i;
39 40
40 if (pf >= ARRAY_SIZE(nf_loggers)) 41 if (pf >= ARRAY_SIZE(nf_loggers))
@@ -51,7 +52,9 @@ int nf_log_register(u_int8_t pf, struct nf_logger *logger)
51 } else { 52 } else {
52 /* register at end of list to honor first register win */ 53 /* register at end of list to honor first register win */
53 list_add_tail(&logger->list[pf], &nf_loggers_l[pf]); 54 list_add_tail(&logger->list[pf], &nf_loggers_l[pf]);
54 if (nf_loggers[pf] == NULL) 55 llog = rcu_dereference_protected(nf_loggers[pf],
56 lockdep_is_held(&nf_log_mutex));
57 if (llog == NULL)
55 rcu_assign_pointer(nf_loggers[pf], logger); 58 rcu_assign_pointer(nf_loggers[pf], logger);
56 } 59 }
57 60
@@ -63,11 +66,14 @@ EXPORT_SYMBOL(nf_log_register);
63 66
64void nf_log_unregister(struct nf_logger *logger) 67void nf_log_unregister(struct nf_logger *logger)
65{ 68{
69 const struct nf_logger *c_logger;
66 int i; 70 int i;
67 71
68 mutex_lock(&nf_log_mutex); 72 mutex_lock(&nf_log_mutex);
69 for (i = 0; i < ARRAY_SIZE(nf_loggers); i++) { 73 for (i = 0; i < ARRAY_SIZE(nf_loggers); i++) {
70 if (nf_loggers[i] == logger) 74 c_logger = rcu_dereference_protected(nf_loggers[i],
75 lockdep_is_held(&nf_log_mutex));
76 if (c_logger == logger)
71 rcu_assign_pointer(nf_loggers[i], NULL); 77 rcu_assign_pointer(nf_loggers[i], NULL);
72 list_del(&logger->list[i]); 78 list_del(&logger->list[i]);
73 } 79 }