From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D5DAC10F00 for ; Sat, 16 Feb 2019 18:58:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2ABE7222E6 for ; Sat, 16 Feb 2019 18:58:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hQ+fV+rk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732420AbfBPS6l (ORCPT ); Sat, 16 Feb 2019 13:58:41 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42484 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732354AbfBPS6k (ORCPT ); Sat, 16 Feb 2019 13:58:40 -0500 Received: by mail-pf1-f194.google.com with SMTP id n74so6450804pfi.9 for ; Sat, 16 Feb 2019 10:58:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wWfDPGvbM1zkxCNDZrjlKR2IqVWLItG6akmo/DI/cA8=; b=hQ+fV+rk3ef0CHLKjImEAvfp7JiIVW5sUdSVXfSgftvqYGG1QFz6pmzZohp5sW5xeA imu0+F1s63lAjUJMJdpQT7ywnqDWnYR9vM30Ef2dKpruzLuEeSf/xE6wh4fKLiyJQKxs LHwYmHMQA49agYoaXbZKO2WwRFO2pf3ImiZgaqWP4gDw+dOvGWp1Gr25KMJ6AisU4DiR ZPQ4xWoxwQd1s5FC020KG55046BX97y5OwkzFTKM27qzrQWk2ah4bkgZtflexYDJefr3 ta403fqDe3VmJbh0v3B7AvfpopX55INesMbvYXlr6TvzBNY3uftJUrVc1VjxecoHLXWw iYHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wWfDPGvbM1zkxCNDZrjlKR2IqVWLItG6akmo/DI/cA8=; b=nsSLFrAMCeVMhYRurFIYOqoa7qRWjgqmXDeQIKyxTIaZ3EPUijIFBh5xXNGPefSSu+ CE9kuuSe6t5Q/pMnAByJpjMUmUUHD1Zdl24Pnnz6nBtHUKALIbbMAHtdBFjCYLSMznlQ qIsjxlxsqwI4e1u00fUsF5RQ/Tozq+kmow3C3YLV+dQn20uEgsTRG7mqzQyZ5sy9ogOV yKi7/MRpIXyvSfFPHwz0LIZrKm4345OpKfzOCe9iFTUfMy7wwDKyhiefQ71GZeDLs1ze tr8jzy+92yfY0txG5mooSQvabf3weybkZ9tdqBXN3bQMHBqfqyG94plSEP21hUwrwULZ KVRw== X-Gm-Message-State: AHQUAubBj4hgQHfk1dvT6s3wQozHjQ3/uiOHFEYq2N9LRsUPdomCuKID HyDFzNrT98pHdIULkWryfejrSMAq X-Google-Smtp-Source: AHgI3IYJiV0Pg45tvg5za73jS/I+Cwi0RW+/MlPDur/Rl6/mHZ/1BRpt9XQlM8Eo3wARUNU6OsL0XQ== X-Received: by 2002:a62:864c:: with SMTP id x73mr16087720pfd.49.1550343518733; Sat, 16 Feb 2019 10:58:38 -0800 (PST) Received: from tw-172-25-17-123.office.twttr.net ([8.25.197.27]) by smtp.gmail.com with ESMTPSA id f20sm10725703pfn.177.2019.02.16.10.58.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Feb 2019 10:58:37 -0800 (PST) From: Cong Wang To: netdev@vger.kernel.org Cc: Cong Wang , Jamal Hadi Salim , Jiri Pirko Subject: [Patch net-next 2/2] net_sched: fix a memory leak in cls_tcindex Date: Sat, 16 Feb 2019 10:58:27 -0800 Message-Id: <20190216185827.21535-2-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190216185827.21535-1-xiyou.wangcong@gmail.com> References: <20190216185827.21535-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org (cherry picked from commit 033b228e7f26b29ae37f8bfa1bc6b209a5365e9f) When tcindex_destroy() destroys all the filter results in the perfect hash table, it invokes the walker to delete each of them. However, results with class==0 are skipped in either tcindex_walk() or tcindex_delete(), which causes a memory leak reported by kmemleak. This patch fixes it by skipping the walker and directly deleting these filter results so we don't miss any filter result. As a result of this change, we have to initialize exts->net properly in tcindex_alloc_perfect_hash(). For net-next, we need to consider whether we should initialize ->net in tcf_exts_init() instead, before that just directly test CONFIG_NET_CLS_ACT=y. Cc: Jamal Hadi Salim Cc: Jiri Pirko Signed-off-by: Cong Wang --- net/sched/cls_tcindex.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index 81a433ae31b3..fbf3519a12d8 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c @@ -221,14 +221,6 @@ static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last, return 0; } -static int tcindex_destroy_element(struct tcf_proto *tp, - void *arg, struct tcf_walker *walker) -{ - bool last; - - return tcindex_delete(tp, arg, &last, false, NULL); -} - static void tcindex_destroy_work(struct work_struct *work) { struct tcindex_data *p = container_of(to_rcu_work(work), @@ -568,13 +560,32 @@ static void tcindex_destroy(struct tcf_proto *tp, bool rtnl_held, struct netlink_ext_ack *extack) { struct tcindex_data *p = rtnl_dereference(tp->root); - struct tcf_walker walker; + int i; pr_debug("tcindex_destroy(tp %p),p %p\n", tp, p); - walker.count = 0; - walker.skip = 0; - walker.fn = tcindex_destroy_element; - tcindex_walk(tp, &walker, true); + + if (p->perfect) { + for (i = 0; i < p->hash; i++) { + struct tcindex_filter_result *r = p->perfect + i; + + tcf_unbind_filter(tp, &r->res); + if (tcf_exts_get_net(&r->exts)) + tcf_queue_work(&r->rwork, + tcindex_destroy_rexts_work); + else + __tcindex_destroy_rexts(r); + } + } + + for (i = 0; p->h && i < p->hash; i++) { + struct tcindex_filter *f, *next; + bool last; + + for (f = rtnl_dereference(p->h[i]); f; f = next) { + next = rtnl_dereference(f->next); + tcindex_delete(tp, &f->result, &last, rtnl_held, NULL); + } + } tcf_queue_work(&p->rwork, tcindex_destroy_work); } -- 2.20.1