Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp960863rdh; Thu, 26 Oct 2023 23:59:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmlzTsWSNDRbnLdDbJhMmK4BO77FrZUVc4cwS2cJAzdlm/MSf0n4Mvv6boIg+1cEWDgXrv X-Received: by 2002:a05:690c:f89:b0:5a7:da36:4d33 with SMTP id df9-20020a05690c0f8900b005a7da364d33mr1857773ywb.25.1698389962969; Thu, 26 Oct 2023 23:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698389962; cv=none; d=google.com; s=arc-20160816; b=ymAd/6OMedXPeyfBBHVwp92ON9uFgz3lvCIyPkkweFSljvchLlaxf0f8itkBZ4yBu9 8JKfZkiDjS+vUDMHXc+PwLdyV6uH9ix5vkOc6+avHAsnrUWNs1k/KUWxkXFLeyejW2hQ bsloHkrfIRq1DPhYGfIVBsw/1S4kb3b2OhnXACQuwbTtVFVg4eMBGn4L9mWrLhWOog46 n+nv7U7RVdY2xatl6bXBhh+rBq7s/h7Mh6i69e2uGRBBMzwWSxWihZI7PN7HzmcC2KUG mNVyxTtztE2bKUmkE+6i7JNi0w2bRdnwBxmwb0fwvh8LPZNHzWzKPcFU+dcc4dyDC3kY j5RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date; bh=DVCtosiZMSkXowGyzZg8gbhrfW2n5Jl/vv9jrf9sXXk=; fh=+kMn5pQJgwZhQR4fWvAFrb+say+h+TjQH+arCm7xmnA=; b=UwBUgUbHbtmVL498ii1a5N4wXi0wmE27FYJ/l7HOnkBvlo1BKYyqV947wW0kS/QVcN 7IZ/+YXb7VyHIGVsQ1GvZnD3CT909mMLVEtAK0e6k7h2slrKKWzPpISTeOd9Hn4SdiWD F2s2Z6RD+1Kj1xBbcq7iJFfFNNZU/PfXLEyK6L7Od0JiGh1WiZdbYil4OGNH+tDCAF6F Cjwg1X2YY3PxBpab+WO1gBJoS1PZC9CCRjOz3tBQ1sglPB9hOOvkpM+De/ZPl0IQg5Mq xRHIQY/YLFoo1WyUIME3cfXudivAq1nxyVHa9k6r+dYphl+z6XlK6ntsE5jmJAG33MNF ocZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z142-20020a814c94000000b005afd3eabb2bsi771357ywa.509.2023.10.26.23.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 23:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 37E008112AAF; Thu, 26 Oct 2023 23:59:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbjJ0G7F (ORCPT + 99 others); Fri, 27 Oct 2023 02:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjJ0G7E (ORCPT ); Fri, 27 Oct 2023 02:59:04 -0400 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 016651AA; Thu, 26 Oct 2023 23:58:59 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R891e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=dust.li@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0Vv-4-7R_1698389935; Received: from localhost(mailfrom:dust.li@linux.alibaba.com fp:SMTPD_---0Vv-4-7R_1698389935) by smtp.aliyun-inc.com; Fri, 27 Oct 2023 14:58:55 +0800 Date: Fri, 27 Oct 2023 14:58:54 +0800 From: Dust Li To: Wojciech Drewek , Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Cruz Zhao , Tianchen Ding Subject: Re: [PATCH net] net/mlx5e: fix double free of encap_header Message-ID: <20231027065854.GB92403@linux.alibaba.com> Reply-To: dust.li@linux.alibaba.com References: <20231025032712.79026-1-dust.li@linux.alibaba.com> <5a89b15e-e4ca-4e06-9069-6f005c6884f2@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5a89b15e-e4ca-4e06-9069-6f005c6884f2@intel.com> X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 26 Oct 2023 23:59:20 -0700 (PDT) On Wed, Oct 25, 2023 at 11:06:25AM +0200, Wojciech Drewek wrote: > > >On 25.10.2023 05:27, Dust Li wrote: >> When mlx5_packet_reformat_alloc() fails, the encap_header allocated in >> mlx5e_tc_tun_create_header_ipv4{6} will be released within it. However, >> e->encap_header is already set to the previously freed encap_header >> before mlx5_packet_reformat_alloc(). As a result, the later >> mlx5e_encap_put() will free e->encap_header again, causing a double free >> issue. >> >> mlx5e_encap_put() >> --> mlx5e_encap_dealloc() >> --> kfree(e->encap_header) > >nit: I think it should mlx5e_encap_put_locked not mlx5e_encap_put to be precise. You are right. The original version is mlx5e_encap_put, I mistakenly used the name of the old version when doing git blame. Best regards, Dust > >> >> This happens when cmd: MLX5_CMD_OP_ALLOC_PACKET_REFORMAT_CONTEXT fail. >> >> This patch fix it by not setting e->encap_header until >> mlx5_packet_reformat_alloc() success. >> >> Fixes: d589e785baf5e("net/mlx5e: Allow concurrent creation of encap entries") >> Reported-by: Cruz Zhao >> Reported-by: Tianchen Ding >> Signed-off-by: Dust Li >> --- > >Reviewed-by: Wojciech Drewek > >> drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 10 ++++------ >> 1 file changed, 4 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c >> index 00a04fdd756f..8bca696b6658 100644 >> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c >> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c >> @@ -300,9 +300,6 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, >> if (err) >> goto destroy_neigh_entry; >> >> - e->encap_size = ipv4_encap_size; >> - e->encap_header = encap_header; >> - >> if (!(nud_state & NUD_VALID)) { >> neigh_event_send(attr.n, NULL); >> /* the encap entry will be made valid on neigh update event >> @@ -322,6 +319,8 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, >> goto destroy_neigh_entry; >> } >> >> + e->encap_size = ipv4_encap_size; >> + e->encap_header = encap_header; >> e->flags |= MLX5_ENCAP_ENTRY_VALID; >> mlx5e_rep_queue_neigh_stats_work(netdev_priv(attr.out_dev)); >> mlx5e_route_lookup_ipv4_put(&attr); >> @@ -568,9 +567,6 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, >> if (err) >> goto destroy_neigh_entry; >> >> - e->encap_size = ipv6_encap_size; >> - e->encap_header = encap_header; >> - >> if (!(nud_state & NUD_VALID)) { >> neigh_event_send(attr.n, NULL); >> /* the encap entry will be made valid on neigh update event >> @@ -590,6 +586,8 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, >> goto destroy_neigh_entry; >> } >> >> + e->encap_size = ipv6_encap_size; >> + e->encap_header = encap_header; >> e->flags |= MLX5_ENCAP_ENTRY_VALID; >> mlx5e_rep_queue_neigh_stats_work(netdev_priv(attr.out_dev)); >> mlx5e_route_lookup_ipv6_put(&attr);