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 7641EC4332F for ; Sun, 18 Dec 2022 16:13:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 049E7606AA; Sun, 18 Dec 2022 16:13:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 049E7606AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1671380034; bh=3CCKbjBgXO5kdhPffLStnz+iBnitYZa9p+hU/puY+js=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=iaXWnCyWroIPXq77e1vZjpQZlwNUmv2XbADYAu0uhD39LbOVTgmGF4iEVsaH8E5Xl jF/POec2lydOOrBKL2ey+dyaArHIAgSj6oHlSJc0TiS57z3PEQlqx+QN5ENK/BkaZy 2qXxXouClxVPy3LeCMgJnUai1UTFAqKC7gNdAW8gGojHEmDOoYEKb2XwEC9fdBq8io pQqUzZKQJR8tSQ5BeW064eFBvr3JY8s7sPbe+OUZqz0ZwvBmIT7W9Jq4F+uun4p9Y8 0uxYcFzydYHpXKyfAVGkchHoUiRJMf5zOcjD1mfjQxOQop24kzzxZ3bl5y2e0q5o2t RsMePrwBM3QnQ== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hY25rUvx0xFm; Sun, 18 Dec 2022 16:13:53 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id ED43D60706; Sun, 18 Dec 2022 16:13:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org ED43D60706 Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 5FA9A1BF3A3 for ; Sun, 18 Dec 2022 16:13:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 2CD9240632 for ; Sun, 18 Dec 2022 16:13:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 2CD9240632 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DUBqhNtwwLyI for ; Sun, 18 Dec 2022 16:13:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 2E63C404CC Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by smtp4.osuosl.org (Postfix) with ESMTPS id 2E63C404CC for ; Sun, 18 Dec 2022 16:13:50 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 83AE4B80B43; Sun, 18 Dec 2022 16:13:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5968C433EF; Sun, 18 Dec 2022 16:13:46 +0000 (UTC) From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Sun, 18 Dec 2022 11:12:13 -0500 Message-Id: <20221218161244.930785-15-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380028; bh=y48vZNvlUBVKupBmNUPIXPfFYobLj2yzad9v9f3aaF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/qsQMSyakSqvDaTB5mlMO52T4uX+9Fu7YlyG0MFdzp9RcMl4Q78CI8TmBOEELFbm dSFwQ5YqEtDRxy/nFjRgKWBbzR9FZOFQQXnCVSUgcyR45aAVt5he1I7fGP0XyrmWLZ ViGR2a4Z7AEqtPaPT/wBw1az/POcCCugt4UpYD6x9KqCNu1798Kru/8pkf+e5jNxvb KTB1LGDZ0/UtbRpblNq3eD1+QucCUBCmr/gwjqnIbPHGz4QyP+VqhXYQxqV0Sx/yKe OmbTZrTFsHLYO4rOXhuZgnaeK7XjhK/CvfXa93o+qxIAQCPH+daCZnWQD6tUMbqgmN JdrGYzMf0kQHQ== 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=j/qsQMSy Subject: [Intel-wired-lan] [PATCH AUTOSEL 5.15 15/46] igb: Do not free q_vector unless new one was allocated 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: Sasha Levin , Kees Cook , intel-wired-lan@lists.osuosl.org, Jesse Brandeburg , "Michael J . Ruhl" , Eric Dumazet , Tony Nguyen , netdev@vger.kernel.org, Jakub Kicinski , Paolo Abeni , "David S. Miller" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" From: Kees Cook [ Upstream commit 0668716506ca66f90d395f36ccdaebc3e0e84801 ] Avoid potential use-after-free condition under memory pressure. If the kzalloc() fails, q_vector will be freed but left in the original adapter->q_vector[v_idx] array position. Cc: Jesse Brandeburg Cc: Tony Nguyen Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook Reviewed-by: Michael J. Ruhl Reviewed-by: Jacob Keller Tested-by: Gurucharan (A Contingent worker at Intel) Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index f19e64830739..1a2455c1d091 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -1204,8 +1204,12 @@ static int igb_alloc_q_vector(struct igb_adapter *adapter, if (!q_vector) { q_vector = kzalloc(size, GFP_KERNEL); } else if (size > ksize(q_vector)) { - kfree_rcu(q_vector, rcu); - q_vector = kzalloc(size, GFP_KERNEL); + struct igb_q_vector *new_q_vector; + + new_q_vector = kzalloc(size, GFP_KERNEL); + if (new_q_vector) + kfree_rcu(q_vector, rcu); + q_vector = new_q_vector; } else { memset(q_vector, 0, size); } -- 2.35.1 _______________________________________________ Intel-wired-lan mailing list Intel-wired-lan@osuosl.org https://lists.osuosl.org/mailman/listinfo/intel-wired-lan 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17953C4167B for ; Sun, 18 Dec 2022 16:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232413AbiLRQjs (ORCPT ); Sun, 18 Dec 2022 11:39:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232414AbiLRQjK (ORCPT ); Sun, 18 Dec 2022 11:39:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0723183A2; Sun, 18 Dec 2022 08:13:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C3E4160DCC; Sun, 18 Dec 2022 16:13:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5968C433EF; Sun, 18 Dec 2022 16:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380028; bh=y48vZNvlUBVKupBmNUPIXPfFYobLj2yzad9v9f3aaF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/qsQMSyakSqvDaTB5mlMO52T4uX+9Fu7YlyG0MFdzp9RcMl4Q78CI8TmBOEELFbm dSFwQ5YqEtDRxy/nFjRgKWBbzR9FZOFQQXnCVSUgcyR45aAVt5he1I7fGP0XyrmWLZ ViGR2a4Z7AEqtPaPT/wBw1az/POcCCugt4UpYD6x9KqCNu1798Kru/8pkf+e5jNxvb KTB1LGDZ0/UtbRpblNq3eD1+QucCUBCmr/gwjqnIbPHGz4QyP+VqhXYQxqV0Sx/yKe OmbTZrTFsHLYO4rOXhuZgnaeK7XjhK/CvfXa93o+qxIAQCPH+daCZnWQD6tUMbqgmN JdrGYzMf0kQHQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, "Michael J . Ruhl" , Jacob Keller , Gurucharan , Sasha Levin Subject: [PATCH AUTOSEL 5.15 15/46] igb: Do not free q_vector unless new one was allocated Date: Sun, 18 Dec 2022 11:12:13 -0500 Message-Id: <20221218161244.930785-15-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Kees Cook [ Upstream commit 0668716506ca66f90d395f36ccdaebc3e0e84801 ] Avoid potential use-after-free condition under memory pressure. If the kzalloc() fails, q_vector will be freed but left in the original adapter->q_vector[v_idx] array position. Cc: Jesse Brandeburg Cc: Tony Nguyen Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook Reviewed-by: Michael J. Ruhl Reviewed-by: Jacob Keller Tested-by: Gurucharan (A Contingent worker at Intel) Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index f19e64830739..1a2455c1d091 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -1204,8 +1204,12 @@ static int igb_alloc_q_vector(struct igb_adapter *adapter, if (!q_vector) { q_vector = kzalloc(size, GFP_KERNEL); } else if (size > ksize(q_vector)) { - kfree_rcu(q_vector, rcu); - q_vector = kzalloc(size, GFP_KERNEL); + struct igb_q_vector *new_q_vector; + + new_q_vector = kzalloc(size, GFP_KERNEL); + if (new_q_vector) + kfree_rcu(q_vector, rcu); + q_vector = new_q_vector; } else { memset(q_vector, 0, size); } -- 2.35.1