can: gw: synchronize rcu operations before removing gw job entry
PATCH 1/1 can: gw: synchronize rcu operations before removing gw job entry
From: Oliver Hartkopp <[email protected]>
commit fb8696ab14adadb2e3f6c17c18ed26b3ecd96691 upstream.
can_can_gw_rcv() is called under RCU protection, so after calling can_rx_unregister(), we have to call synchronize_rcu in order to wait for any RCU read-side critical sections to finish before removing the kmem_cache entry with the referenced gw job entry.
--- net/can/gw.c | 3 +++ 1 file changed, 3 insertions(+)
net/can/gw.c +3 -0
@@ -495,10 +495,11 @@ static int cgw_notifier(struct notifier_block *nb,hlist_for_each_entry_safe (gwj, nx, &cgw_list, list) {if (gwj->src.dev == dev || gwj->dst.dev == dev) {hlist_del (&gwj->list);cgw_unregister_filter (gwj); +synchronize_rcu ();kmem_cache_free (cgw_cache, gwj); } } }
@@ -939,10 +940,11 @@ static void cgw_remove_all_jobs(void)ASSERT_RTNL ();hlist_for_each_entry_safe (gwj, nx, &cgw_list, list) {hlist_del (&gwj->list);cgw_unregister_filter (gwj); +synchronize_rcu ();kmem_cache_free (cgw_cache, gwj); } }static int cgw_remove_job (struct sk_buff *skb,struct nlmsghdr *nlh)
@@ -1006,10 +1008,11 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)if (memcmp (&gwj->ccgw, &ccgw,sizeof (ccgw)))continue ;hlist_del (&gwj->list);cgw_unregister_filter (gwj); +synchronize_rcu ();kmem_cache_free (cgw_cache, gwj); err =0 ;break ; }
Signature · 1 line
2.30.2
PATCH 1/1 can: bcm: delay release of struct bcm_op after synchronize_rcu()
From: Thadeu Lima de Souza Cascardo <[email protected]>
From: Thadeu Lima de Souza Cascardo <[email protected]>
commit d5f9023fa61ee8b94f37a93f08e94b136cf1e463 upstream.
can_rx_register() callbacks may be called concurrently to the call to can_rx_unregister(). The callbacks and callback data, though, are protected by RCU and the struct sock reference count.
So the callback data is really attached to the life of sk, meaning that it should be released on sk_destruct. However, bcm_remove_op() calls tasklet_kill(), and RCU callbacks may be called under RCU softirq, so that cannot be used on kernels before the introduction of HRTIMER_MODE_SOFT.
However, bcm_rx_handler() is called under RCU protection, so after calling can_rx_unregister(), we may call synchronize_rcu() in order to wait for any RCU read-side critical sections to finish. That is, bcm_rx_handler() won't be called anymore for those ops. So, we only free them, after we do that synchronize_rcu().
--- net/can/bcm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/can/bcm.c +6 -1
@@ -811,10 +811,11 @@ static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex)can_rx_unregister (NULL , op->can_id,REGMASK (op->can_id), bcm_rx_handler, op);list_del (&op->list); +synchronize_rcu ();bcm_remove_op (op);return 1 ;/* done */ } }
@@ -1536,13 +1537,17 @@ static int bcm_release(struct socket *sock) }else can_rx_unregister (NULL , op->can_id,REGMASK (op->can_id), bcm_rx_handler, op); -bcm_remove_op (op); } +synchronize_rcu (); + +list_for_each_entry_safe (op, next, &bo->rx_ops, list) +bcm_remove_op (op); +/* remove procfs entry */ if (proc_dir && bo->bcm_proc_read)remove_proc_entry (bo->procname, proc_dir);/* remove device reference */
Signature · 1 line
2.30.2
Greg KH
maintainerQuoted 9 lines · Oliver Hartkopp
From: Oliver Hartkopp <[email protected]>
commit
fb8696ab14adadb2e3f6c17c18ed26b3ecd96691upstream.
can_can_gw_rcv()is called under RCU protection, so after callingcan_rx_unregister(), we have to callsynchronize_rcuin order to wait for any RCU read-side critical sections to finish before removing thekmem_cacheentry with the referenced gw job entry.
Quoted 8 lines
Fixes c1aabdf379bc ("can-gw: add netlink based CAN routing")Cc linux-stable <[email protected]>Signed-off-by Oliver Hartkopp <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- net/can/gw.c | 3 +++ 1 file changed, 3 insertions(+)
Both now queued up, thanks.
greg k-h