diff mbox series

[net-next] net_sched: check NULL in tcf_block_put()

Message ID 20171103003208.12329-1-xiyou.wangcong@gmail.com
State Accepted, archived
Delegated to: David Miller
Headers show
Series [net-next] net_sched: check NULL in tcf_block_put() | expand

Commit Message

Cong Wang Nov. 3, 2017, 12:32 a.m. UTC
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>
---
 net/sched/cls_api.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Jiri Pirko Nov. 3, 2017, 6:56 a.m. UTC | #1
Fri, Nov 03, 2017 at 01:32:08AM CET, xiyou.wangcong@gmail.com wrote:
>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>
David Miller Nov. 3, 2017, 12:31 p.m. UTC | #2
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Thu,  2 Nov 2017 17:32:08 -0700

> 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>

Applied, thanks Cong.
diff mbox series

Patch

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index a26c690b48ac..ad35bb4dffaa 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -340,9 +340,6 @@  void tcf_block_put_ext(struct tcf_block *block,
 {
 	struct tcf_chain *chain, *tmp;
 
-	if (!block)
-		return;
-
 	tcf_block_offload_unbind(block, q, ei);
 
 	list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
@@ -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);
 }