Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp1032978rdf; Wed, 22 Nov 2023 04:03:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKQnOXTEZ64YDUnrEG+BDmn/p7upKzuk1Ha4OfnnJHz9ZjBpcBtXVAjPM1GzTy+eKJPtYO X-Received: by 2002:a05:6820:1622:b0:573:4da2:4427 with SMTP id bb34-20020a056820162200b005734da24427mr2059831oob.7.1700654587359; Wed, 22 Nov 2023 04:03:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700654587; cv=none; d=google.com; s=arc-20160816; b=1FXgM6nOrjW4yyMMi6qprHbG9TvvM5FxB7QJqkAjtdoOkZWzqPK5iZ/U8t3iQmu1Lm u3nZ06/cu4bxcI+ZiBl/sogbrBaE/OIeSWgWtKWW5oO9qol8yeCjSQMYF56XMDoxjXaG lG7J4DfHgg9A7w9dKIFXvdjHknE3m/HghuxddoYqf3eTps2RqZEHYkojAUr+YMh5k0M3 y1D60sVuQTxNv/z24hXfTwBu2Lo0cSXzTPQ2u8jjKVv2vL3l1Yw0ZR5RtzoI5+OZcBGQ INVU1Pn3by+CkiAeI5E+iBcTWhyaivc+H3gdyfM+4GOWHqXFOsxtgkilsjd7hVPK33Zr jvTg== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=s4AM5AgWbEjlkXR5m6+sA+7pho4hdstVB43zNyRXwJs=; fh=X3s78X7zDAC9EAjld4Onk289+lFywPxXSkckyzIWw3M=; b=jDzU7aRE8dMt3A8cwSHyPoFQ/BBZfUVEUHU7ZXgVgVOwIFHsmLJdM4d0Qp44MeA/hu JeKmlCDzuEp4gXJJSiYuDRsyWVYbQAF13ra/MxUAl5DLrBDc//Zhgywg4NMjf1JK/W6A MTRONE3Rn5BWXYquJgehkGdedNdMngFBawFceA916Zn/bDs3SVQqT3YPDCAF/6bizyLg m6UI1FvtlSnT2RbKm8Tpj2ctlVZTF48DcS+0DSqVsFVMNySMK84G75GCXUQZGoZNPSkP kXYy8Y0UN23D2fz0pASEGnwARTeZI/fK1E2t3Kh25DJycSqxkU8r2lhEVCCozuELXCog dFqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SDjSISX5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id w20-20020a4ac194000000b0057117b1b19dsi4246407oop.96.2023.11.22.04.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SDjSISX5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A2CA181972C1; Wed, 22 Nov 2023 04:03:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343876AbjKVMC6 (ORCPT + 99 others); Wed, 22 Nov 2023 07:02:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343732AbjKVMC4 (ORCPT ); Wed, 22 Nov 2023 07:02:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F20D6197 for ; Wed, 22 Nov 2023 04:02:49 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15210C433C7; Wed, 22 Nov 2023 12:02:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700654569; bh=k3VwmQ8DE2uo8esdCeXtKuvUpO2bTcjeZR24PVxbjWc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SDjSISX5iLRS7BlCEmVciXskQBy7RprcCoA9BapM2a+UUUvmvQruzribhnMZrAy4K 0D8qSgA64qchOzX7Sxfy0QPRtSe3V9ZhEqvT1PwRSpDpZQrY16Cboq2iBRmA2aUgV2 FupzbjBJHweGZ0L4NssWQd/Mf9fFNzKbVtGr2SQ9bMS6+Semvju4st7/AXMENNW+Cb /FqA1Y5C7cmTkTfeOVh/R/8Fhs6x4szVDe1KQd/hf9yX8NBAtdbtMqpZeUHM59hlg4 SYt3Zy5DxyIZ9jDtExPYKFVXbsMal+0ncByIKuQsKdLE9KNO7s9c3/ao3bUDk/qJvR jQ+rI6/RxLYVw== Date: Wed, 22 Nov 2023 14:02:45 +0200 From: Leon Romanovsky To: Shifeng Li Cc: saeedm@nvidia.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jackm@dev.mellanox.co.il, ogerlitz@mellanox.com, roland@purestorage.com, eli@mellanox.com, dinghui@sangfor.com.cn, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] net/mlx5e: Fix a race in command alloc flow Message-ID: <20231122120245.GC4760@unreal> References: <20231121115251.588436-1-lishifeng1992@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231121115251.588436-1-lishifeng1992@126.com> X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Wed, 22 Nov 2023 04:03:04 -0800 (PST) On Tue, Nov 21, 2023 at 03:52:51AM -0800, Shifeng Li wrote: > Fix a cmd->ent use after free due to a race on command entry. > Such race occurs when one of the commands releases its last refcount and > frees its index and entry while another process running command flush > flow takes refcount to this command entry. The process which handles > commands flush may see this command as needed to be flushed if the other > process allocated a ent->idx but didn't set ent to cmd->ent_arr in > cmd_work_handler(). Fix it by moving the assignment of cmd->ent_arr into > the spin lock. > > [70013.081955] BUG: KASAN: use-after-free in mlx5_cmd_trigger_completions+0x1e2/0x4c0 [mlx5_core] > [70013.081967] Write of size 4 at addr ffff88880b1510b4 by task kworker/26:1/1433361 > [70013.081968] > [70013.081989] CPU: 26 PID: 1433361 Comm: kworker/26:1 Kdump: loaded Tainted: G OE 4.19.90-25.17.v2101.osc.sfc.6.10.0.0030.ky10.x86_64+debug #1 > [70013.082001] Hardware name: SANGFOR 65N32-US/ASERVER-G-2605, BIOS SSSS5203 08/19/2020 > [70013.082028] Workqueue: events aer_isr > [70013.082053] Call Trace: > [70013.082067] dump_stack+0x8b/0xbb > [70013.082086] print_address_description+0x6a/0x270 > [70013.082102] kasan_report+0x179/0x2c0 > [70013.082133] ? mlx5_cmd_trigger_completions+0x1e2/0x4c0 [mlx5_core] > [70013.082173] mlx5_cmd_trigger_completions+0x1e2/0x4c0 [mlx5_core] > [70013.082213] ? mlx5_cmd_use_polling+0x20/0x20 [mlx5_core] > [70013.082223] ? kmem_cache_free+0x1ad/0x1e0 > [70013.082267] mlx5_cmd_flush+0x80/0x180 [mlx5_core] > [70013.082304] mlx5_enter_error_state+0x106/0x1d0 [mlx5_core] > [70013.082338] mlx5_try_fast_unload+0x2ea/0x4d0 [mlx5_core] > [70013.082377] remove_one+0x200/0x2b0 [mlx5_core] > [70013.082390] ? __pm_runtime_resume+0x58/0x70 > [70013.082409] pci_device_remove+0xf3/0x280 > [70013.082426] ? pcibios_free_irq+0x10/0x10 > [70013.082439] device_release_driver_internal+0x1c3/0x470 > [70013.082453] pci_stop_bus_device+0x109/0x160 > [70013.082468] pci_stop_and_remove_bus_device+0xe/0x20 > [70013.082485] pcie_do_fatal_recovery+0x167/0x550 > [70013.082493] aer_isr+0x7d2/0x960 > [70013.082510] ? aer_get_device_error_info+0x420/0x420 > [70013.082526] ? __schedule+0x821/0x2040 > [70013.082536] ? strscpy+0x85/0x180 > [70013.082543] process_one_work+0x65f/0x12d0 > [70013.082556] worker_thread+0x87/0xb50 > [70013.082563] ? __kthread_parkme+0x82/0xf0 > [70013.082569] ? process_one_work+0x12d0/0x12d0 > [70013.082571] kthread+0x2e9/0x3a0 > [70013.082579] ? kthread_create_worker_on_cpu+0xc0/0xc0 > [70013.082592] ret_from_fork+0x1f/0x40 I'm curious how did you get this error? I would expect to see some sort of lock in upper level which prevents it. Thanks