Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1093405rdd; Wed, 10 Jan 2024 08:25:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMwgbPzAwhRAQcOPwr2TGpdUrr3jwbZtc2Cs+GYFJSsp+yyLRbmH3py54C32eOjKeQbJZy X-Received: by 2002:a05:6a00:10d3:b0:6d9:e275:f646 with SMTP id d19-20020a056a0010d300b006d9e275f646mr1192261pfu.15.1704903922837; Wed, 10 Jan 2024 08:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704903922; cv=none; d=google.com; s=arc-20160816; b=FDQ3FcdO2AgfnaD04J/Qmw8dVqUYuadnxdjMmnOlXYafbmiQE1+d7kO/3RXI4EL5kb TUwx6qJpMnv7AxtK7up/FADdSRvCNKHilXDfsjeu7aIhlvkn61qR89HtRkDgpO+hx19L yLeQHzZY/XHl3yviVzCBIvVKgUoMRGVm+FOSLYkbgU0PpYL7NdjEFWxLYkvWo5ynhQNK B6xf4p9b/lcPxlj0CFIJm/trVQDMTslHzPqMsRSa8KJNUYH+/i1pOS6HRNR32yluW3t3 ZOmKKRsp0xkhrNEgvVfUL7/RnviJJ4C9JRQUI03HJQnWBGhgh62X489Cok7sYDIRRaQq XZiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7SJiKLWJNY1RokKtw6+Ytu+AkY5bVQSh7V0S30/0Bqc=; fh=/Gu90RCdx+gNxSpHGyvqQQX/gt6LIkzdEDoQg/3nweQ=; b=j0lYF3zMe0aZKwDxdI4O0X5VBwXrgkB+MQXdAp/EBCQ+FtRT+FJSW+fWp4LEmAuEfq vWRetEdBe/pkgvYczs+XCyVHGaf5uRwt54uLIajJ18Up53F1vMQfRYn+zE4jg2Jl8xwi sEnipBdHFU6SVSbJP28MYHdsyCwkRIZH2jOR9wa3acP2/tddXtpGXUjoIY8PYtaeDyiQ qRbTy2Sw530hR0YaF1x6WK/OfXPXumwnLgPgkEwBPakwfRa12qtJfkhDXronuP37lo6G kEXsDcwgFw++hqGW8V+wbqBGaNoDh6IOYpTBTdena8219nJM9LyrXlYdfwwNkzpRtKFV zzCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=Ufudp8Qg; spf=pass (google.com: domain of linux-kernel+bounces-22491-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 199-20020a6302d0000000b005ce01eee2afsi3934530pgc.836.2024.01.10.08.25.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 08:25:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22491-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=Ufudp8Qg; spf=pass (google.com: domain of linux-kernel+bounces-22491-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4BB402831F1 for ; Wed, 10 Jan 2024 16:25:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1B854CB57; Wed, 10 Jan 2024 16:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ufudp8Qg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB76F4CB41; Wed, 10 Jan 2024 16:24:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DF93C41674; Wed, 10 Jan 2024 16:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704903891; bh=F/rRPZEP4jt4dv94N+GBp79mg97U/mDxSAOx1+gJl7c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ufudp8Qg9VLe8RnLKEopFn0JZ6i4YfvSuUASRNwS1p+YfsHir98+Pu8BXPbZZc2KG qLuFVVyEP8CtAoCKLGZCMujLGWnETj5HMal8pJXodKRnMma/oaTpfPSVdDU34G6nJP jb/dcWrmweLhMbTldpOm3dBEzr6LKpGCvtTV1SFY6pmZFagrT5lQhlTP0NweR4Zaa+ f4+H++RQYiroFkBCcvlvjS7rPQ2kusPg8pXQF2vZKxTxrD2njcv5bdFezUT1U4TGjB NRjrWTlkAWkkxncDUxHzf3sNgmEeU9BgyigMJC3067oJ0npjmu6ikXlz6nSK+M/q+X LatT7sy5QW2ng== Date: Wed, 10 Jan 2024 16:24:46 +0000 From: Simon Horman To: alexious@zju.edu.cn Cc: Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maor Gottlieb , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [v2] net/mlx5e: fix a double-free in arfs_create_groups Message-ID: <20240110162446.GJ9296@kernel.org> References: <20240108152605.3712050-1-alexious@zju.edu.cn> <20240109081837.GJ132648@kernel.org> <49a38639.7d59b.18cf38ab939.Coremail.alexious@zju.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49a38639.7d59b.18cf38ab939.Coremail.alexious@zju.edu.cn> On Wed, Jan 10, 2024 at 09:23:24PM +0800, alexious@zju.edu.cn wrote: > > On Mon, Jan 08, 2024 at 11:26:04PM +0800, Zhipeng Lu wrote: > > > When `in` allocated by kvzalloc fails, arfs_create_groups will free > > > ft->g and return an error. However, arfs_create_table, the only caller of > > > arfs_create_groups, will hold this error and call to > > > mlx5e_destroy_flow_table, in which the ft->g will be freed again. > > > > > > Fixes: 1cabe6b0965e ("net/mlx5e: Create aRFS flow tables") > > > Signed-off-by: Zhipeng Lu > > > Reviewed-by: Simon Horman > > > > When working on netdev (and probably elsewhere) > > Please don't include Reviewed-by or other tags > > that were explicitly supplied by someone: I don't recall > > supplying the tag above so please drop it. > > I apologize, but it appears that you included a "reviewed-by" > tag along with certain suggestions for version 1 of this patch > in the first review email(about 6 days before). Yes, sorry. My statement above is not correct: I now see that I did supply the tag. > In response, after a short discussion, I followed some of > those suggestions and send this v2 patch. > I referred to the "Dealing with tags" section in this KernelNewbies > tips: https://kernelnewbies.org/PatchTipsAndTricks and thought > that I should include that tag in v1 email to this v2 patch. > So now I'm a little bit confused here: if the tag rule has changed > or I got some misunderstanding on existing rules? Your clarification > on this matter would be greatly appreciated. I think in this case my statement above was incorrect, and indeed the rule above is correct AFAIK But it probably would have been best not to include the tag in v2, because there were significant changes between v1 and v2. > I'll send a new version of this patch after correcting the tag > issue and taking your suggestions into consideration. > > Several comments below. .. > > > @@ -883,7 +883,6 @@ void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *ne > > > void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft) > > > { > > > mlx5e_destroy_groups(ft); > > > - kfree(ft->g); > > > mlx5_destroy_flow_table(ft->t); > > > ft->t = NULL; > > > > Is the above still needed in some cases, and safe in all cases? > > Well, in fact the kfree(ft->g) in mlx5e_destroy_flow_table causes > double frees in different functions such as fs_udp_create_table, > not only in arfs_create_groups. But you are right, with a more > detailed check I found that in some other functions, like > accel_fs_tcp_create_table, removing such free will cause memleak. > So it could be a better idea to leave mlx5e_destroy_flow_table > as it used to be. And that follows the "one patch for one change" idea. Right, I think it would be best to focus on fixing arfs_create_groups(). And making sure that neither leaks nor double frees occur. And I think that at this point that includes ensuring ft->g is NULL if it has been freed.