net_sched: check NULL in tcf_block_put()
authorCong Wang <xiyou.wangcong@gmail.com>
Fri, 3 Nov 2017 00:32:08 +0000 (17:32 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 3 Nov 2017 12:31:15 +0000 (21:31 +0900)
Callers of tcf_block_put() could pass NULL so
we can't use block->q before checking if block is
NULL or not.

tcf_block_put_ext() callers are fine, it is always
non-NULL.

Fixes: 8c4083b30e56 ("net: sched: add block bind/unbind notif. and extended block_get/put")
Reported-by: Dave Taht <dave.taht@gmail.com>
Cc: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/cls_api.c

index 3364347bc699a475327c57eeb9a570d74718a7b4..8d1885abee83878ff513588bedcf139848a25f1e 100644 (file)
@@ -340,9 +340,6 @@ void tcf_block_put_ext(struct tcf_block *block,
 {
        struct tcf_chain *chain, *tmp;
 
-       if (!block)
-               return;
-
        list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
                tcf_chain_flush(chain);
 
@@ -362,6 +359,8 @@ void tcf_block_put(struct tcf_block *block)
 {
        struct tcf_block_ext_info ei = {0, };
 
+       if (!block)
+               return;
        tcf_block_put_ext(block, NULL, block->q, &ei);
 }