diff options
author | David S. Miller <davem@davemloft.net> | 2017-08-22 14:39:59 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-08-22 14:39:59 -0700 |
commit | e188245d02ed3798914b528cfe0fb680d2f4a5a6 (patch) | |
tree | 497408b42d7f0ee86b172ad3048944cb30997b14 | |
parent | fd6055a806edc4019be1b9fb7d25262599bca5b1 (diff) | |
parent | 30d65e8f96ad01d9f998039e9af9ce5545e5a4ee (diff) | |
download | linux-e188245d02ed3798914b528cfe0fb680d2f4a5a6.tar.bz2 |
Merge branch 'net-sched-couple-of-chain-fixes'
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 <davem@davemloft.net>
-rw-r--r-- | net/sched/cls_api.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 9fd44c221347..6c5ea84d2682 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -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, @@ -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); |