Skip to content

Commit

Permalink
Merge branch 'net-sched-couple-of-chain-fixes'
Browse files Browse the repository at this point in the history
Jiri Pirko says:

====================
net: sched: couple of chain fixes

Jiri Pirko (2):
  net: sched: fix use after free when tcf_chain_destroy is called
    multiple times
  net: sched: don't do tcf_chain_flush from tcf_chain_destroy
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Aug 22, 2017
2 parents fd6055a + 30d65e8 commit e188245
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,15 @@ static void tcf_chain_flush(struct tcf_chain *chain)

static void tcf_chain_destroy(struct tcf_chain *chain)
{
list_del(&chain->list);
tcf_chain_flush(chain);
kfree(chain);
/* May be already removed from the list by the previous call. */
if (!list_empty(&chain->list))
list_del_init(&chain->list);

/* There might still be a reference held when we got here from
* tcf_block_put. Wait for the user to drop reference before free.
*/
if (!chain->refcnt)
kfree(chain);
}

struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
Expand Down Expand Up @@ -288,8 +294,10 @@ void tcf_block_put(struct tcf_block *block)
if (!block)
return;

list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
list_for_each_entry_safe(chain, tmp, &block->chain_list, list) {
tcf_chain_flush(chain);
tcf_chain_destroy(chain);
}
kfree(block);
}
EXPORT_SYMBOL(tcf_block_put);
Expand Down

0 comments on commit e188245

Please sign in to comment.