Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3340897yba; Mon, 6 May 2019 22:50:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNaw/3wtjVeNhK39n13Z/ulrAsvLUQ34zbq1QXFda5BvCKzk8coILLz3giPystAExwYutn X-Received: by 2002:a17:902:5983:: with SMTP id p3mr6021579pli.224.1557208215773; Mon, 06 May 2019 22:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557208215; cv=none; d=google.com; s=arc-20160816; b=q/EQnXabke56Mnmd402GMBZcjGbDRMc9zk8hf7PRgG1ttWcKqOZj4i52MyaB0EOKGV zS3c5kjGulByyRSV7LZNN2WchuF0cGtYumTWOLytWcQ8gMehQ85THZAIT3SUxfS+RxUV dM074ZLdqYYPMrMXac6bvfCOEI4zX8/OLgBPfKcTLjU7eD6QWJpSmIRoR6+BGK1sdOLn KCgOBHMYcQQfepigHG9gYyMzuuKqnkgLAh6qCycYWoNZCzuvBqz1Sn5bpJ+lQHZnzwe+ HxwIH5N2ACVo91PHrRiAy/6/wmAm7rwAXQSSTnY82WWjHK+2TIcY1KIUTmCeZ1VptG8T Awjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cNpJkhIFj/bJvKWHDYWnDb1A/oLLaIUMpiTKPwlG5A8=; b=CdtBXlK4YcVhkRYwZkO8jXAnmwVv8baSHCJgBXm5nzO6Q60FJCY7zJfD0HAmUEeSFA 80GvG+txh3LmN6QeUILEy7hCYXV3dRM0bpoRr5tGKNFkOSi+9M+7S4qvRRCROfc72txT 5QrBE0G9AoQzge/a7WKWyBBzO2W+QZ6NvBM8Q530YYy6WuYlXhbXHVBz45s2XsHbHEak pI5c1CC1lbiXZh8HZf0haQnmTCqyCGB4fgMByqsDvOwRMooZtXhv7f9KFyueAu7OkqAG 5U9RB2oKUvleEieXI31Rh5/AFmfR9Jz+3qdHozfVllLVlpJ8NeGH5uUQkFNndxlV+HwU +isQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uJszTVfg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i18si16017235pfd.64.2019.05.06.22.49.54; Mon, 06 May 2019 22:50:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uJszTVfg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbfEGFkp (ORCPT + 99 others); Tue, 7 May 2019 01:40:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:60178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbfEGFkn (ORCPT ); Tue, 7 May 2019 01:40:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CC97420675; Tue, 7 May 2019 05:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557207642; bh=1Ohsioqf6e9PSqCMvFBCxo6ssLXNXK3ezfG6Snz+1is=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJszTVfgS3EUTBCmd8TIFp7tV6Nc265+9hVB5kp2NNFJqhR3eAM8F/WCjFKPN53tD 44vEhFmsln6n/ElabpJmTWg/3cA2lVAjBgZz5iwqDkIj/bs8cbUR0QZTuLB5qBgP8w lT68rLfjBDu3h1qMdd0mIdCnNdOzbvzlkD2D8RGk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Cong Wang , Jamal Hadi Salim , Jiri Pirko , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 75/95] net_sched: fix two more memory leaks in cls_tcindex Date: Tue, 7 May 2019 01:38:04 -0400 Message-Id: <20190507053826.31622-75-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190507053826.31622-1-sashal@kernel.org> References: <20190507053826.31622-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cong Wang [ Upstream commit 1db817e75f5b9387b8db11e37d5f0624eb9223e0 ] struct tcindex_filter_result contains two parts: struct tcf_exts and struct tcf_result. For the local variable 'cr', its exts part is never used but initialized without being released properly on success path. So just completely remove the exts part to fix this leak. For the local variable 'new_filter_result', it is never properly released if not used by 'r' on success path. Cc: Jamal Hadi Salim Cc: Jiri Pirko Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/cls_tcindex.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index 52829fdc280b..75c7c7cc7499 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c @@ -322,9 +322,9 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, struct nlattr *est, bool ovr) { struct tcindex_filter_result new_filter_result, *old_r = r; - struct tcindex_filter_result cr; struct tcindex_data *cp = NULL, *oldp; struct tcindex_filter *f = NULL; /* make gcc behave */ + struct tcf_result cr = {}; int err, balloc = 0; struct tcf_exts e; @@ -363,13 +363,10 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, cp->h = p->h; err = tcindex_filter_result_init(&new_filter_result); - if (err < 0) - goto errout1; - err = tcindex_filter_result_init(&cr); if (err < 0) goto errout1; if (old_r) - cr.res = r->res; + cr = r->res; if (tb[TCA_TCINDEX_HASH]) cp->hash = nla_get_u32(tb[TCA_TCINDEX_HASH]); @@ -460,8 +457,8 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, } if (tb[TCA_TCINDEX_CLASSID]) { - cr.res.classid = nla_get_u32(tb[TCA_TCINDEX_CLASSID]); - tcf_bind_filter(tp, &cr.res, base); + cr.classid = nla_get_u32(tb[TCA_TCINDEX_CLASSID]); + tcf_bind_filter(tp, &cr, base); } if (old_r && old_r != r) { @@ -473,7 +470,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, } oldp = p; - r->res = cr.res; + r->res = cr; tcf_exts_change(&r->exts, &e); rcu_assign_pointer(tp->root, cp); @@ -492,6 +489,8 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ; /* nothing */ rcu_assign_pointer(*fp, f); + } else { + tcf_exts_destroy(&new_filter_result.exts); } if (oldp) @@ -504,7 +503,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, else if (balloc == 2) kfree(cp->h); errout1: - tcf_exts_destroy(&cr.exts); tcf_exts_destroy(&new_filter_result.exts); errout: kfree(cp); -- 2.20.1