From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roman Mashak Subject: [PATCH net 1/1] net sched actions: fix refcnt leak in skbmod Date: Fri, 11 May 2018 14:35:33 -0400 Message-ID: <1526063733-7813-1-git-send-email-mrv@mojatatu.com> Cc: netdev@vger.kernel.org, kernel@mojatatu.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, Roman Mashak To: davem@davemloft.net Return-path: Received: from mail-io0-f194.google.com ([209.85.223.194]:40473 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980AbeEKSfn (ORCPT ); Fri, 11 May 2018 14:35:43 -0400 Received: by mail-io0-f194.google.com with SMTP id g14-v6so8074256ioc.7 for ; Fri, 11 May 2018 11:35:43 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: When application fails to pass flags in netlink TLV when replacing existing skbmod action, the kernel will leak refcnt: $ tc actions get action skbmod index 1 total acts 0 action order 0: skbmod pipe set smac 00:11:22:33:44:55 index 1 ref 1 bind 0 For example, at this point a buggy application replaces the action with index 1 with new smac 00:aa:22:33:44:55, it fails because of zero flags, however refcnt gets bumped: $ tc actions get actions skbmod index 1 total acts 0 action order 0: skbmod pipe set smac 00:11:22:33:44:55 index 1 ref 2 bind 0 $ Tha patch fixes this by calling tcf_idr_release() on existing actions. Fixes: 86da71b57383d ("net_sched: Introduce skbmod action") Signed-off-by: Roman Mashak --- net/sched/act_skbmod.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c index bbcbdce732cc..ad050d7d4b46 100644 --- a/net/sched/act_skbmod.c +++ b/net/sched/act_skbmod.c @@ -131,8 +131,11 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla, if (exists && bind) return 0; - if (!lflags) + if (!lflags) { + if (exists) + tcf_idr_release(*a, bind); return -EINVAL; + } if (!exists) { ret = tcf_idr_create(tn, parm->index, est, a, -- 2.7.4