Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2294129rda; Tue, 24 Oct 2023 20:27:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+wuldiK2wEQzz4zjbdaJLQS8vipQjoREchtsizuFjbYygmyoVr77HFYoOQKosjV46YSku X-Received: by 2002:a0d:cbcb:0:b0:5a7:b557:6595 with SMTP id n194-20020a0dcbcb000000b005a7b5576595mr13693442ywd.21.1698204456979; Tue, 24 Oct 2023 20:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698204456; cv=none; d=google.com; s=arc-20160816; b=iUYq9pQiHdxUF/ZOjz9LB6upWoF7UtTImQx5Ayzvx9QLwu2es1YbZJGk2TiQ04YQ0B OrZx56bO2DMONO7kei8pC5pOj0IqvrynfvtoQdUhbQBef/69q2/cA4v1S7Trz/Wi6fsF NkD29479nAzdtMr/eBgoVwsFiMBWmIsW04JG0Ui2YD5YJY8iMw9KOg6COzuaPGzsVdV3 zyBs4eJr2OAd6m96q2fgWMbq2MldK/XTSHnvD5LmehsodR5TcYkZiae9hIfRA6t6pre9 KTHNdXHDS28acnu5RBPMvvXxJgx2uRm8FGPTIpfIgQfGAtGf/6NfXT6nnDPTh3uxFZ8w 4glQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=aoRaudJsvtIqP/aQlB9S9+b8ActGFq5NSSmYXubbDko=; fh=h+NtxpuPh+r52TWdP/RrMrHjdUrZDXvraCXjjk96ng8=; b=PKQlN9yU16UUpk8LynxaQtUYlglihSHsUdrjhey/ARrlYF32AxldWGP+Rjv/b2z1ea ZvmWSVYprWUkCpiN0Wfih8ru5brYXRaAxLVU1/0tzGFrvA+vmGR+x1tg6bBuxqGLVa0J Sf2n9w9L8y7lvwdd0+XQaXwK2VrLv0hbEC5tI5Yduzt4a8ZcJcRgla2JTjK6Y073VqOm Y+fk6C9WcoREN5Dc+deb+hsMBd0OEQtEaLH4A5o4JUzBtcJ+ISS1f1vjtZE2XJxfEK2o g2FOhNhVbFlm5f1+qNMtWEUZuKDmK/mlDSup/F71xbQqacdq3tY0VXi1zVnUnJLjtz6V iI4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id a11-20020a81bb4b000000b005a7aa3faa68si10390680ywl.138.2023.10.24.20.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 20:27:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 87B5A8023EC3; Tue, 24 Oct 2023 20:27:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbjJYD1X (ORCPT + 99 others); Tue, 24 Oct 2023 23:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232486AbjJYD1V (ORCPT ); Tue, 24 Oct 2023 23:27:21 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26FC9B4; Tue, 24 Oct 2023 20:27:16 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=dust.li@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VusqkGd_1698204432; Received: from localhost(mailfrom:dust.li@linux.alibaba.com fp:SMTPD_---0VusqkGd_1698204432) by smtp.aliyun-inc.com; Wed, 25 Oct 2023 11:27:13 +0800 From: Dust Li To: Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Dust Li , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Cruz Zhao , Tianchen Ding Subject: [PATCH net] net/mlx5e: fix double free of encap_header Date: Wed, 25 Oct 2023 11:27:12 +0800 Message-Id: <20231025032712.79026-1-dust.li@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 20:27:34 -0700 (PDT) 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) 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 --- 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); -- 2.19.1.6.gb485710b