From patchwork Tue Oct 15 10:30:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1177892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OfZMOitL"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46tXMq6Vxgz9sP7 for ; Wed, 16 Oct 2019 23:55:33 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1DDD6E38; Wed, 16 Oct 2019 12:50:51 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 804F6E34 for ; Wed, 16 Oct 2019 12:50:49 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3364F831 for ; Wed, 16 Oct 2019 12:50:49 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id q21so14654991pfn.11 for ; Wed, 16 Oct 2019 05:50:49 -0700 (PDT) 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; bh=kP585WOSESkrGweaLhfk1ecnyRlG66kJBicCGup0/PI=; b=OfZMOitLpJk4SUuFegpXZ/9eFU7GAic/3SxPx6J+HEjibshbXT8OTCdOWc/TudjP7k lPK2v+4R81EChyo1KNQun4/t0mSxvixcn08CScvma/DD2cJ0S6xUnuli/ctViMITZrG8 GXXltb9Xl/hKShioJqoo5A4KpFHtslryDM6U4vXB1GNhsY3nWcs/Bm7PCu6FzK6a5F6C 6Bfkp/4xua/dicuD1KcN0KOSXSmio25h5mamwcH95Hqib8UTk7bQI71gDUJn1Tz4iTiM W0DGim6UYL4uORU5lKmDRrq4DP4NLP0Yp6R2E0tPgyu9H/CKHkDoO+iszLYkQATWd2wO BHlg== 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; bh=kP585WOSESkrGweaLhfk1ecnyRlG66kJBicCGup0/PI=; b=Thgol0fT1L0vCEuV+euQ9JoalwGMTmpcMAbPmvWnbMxZZm94GYZbVGBIHyH9BSMPzI C/bOEHGtcQFV+xN5l7hYttzU3mG/7P8sa82cBRoPCV879JRyjSjrja9brBxWZGibIXRt 2HxoPdgsGoacYpvIYi1BGk4wb/4rpfF1PiXg9pfcCuQlaND2hnPj9ZVJd+BaQxEIj9FC 73+Cnt8h14ISIRTiTw8eh56qcov4uGBKGJM3IHfJLUZyAazk+HbUc+27HfBZb7ERcrIo nw5uE0hjLiA9xEZyqnwXOtEv10MrkU/urITM4DlbhITwLDUraEDFl/9osJH0+ikInoFB 4tng== X-Gm-Message-State: APjAAAX/NcyxQRqj+XbynW3NDf6mm04ShVzyM1rM9Z3JWJMJwk0bZcsu PElx10ZjJ5SM3/KdlZX1WJw= X-Google-Smtp-Source: APXvYqzFMD474lxcczA3J3Hm1jhOpIk8wdKgQnZM0107qdECi4p6i0wWJXkWrM4Gk6uSZYLFynY+wA== X-Received: by 2002:a17:90a:eb03:: with SMTP id j3mr4981956pjz.88.1571230248745; Wed, 16 Oct 2019 05:50:48 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id d19sm2747339pjz.5.2019.10.16.05.50.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Oct 2019 05:50:48 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: gvrose8192@gmail.com, pshelar@ovn.org Date: Tue, 15 Oct 2019 18:30:38 +0800 Message-Id: <1571135440-24313-9-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571135440-24313-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1571135440-24313-1-git-send-email-xiangxia.m.yue@gmail.com> X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00, DATE_IN_PAST_24_48, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v4 08/10] net: openvswitch: fix possible memleak on destroy flow-table X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Tonghao Zhang When we destroy the flow tables which may contain the flow_mask, so release the flow mask struct. Signed-off-by: Tonghao Zhang Tested-by: Greg Rose --- net/openvswitch/flow_table.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index 5df5182..d5d768e 100644 --- a/net/openvswitch/flow_table.c +++ b/net/openvswitch/flow_table.c @@ -295,6 +295,18 @@ static void table_instance_destroy(struct table_instance *ti, } } +static void tbl_mask_array_destroy(struct flow_table *tbl) +{ + struct mask_array *ma = ovsl_dereference(tbl->mask_array); + int i; + + /* Free the flow-mask and kfree_rcu the NULL is allowed. */ + for (i = 0; i < ma->max; i++) + kfree_rcu(rcu_dereference_raw(ma->masks[i]), rcu); + + kfree_rcu(rcu_dereference_raw(tbl->mask_array), rcu); +} + /* No need for locking this function is called from RCU callback or * error path. */ @@ -304,7 +316,7 @@ void ovs_flow_tbl_destroy(struct flow_table *table) struct table_instance *ufid_ti = rcu_dereference_raw(table->ufid_ti); free_percpu(table->mask_cache); - kfree_rcu(rcu_dereference_raw(table->mask_array), rcu); + tbl_mask_array_destroy(table); table_instance_destroy(ti, ufid_ti, false); }