Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2927737rdd; Sat, 13 Jan 2024 07:33:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeAM1hMkuP2XImJMHeNxrkYmB4w3IdnYEJOHAKsfzsRroqMgSGvo6ZNUTKTEeN4sKKn0Ja X-Received: by 2002:a05:6402:1e8b:b0:559:82f:d95a with SMTP id f11-20020a0564021e8b00b00559082fd95amr710165edf.32.1705160011183; Sat, 13 Jan 2024 07:33:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705160011; cv=none; d=google.com; s=arc-20160816; b=EsZy6pV+N8dJhtkO4jEry10yyQRsAyPI7kLLQPzS4KJjSsQqCf2dOjB/BAaMhCQ9yO XMAp4Own3YighV7mgg+hzrwlH0IqM9Vh55++rxI0LYZnDwFAYYRt+TTOX8o3C2E7rMa9 nmtsbx/3/8fMRW3tzO4Vzt51fJUiIzDmZB7zOqMdjaJIQZcLVtJTTWZBBYQafhkREfFS l8rB6b4JecaFYKoa32zIallM3uhZz40BF15co9tpYMZwSnwR42b0aYeiOD0DKZnelSOt Zj1LvDvsZxTTPbp/g1z92VyJYP+4vraEaSPl8p9msOLailZ+Ltug986kCFILvANkEygv 70HQ== 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=d8Hh4Jhaz9SWLkBAPl+98Tw0NzBoejvfh0hD+Sk+Y0s=; fh=9zqRx+GNpScMPCWDco+LS9Ydp9CYDADAb+HYhJ22Ri0=; b=UQgtsHliq9PW2UdNKm+0+l0HfcS8cUoNnrjU9kOMBR10pUfeznkjXVi9Kl3OCeMhJ0 IwRvOgK9oXKNOoKGifEBUZfiAyAElnyy+NpOaTVnNHBGUmcEtKGWzw3ySYchHZTSwBoR 33necmX26V78DXCaT6nKl67sokEmXuYImDq80cdSKAP0Wd79wzmC3B2re2EvMP+iRSWW NOoPkGu0gQ0efBGryd00djeasxnNKhQ3SPdKh4d1VZ+E0GCgQfFYcN75mMfVEf3DoQR0 5ELTvtsMLpVMilcOgXhKmR2yfX2bgE4LQ53741eNuEr8s4YxeAnchHuDHFTNaBwMklJ8 5JCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=l8dSd36e; spf=pass (google.com: domain of linux-kernel+bounces-25323-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b11-20020aa7df8b000000b005533b5821b8si2405789edy.686.2024.01.13.07.33.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 07:33:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25323-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=l8dSd36e; spf=pass (google.com: domain of linux-kernel+bounces-25323-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25323-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D385D1F22086 for ; Sat, 13 Jan 2024 15:33:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6025E23C6; Sat, 13 Jan 2024 15:33:19 +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="l8dSd36e" 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 8ACA31C16; Sat, 13 Jan 2024 15:33:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B3BEC433F1; Sat, 13 Jan 2024 15:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705159998; bh=a6Ra8/vW20LqIUs9s37sHdzXHXZxogXvoS1zUc0El3w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=l8dSd36ej497TKceU3Qsy8VxpLEUAfUPXC6n1FJE54MokQT4OwMUHEYC/czQFaZQw uTbccaH3L+xnx114iixt7ab12pWgT5tiaSi9A4iNY77nQmbdROGYbjU+rDkOjIV+qM uSqd/vN9YJDuPo7sRpNjU6nWK+eg+Hxz7Z5jbSOjZ0g7AqZzDl+o/hHNkjbpgnYePJ QtVzy5c5/94vJhSZK5wYRlFWqZYWh66LlRBBWSmh39KWPdcOvSyrJD/WC9T2k/uzdi eAw1txfsm4R3d71W6NXI4E7mOXLjUl5/w/YV0ThY02uCFj4zX5fC+EVUZfCCtqE2dz lbnSzMwZot9bg== Date: Sat, 13 Jan 2024 15:33:13 +0000 From: Simon Horman To: Zhipeng Lu 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] [v3] net/mlx5e: fix a double-free in arfs_create_groups Message-ID: <20240113153313.GH392144@kernel.org> References: <20240112072916.3726945-1-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: <20240112072916.3726945-1-alexious@zju.edu.cn> On Fri, Jan 12, 2024 at 03:29:16PM +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 Thanks, I think this is getting close. Can you please prepare a v4 with the nits below fixed? And please target at the 'net' tree, by making sure it is based on the main branch of that tree, and marking the subject as follows: Subject: [PATCH net v3] ... > --- > Changelog: > > v2: free ft->g just in arfs_create_groups with a unwind ladder. > v3: split the allocation of ft->g and in. Rename the error label. > remove some refector change in v2. > --- > .../net/ethernet/mellanox/mlx5/core/en_arfs.c | 26 +++++++++++-------- > 1 file changed, 15 insertions(+), 11 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c > index bb7f86c993e5..0424ae068a60 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c > @@ -254,11 +254,13 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, > > ft->g = kcalloc(MLX5E_ARFS_NUM_GROUPS, > sizeof(*ft->g), GFP_KERNEL); > - in = kvzalloc(inlen, GFP_KERNEL); > - if (!in || !ft->g) { > - kfree(ft->g); > - kvfree(in); > + if(!ft->g) nit: (one) space after if, please > return -ENOMEM; > + > + in = kvzalloc(inlen, GFP_KERNEL); > + if (!in) { nit: one space is enough after if > + err = -ENOMEM; > + goto err_free_g; > } > > mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria); ..