From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CB12CE7AE8 for ; Fri, 6 Sep 2024 08:30:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0008660B17; Fri, 6 Sep 2024 08:30:46 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 5o-Ae9Lixfwf; Fri, 6 Sep 2024 08:30:46 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.34; helo=ash.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3C10260BB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1725611446; bh=WFUfnBfRtyio+90VekMcNUlTF0vl7wv9aDL1Yw/3kqA=; h=Date:From:To:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=4zQ28l10bdqQCsZ1SfAiu2AlVuejLUALDn7s7u3QrbnqFpToRkLE5tlBeNEEg3srs ri0K/9FNRcTyeqBVS5isPJo3yJXq3+Xh/Zko8swJUSqMl8o0oeIvJ1zok193wEPBI/ KV9qUN7T/dB8Wj5MT7pdCVUQkNPDofQgd7j8BCr1Z/eT/WH4AkHzMRuwV76Ce1kF18 KEDc+JpidKs/2O3ilPzZ0t6Q6fO7xFwwIyxhRk1eIXAJd1YIVaSIAg4RA9IupJ0zjC fIh7gHF4D/O/Qu7OE9DcdT0Q51zBD8pN5opTZq88t1mSJK28TdGMOmxw1khfNEqRrk muwJizUOp1ddg== Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 3C10260BB2; Fri, 6 Sep 2024 08:30:46 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 11A361BF355 for ; Fri, 6 Sep 2024 08:30:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 08AE440967 for ; Fri, 6 Sep 2024 08:30:45 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ZLnCpARscZ_S for ; Fri, 6 Sep 2024 08:30:44 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=139.178.84.217; helo=dfw.source.kernel.org; envelope-from=horms@kernel.org; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 21BFC406F9 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 21BFC406F9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by smtp4.osuosl.org (Postfix) with ESMTPS id 21BFC406F9 for ; Fri, 6 Sep 2024 08:30:44 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 759E65C5B03; Fri, 6 Sep 2024 08:30:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 619BBC4CEC4; Fri, 6 Sep 2024 08:30:40 +0000 (UTC) Date: Fri, 6 Sep 2024 09:30:38 +0100 From: Simon Horman To: Gui-Dong Han Message-ID: <20240906083038.GC2097826@kernel.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725611442; bh=A5dq9VXSOyYLnbKAephiLb4/q2ZPRZWcqiBaCOExek4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SWv0+dmp0VjjpwgOjn/rgchbdug4Cxd8CeXi17mh1b0caKbFg21RCbpO1xdkdEA3+ UymzcCa7gSnv4pDx4yzQTEuwr2Jz/z58ImXpGaDYfed7FPRb4CaAt1b/4gFuZP9Y8c 9EZf8pTXk6Ycd3KP+Vi4IDTRUNB2QcuS8RU6dy8JBVho43tpxE0T3sRwSn67l1Actk 6lIZoXB/cJJrtaigyAABRHFX9913ntCZJR2iHERmKaCl7C+mPy8r8izFNlYviDJpAZ q8aXYWL6HPNNRKB9ZtzJhIhYM3DmAfDbVAioCltQU9AwdksKpsW7nMfewX8PLvb+dH LZG4fbO9qdUzw== X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=SWv0+dmp Subject: Re: [Intel-wired-lan] [PATCH v2] ice: Fix improper handling of refcount in ice_sriov_set_msix_vec_count() X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: przemyslaw.kitszel@intel.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, edumazet@google.com, netdev@vger.kernel.org, anthony.l.nguyen@intel.com, intel-wired-lan@lists.osuosl.org, baijiaju1990@gmail.com, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" On Tue, Sep 03, 2024 at 11:59:43AM +0000, Gui-Dong Han wrote: > This patch addresses an issue with improper reference count handling in the > ice_sriov_set_msix_vec_count() function. > > First, the function calls ice_get_vf_by_id(), which increments the > reference count of the vf pointer. If the subsequent call to > ice_get_vf_vsi() fails, the function currently returns an error without > decrementing the reference count of the vf pointer, leading to a reference > count leak. The correct behavior, as implemented in this patch, is to > decrement the reference count using ice_put_vf(vf) before returning an > error when vsi is NULL. > > Second, the function calls ice_sriov_get_irqs(), which sets > vf->first_vector_idx. If this call returns a negative value, indicating an > error, the function returns an error without decrementing the reference > count of the vf pointer, resulting in another reference count leak. The > patch addresses this by adding a call to ice_put_vf(vf) before returning > an error when vf->first_vector_idx < 0. > > This bug was identified by an experimental static analysis tool developed > by our team. The tool specializes in analyzing reference count operations > and identifying potential mismanagement of reference counts. In this case, > the tool flagged the missing decrement operation as a potential issue, > leading to this patch. > > Fixes: 4035c72dc1ba ("ice: reconfig host after changing MSI-X on VF") > Fixes: 4d38cb44bd32 ("ice: manage VFs MSI-X using resource tracking") > Cc: stable@vger.kernel.org > Signed-off-by: Gui-Dong Han > --- > v2: > * In this patch v2, an additional resource leak was addressed when > vf->first_vector_idx < 0. The issue is now fixed by adding ice_put_vf(vf) > before returning an error. > Thanks to Simon Horman for identifying this additional leak scenario. Thanks for the update, I agree with the analysis and that the two instances of this problem were introduced by each of the cited commits. Reviewed-by: Simon Horman