Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1472694rwj; Sun, 18 Dec 2022 08:51:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf4KwUqBD1MPjCUor+g8XsSi7nEDA3y5QbP3J23GXhpRKuSgPGA7+ss//0wbwzXsKgy1ZREB X-Received: by 2002:a17:906:2284:b0:7c0:4030:ae20 with SMTP id p4-20020a170906228400b007c04030ae20mr35554541eja.24.1671382317965; Sun, 18 Dec 2022 08:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671382317; cv=none; d=google.com; s=arc-20160816; b=HXZMN4EF8ksZnNyV+g47FaKxjvIstQgbcbS5xYzKCJrf6N7SN5aexXo5A9HoUbgBEs Tvg7U9LBDY6mt8OaNb3vAY7tndBNbT3VOg8D0WSkmv5xsON7O7QC0yTiDNcJOiPB2YMe eqOHOzYtX4apuf8cFuC6pQwz+WseCnoHINU45rVXd9afVDW1NgfAugCJZests5zJvLfo mgIHXNI7lEnyDnS2SfMuuYt8h8w/eUmEnxF6rxslCMmB3KqjP2uKtRe58dGjaggS568z 6jtPRNA9SvMG552YFu5jXuHu3KFRgYl2HrmAhGFeTYYxTzmxer5/EK1m5aaR+nF6Wl+o 5c3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K4kN125BkqEdZ83jZv134zUZMHYbkz+csEWqX5QTDiE=; b=L9qP1hu6ssX6mqv0TVTIC+nOUR5vMjWrK8S2nlBgMs9iI9zkn9M/5AQ67Fj8pnTZOs 705uasgo0HtUnpzeZuK9AXfFyxrfhBuwtW4zI97HtX9cS+7J4YQOepPhQvZa9Fx0oEE7 SWrPkglkpC9Oo7ys+y36qijwMO9sScbhZG3Kpu6NYMpVxrASI7nlvl7qHbtK1BV5H09d k6bKL6OSXtf2UF/76RpplCWtnAF+G+h2KGwic2+6m26CshZ2w6Qtz70wB674bc8KYCNH YyqJ4rsEC5XRwrlY3rqe5fvae5nx9CJS1dJLdTCLBLXOsc57XwlRqfSq0ww3zCkNAKem 1LWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j/qsQMSy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gv12-20020a1709072bcc00b007bed39516b0si5903024ejc.921.2022.12.18.08.51.41; Sun, 18 Dec 2022 08:51:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j/qsQMSy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232425AbiLRQjx (ORCPT + 70 others); Sun, 18 Dec 2022 11:39:53 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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