Skip to content

Commit 1c8e7e6

Browse files
rkaplgregkh
authored andcommitted
net: sched: crash on blocks with goto chain action
commit a60b3f5 upstream. tcf_block_put_ext has assumed that all filters (and thus their goto actions) are destroyed in RCU callback and thus can not race with our list iteration. However, that is not true during netns cleanup (see tcf_exts_get_net comment). Prevent the user after free by holding all chains (except 0, that one is already held). foreach_safe is not enough in this case. To reproduce, run the following in a netns and then delete the ns: ip link add dtest type dummy tc qdisc add dev dtest ingress tc filter add dev dtest chain 1 parent ffff: handle 1 prio 1 flower action goto chain 2 Fixes: 822e86d ("net_sched: remove tcf_block_put_deferred()") Signed-off-by: Roman Kapl <code@rkapl.cz> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net> Cc: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b6b42b3 commit 1c8e7e6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎net/sched/cls_api.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,25 +282,32 @@ static void tcf_block_put_final(struct work_struct *work)
282282
struct tcf_chain *chain, *tmp;
283283

284284
rtnl_lock();
285-
/* Only chain 0 should be still here. */
285+
286+
/* At this point, all the chains should have refcnt == 1. */
286287
list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
287288
tcf_chain_put(chain);
288289
rtnl_unlock();
289290
kfree(block);
290291
}
291292

292293
/* XXX: Standalone actions are not allowed to jump to any chain, and bound
293-
* actions should be all removed after flushing. However, filters are now
294-
* destroyed in tc filter workqueue with RTNL lock, they can not race here.
294+
* actions should be all removed after flushing.
295295
*/
296296
void tcf_block_put(struct tcf_block *block)
297297
{
298-
struct tcf_chain *chain, *tmp;
298+
struct tcf_chain *chain;
299299

300300
if (!block)
301301
return;
302302

303-
list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
303+
/* Hold a refcnt for all chains, except 0, so that they don't disappear
304+
* while we are iterating.
305+
*/
306+
list_for_each_entry(chain, &block->chain_list, list)
307+
if (chain->index)
308+
tcf_chain_hold(chain);
309+
310+
list_for_each_entry(chain, &block->chain_list, list)
304311
tcf_chain_flush(chain);
305312

306313
INIT_WORK(&block->work, tcf_block_put_final);

0 commit comments

Comments
 (0)