Message ID | 20231224081348.3535146-1-alexious@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-10654-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp2034056dyi; Sun, 24 Dec 2023 00:15:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkvi2CKyD3dB0IyLZlFHYDu6SbnW/Cxt3V3+bIQOC2oPwh3TGGQLy8OT49cBGzfLlRbFT/ X-Received: by 2002:a05:6808:38c3:b0:3bb:a0e2:8d51 with SMTP id el3-20020a05680838c300b003bba0e28d51mr1579035oib.2.1703405711616; Sun, 24 Dec 2023 00:15:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703405711; cv=none; d=google.com; s=arc-20160816; b=rdiCRSkPv+NM2j/AlsYrPSgyw07IUTsRKcNtLDaA5FXO1nvjyQxfKAKWD9HmBaRfJt nMfm7FxQ7+daWgRTwgbZevlFW5GjLXi+F3OReYymRw4Zr5uTjF9I01cGRSVbIV47t9Hq /OBOrxhLr3IiOpYAh0wTXG+AUvBK6bGRUkMUjajCfv+8XHdZ74aPZToD0SBks5lAyhEd u+1UkenSA0everN1L5x1RmUDSHtn/JRvZBUqGhogmf28UgCgOQPIJjje68CWu4vMUQOj QA2NoDMWY7W5PlDDVb63erR4NUL/2Kur/rCa02lOGnnR+mqopX3JwfzP2tCpydDDOFTY 6OvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=Od0uX9evnS2w6lLd69OZ/spnKiWNoiPN5Kis1sIWx9M=; fh=/Gu90RCdx+gNxSpHGyvqQQX/gt6LIkzdEDoQg/3nweQ=; b=jhG/jyFrSm9qraL+Oc9NL6o9JN0QuCh7r8Zi1/q6pdPYazUrU8Lj1qihCT5fo8DzHe 5rvU4UT+5N2vZ6p1asxQBiWxx5N86ZJEhNwkqDYpF02QPmnj71dhheTSVAtdK6LdpWs8 X46VwO0YgczO/CcHbsft15KVD7gZDEZNcXj08HNyRYMqG5+35ryOrnhtWv51ilCJhl+m EwR/h5UlugWQmumlutWb7aAsD4nWHzlpucTO1PD4Sg/Kqpg8QzYEt7moVROVkwCQnnHh XqBbK0Mi0WQUd0fCZlNv1vngBsbRrV1q2K/LCDdncV0qFwOEHeqYmsjkHvyA3zuf0jQI RpsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10654-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y4-20020aa78044000000b006d983f1b146si4162208pfm.274.2023.12.24.00.15.11 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 00:15:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10654-ouuuleilei=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6C9AEB2129A for <ouuuleilei@gmail.com>; Sun, 24 Dec 2023 08:15:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9005E23C3; Sun, 24 Dec 2023 08:14:45 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from zg8tmtu5ljg5lje1ms4xmtka.icoremail.net (zg8tmtu5ljg5lje1ms4xmtka.icoremail.net [159.89.151.119]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF4A91383; Sun, 24 Dec 2023 08:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [39.174.92.167]) by mail-app3 (Coremail) with SMTP id cC_KCgA3ro1U6IdlArdjAQ--.38379S2; Sun, 24 Dec 2023 16:14:13 +0800 (CST) From: Zhipeng Lu <alexious@zju.edu.cn> To: alexious@zju.edu.cn Cc: Saeed Mahameed <saeedm@nvidia.com>, Leon Romanovsky <leon@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Maor Gottlieb <maorg@mellanox.com>, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net/mlx5e: fix a double-free in arfs_create_groups Date: Sun, 24 Dec 2023 16:13:48 +0800 Message-Id: <20231224081348.3535146-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cC_KCgA3ro1U6IdlArdjAQ--.38379S2 X-Coremail-Antispam: 1UD129KBjvdXoW7Gry3CFWUAF4fGr4UAF4ruFg_yoWDWrg_CF 1UXwn5Cwn0vr4Ykw43WrZ8XrWIkr4qgrnayFZIgFy5Jw4UWryxZ3yxWa4fXF4xWFy8X3ZI y343tF13u34UAjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbx8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFyl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j 6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdHU DUUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786150347478267593 X-GMAIL-MSGID: 1786150347478267593 |
Series |
net/mlx5e: fix a double-free in arfs_create_groups
|
|
Commit Message
Zhipeng Lu
Dec. 24, 2023, 8:13 a.m. UTC
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 <alexious@zju.edu.cn>
---
drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c | 1 +
1 file changed, 1 insertion(+)
Comments
On Sun, Dec 24, 2023 at 04:13:48PM +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 <alexious@zju.edu.cn> Thanks, I agree this addresses the issue that you describe. And as a minimal fix it looks good. Reviewed-by: Simon Horman <horms@kernel.org> However, I would like to suggest that some clean-up work could take place as a follow-up. I think that the error handling in this area of the code is rather fragile. This is because initialisation is not necessarily unwound on error within the function that initialisation occurs. I think it would be better if arfs_create_groups(): 1. Released allocates resources it allocates, including ft->g and elements of ft->g, on error. 2. This was achieved by using a goto unwind ladder. 3. The caller treated ft->g as uninitialised if arfs_create_groups fails. Likewise, I think that: * arfs_create_groups, should initialise ft->num_groups And further, logic similar to the above should guide how arfs_create_table() initialises ft->t and cleans it up on error. I did not look at the code beyond the scope described above. But the above are general principles that may well apply in other nearby code too. ...
> On Sun, Dec 24, 2023 at 04:13:48PM +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 <alexious@zju.edu.cn> > > Thanks, > > I agree this addresses the issue that you describe. > And as a minimal fix it looks good. > > Reviewed-by: Simon Horman <horms@kernel.org> > > However, I would like to suggest that some clean-up work could > take place as a follow-up. > > I think that the error handling in this area of the code > is rather fragile. This is because initialisation is not necessarily > unwound on error within the function that initialisation occurs. > > I think it would be better if arfs_create_groups(): > > 1. Released allocates resources it allocates, including ft->g and > elements of ft->g, on error. > 2. This was achieved by using a goto unwind ladder. > 3. The caller treated ft->g as uninitialised if > arfs_create_groups fails. > Agree, I think a unwind ladder for arfs_create_groups is much better. I'll follow this idea to send a v2 patch later. Another comment below. > Likewise, I think that: > > * arfs_create_groups, should initialise ft->num_groups > > And further, logic similar to the above should guide > how arfs_create_table() initialises ft->t and cleans it > up on error. > I think that ft->t you mentioned refers to mlx5_create_flow_table. I'd like to make the life cycle of ft->t similar to ft->g in arfs_create_groups, but it needs to add an argument for mlx5_create_flow_table to transfer ft to it. However, mlx5_create_flow_table is called in more than 30 different places throughout the kernel. So such modification could be another refactoring patch but may be out of this fix patch's duty. > I did not look at the code beyond the scope described above. > But the above are general principles that may well apply in > other nearby code too. > > ...
On Mon, Jan 08, 2024 at 05:12:06PM +0800, alexious@zju.edu.cn wrote: > > > > On Sun, Dec 24, 2023 at 04:13:48PM +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 <alexious@zju.edu.cn> > > > > Thanks, > > > > I agree this addresses the issue that you describe. > > And as a minimal fix it looks good. > > > > Reviewed-by: Simon Horman <horms@kernel.org> > > > > However, I would like to suggest that some clean-up work could > > take place as a follow-up. > > > > I think that the error handling in this area of the code > > is rather fragile. This is because initialisation is not necessarily > > unwound on error within the function that initialisation occurs. > > > > I think it would be better if arfs_create_groups(): > > > > 1. Released allocates resources it allocates, including ft->g and > > elements of ft->g, on error. > > 2. This was achieved by using a goto unwind ladder. > > 3. The caller treated ft->g as uninitialised if > > arfs_create_groups fails. > > > > Agree, I think a unwind ladder for arfs_create_groups is much better. > I'll follow this idea to send a v2 patch later. Thanks. > Another comment below. > > > Likewise, I think that: > > > > * arfs_create_groups, should initialise ft->num_groups > > > > And further, logic similar to the above should guide > > how arfs_create_table() initialises ft->t and cleans it > > up on error. > > > > I think that ft->t you mentioned refers to mlx5_create_flow_table. > I'd like to make the life cycle of ft->t similar to ft->g in arfs_create_groups, > but it needs to add an argument for mlx5_create_flow_table to transfer ft to > it. However, mlx5_create_flow_table is called in more than 30 different places > throughout the kernel. So such modification could be another refactoring patch > but may be out of this fix patch's duty. I agree there is no need to solve all problems in this patch :) > > I did not look at the code beyond the scope described above. > > But the above are general principles that may well apply in > > other nearby code too. > > > > ...
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c index bb7f86c993e5..d9a60bd04167 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c @@ -257,6 +257,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, in = kvzalloc(inlen, GFP_KERNEL); if (!in || !ft->g) { kfree(ft->g); + ft->g = NULL; kvfree(in); return -ENOMEM; }