From patchwork Mon Jan 16 15:51:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 1727172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=MgJ6zKPK; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nwdnp3hnmz23fT for ; Tue, 17 Jan 2023 04:10:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7C2B0408FB; Mon, 16 Jan 2023 17:10:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 7C2B0408FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1673889034; bh=HDL0FGpiX1SlxihBYglO26g74c+S0YW3IkYigaj26yw=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=MgJ6zKPKrxfaix8V25f7OlEGuLxOFWyBsIR3a98+Ztv1i0Ge6q14QGeTxw/xm0RGl xzRpvlvsFCwhTCK9kWB2t3YNmLx6AduGaULhZv7f12lOzjn0lcjEh86+Pq9Em+Ff2/ Groh8B1JTC8sXcZjI7KQoyDzX5IOTO3s3P5r5l03AqiL9iL2vynLnJ4XGBncObAdpP 6djSuboVtqwAGIIYfg1LTGoLw5YPuuDUiL1b65Gy43A8a4kD7SbWvnb8DgCOcaiOOJ yu9H+zBAuKKI9Zqj9g42MDFvHnHSc6BwOhhwauBHhpA5Vf6TFpSOQhXg8pV+Lfg5jU 8CP5rALB8IXEw== 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 KZpWbDxTVBMh; Mon, 16 Jan 2023 17:10:33 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp4.osuosl.org (Postfix) with ESMTP id 21B824091B; Mon, 16 Jan 2023 17:10:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 21B824091B X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 3F6E61BF358 for ; Mon, 16 Jan 2023 17:10:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 268B440AAB for ; Mon, 16 Jan 2023 17:10:32 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 268B440AAB X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XkePWUbLwfm0 for ; Mon, 16 Jan 2023 17:10:31 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 52749405DD Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by smtp2.osuosl.org (Postfix) with ESMTPS id 52749405DD for ; Mon, 16 Jan 2023 17:10:31 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 2C3B160F7C; Mon, 16 Jan 2023 17:10:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18A2AC433F0; Mon, 16 Jan 2023 17:10:29 +0000 (UTC) From: Greg Kroah-Hartman To: stable@vger.kernel.org Date: Mon, 16 Jan 2023 16:51:44 +0100 Message-Id: <20230116154831.114401657@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230116154820.689115727@linuxfoundation.org> References: <20230116154820.689115727@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673889029; bh=BNm5SNxOTyJIY1k9U//KXsAwGgHWDnCWhJ6OxhROpTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qoS5td2BNss9Ibx9cjARqS4ydtiD9PeJ6UZQ0l6kkByQnuADbDPCJufzJG2D8PfRR l9dyjGGKhvs9DFsioeodQOOU2kwIKHHbxdTfPy9qrQQf4pApJ2EJLFOBe4n6xnSXbd NzJB0a5IxNInxS/7eujYCGBj9fo0uc7BME5rJMwA= X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=qoS5td2B Subject: [Intel-wired-lan] [PATCH 4.14 231/338] 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 , Greg Kroah-Hartman , patches@lists.linux.dev, Jesse Brandeburg , "Michael J. Ruhl" , Eric Dumazet , netdev@vger.kernel.org, Tony Nguyen , intel-wired-lan@lists.osuosl.org, Jakub Kicinski , Paolo Abeni , "David S. Miller" 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 2c1e3ea8f745..e6799913ca0b 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -1222,8 +1222,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); }