From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BA8D171078 for ; Fri, 10 May 2024 15:31:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715355098; cv=none; b=sZ8KFxTGd0kjyOmqU3I9bbYJ+pP2vgJPuUOMYSdFWD0A30fWtg/pUwCffzDUDP0w8fQbjLMoP7SvXHBw+c3YgfnZVN9RAbDi8dslndXAItF4LEb9aupaAQABaLao4FRyVgibrSVlmO2mythS4ysSLKw/dKx9yGOZndAUKsVHRF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715355098; c=relaxed/simple; bh=Oi9NEHASOXuewRoh3iOeTIdWpwfp17+Yk6hzeitr6nA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rn7kzhfJWT02GwWm89oFCKuAupkyZm7BubSBzwB55zMw0tCfMUAkrsOpZqZNykoDrrVyp3Yx/WW+CoEO6s/tGNaaN5P36Jdoke1nCuZ/Wx7ghpgXCx637f8amK8pMHLYnfMPTqci37ylKOKU8Yyfy07XkuM+LJU1hxOAg9I98Vo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GlVZZVxI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GlVZZVxI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69970C113CC; Fri, 10 May 2024 15:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715355097; bh=Oi9NEHASOXuewRoh3iOeTIdWpwfp17+Yk6hzeitr6nA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GlVZZVxImpI/8ZrhkbUJR5P357gUHlZa15tvpRJYQz5FX1S7aWgSfwlxpqU57WSJu 0S0NpUmYzNf0wl4XXNLkOVlk8ckPtdxoYlwbF202GASyBChgi+9vksvImGV8E9kR6J oOI/iL9ubaji0ylxD/IrfW1Vfok6BzYKgyEgrE6C1/rpOXlHI/eHUJ8yso6UnPOg9d 1EX9aDGJO1X8aq+CEXSlT5dVnuIIhgCeQXFj0qiE6QUNoYAJNSS/KlyPcF5RuAKCRu 2KduumzFcmcbmd0lAHSPRzSatvNk5HjiNLPADFdcNz9oRobWr4b7mnQXEJ3Wa/4gTs gGvu1Fj+3uO2Q== Date: Fri, 10 May 2024 16:31:33 +0100 From: Simon Horman To: Tariq Toukan Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, Saeed Mahameed , Gal Pressman , Leon Romanovsky , Shay Drory Subject: Re: [PATCH net 1/5] net/mlx5e: Fix netif state handling Message-ID: <20240510153133.GC2347895@kernel.org> References: <20240509112951.590184-1-tariqt@nvidia.com> <20240509112951.590184-2-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240509112951.590184-2-tariqt@nvidia.com> On Thu, May 09, 2024 at 02:29:47PM +0300, Tariq Toukan wrote: > From: Shay Drory > > mlx5e_suspend cleans resources only if netif_device_present() returns > true. However, mlx5e_resume changes the state of netif, via > mlx5e_nic_enable, only if reg_state == NETREG_REGISTERED. > In the below case, the above leads to NULL-ptr Oops[1] and memory > leaks: > > mlx5e_probe > _mlx5e_resume > mlx5e_attach_netdev > mlx5e_nic_enable <-- netdev not reg, not calling netif_device_attach() > register_netdev <-- failed for some reason. > ERROR_FLOW: > _mlx5e_suspend <-- netif_device_present return false, resources aren't freed :( > > Hence, clean resources in this case as well. > > [1] > BUG: kernel NULL pointer dereference, address: 0000000000000000 ... > Fixes: 2c3b5beec46a ("net/mlx5e: More generic netdev management API") > Signed-off-by: Shay Drory > Signed-off-by: Tariq Toukan Hi, I think that this bug is caused by asymmetry in resource allocation/freeing such that there are cases where _mlx5e_suspend() doesn't unwind _mlx5e_resume(). It seems to me that asymmetry was introduced by the check for reg_state != NETREG_REGISTERED in mlx5e_nic_enable() by: 610e89e05c3f ("net/mlx5e: Don't sync netdev state when not registered") So perhaps that is a more appropriate commit for the Fixes tag. I do note that commit was a fix for: 26e59d8077a3 ("net/mlx5e: Implement mlx5e interface attach/detach callbacks") So perhaps a second fixes tag for that commit is also appropriate. Perhaps it's not important enough to revise things, I don't feel strongly about it, so feel free to add the following regardless. Reviewed-by: Simon Horman All that said, I do wonder if it would be better in the long run to implement things in such a way that there is symmetry in resource allocation / deallocation. Passing flags to control how much cleanup is performed does seem a bit awkward.