Skip to content

Commit 34c5bd6

Browse files
ummakynesdavem330
authored andcommitted
net: filter: don't release unattached filter through call_rcu()
sk_unattached_filter_destroy() does not always need to release the filter object via rcu. Since this filter is never attached to the socket, the caller should be responsible for releasing the filter in a safe way, which may not necessarily imply rcu. This is a short summary of clients of this function: 1) xt_bpf.c and cls_bpf.c use the bpf matchers from rules, these rules are removed from the packet path before the filter is released. Thus, the framework makes sure the filter is safely removed. 2) In the ppp driver, the ppp_lock ensures serialization between the xmit and filter attachment/detachment path. This doesn't use rcu so deferred release via rcu makes no sense. 3) In the isdn/ppp driver, it is called from isdn_ppp_release() the isdn_ppp_ioctl(). This driver uses mutex and spinlocks, no rcu. Thus, deferred rcu makes no sense to me either, the deferred releases may be just masking the effects of wrong locking strategy, which should be fixed in the driver itself. 4) In the team driver, this is the only place where the rcu synchronization with unattached filter is used. Therefore, this patch introduces synchronize_rcu() which is called from the genetlink path to make sure the filter doesn't go away while packets are still walking over it. I think we can revisit this once struct bpf_prog (that only wraps specific bpf code bits) is in place, then add some specific struct rcu_head in the scope of the team driver if Jiri thinks this is needed. Deferred rcu release for unattached filters was originally introduced in 302d663 ("filter: Allow to create sk-unattached filters"). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e10038a commit 34c5bd6

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎drivers/net/team/team_mode_loadbalance.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,15 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
293293
__fprog_destroy(lb_priv->ex->orig_fprog);
294294
orig_fp = rcu_dereference_protected(lb_priv->fp,
295295
lockdep_is_held(&team->lock));
296-
sk_unattached_filter_destroy(orig_fp);
297296
}
298297

299298
rcu_assign_pointer(lb_priv->fp, fp);
300299
lb_priv->ex->orig_fprog = fprog;
300+
301+
if (orig_fp) {
302+
synchronize_rcu();
303+
sk_unattached_filter_destroy(orig_fp);
304+
}
301305
return 0;
302306
}
303307

‎net/core/filter.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,12 @@ static void sk_release_orig_filter(struct sk_filter *fp)
841841
}
842842
}
843843

844+
static void __sk_filter_release(struct sk_filter *fp)
845+
{
846+
sk_release_orig_filter(fp);
847+
sk_filter_free(fp);
848+
}
849+
844850
/**
845851
* sk_filter_release_rcu - Release a socket filter by rcu_head
846852
* @rcu: rcu_head that contains the sk_filter to free
@@ -849,8 +855,7 @@ static void sk_filter_release_rcu(struct rcu_head *rcu)
849855
{
850856
struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
851857

852-
sk_release_orig_filter(fp);
853-
sk_filter_free(fp);
858+
__sk_filter_release(fp);
854859
}
855860

856861
/**
@@ -1050,7 +1055,7 @@ EXPORT_SYMBOL_GPL(sk_unattached_filter_create);
10501055

10511056
void sk_unattached_filter_destroy(struct sk_filter *fp)
10521057
{
1053-
sk_filter_release(fp);
1058+
__sk_filter_release(fp);
10541059
}
10551060
EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);
10561061

0 commit comments

Comments
 (0)