Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3413157rwa; Tue, 23 Aug 2022 04:29:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR4M3eZJ7W9S66vU5oBw1PDYIn1UiPYN+JYr66212eKgzJ9kikMK0WzNxlczM+VkDWD4gN9q X-Received: by 2002:a17:907:762c:b0:73d:9044:ff29 with SMTP id jy12-20020a170907762c00b0073d9044ff29mr3990931ejc.19.1661254164314; Tue, 23 Aug 2022 04:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254164; cv=none; d=google.com; s=arc-20160816; b=N5tBsyXLS0gcEwkRJ7g28D+EyCpkerNZKm0dFk44lTXGNk/GA4fIS3x8hLB5rZsezj DqFz/LZAN9+zLl68Lo0PjCCGPz47yJ8RPCh2zGH2oaLv3jWl1Et0SmGjUhKiDcsBHWg6 0ROHQr8sJNy+aSrE5VvXawlIWSSVtcQYuwdMXarPLhk/OTGuQ3yKkfa7xnxsfqt0jwC4 rz9Ks3+J9kWx9VAQrE2rjtzfcXvUSylavG/EyfhBXukHxcwYx8XkMavcY2ykHBiCviAD BUU6mIAZe/qcYPml2HNRNKgopI2LyhUAMcnsLp7+IT5FsL2U4KhmE6wKlLbl924VfRO3 AGmw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Frd/EVD1dkuwP/oEJj6mXweEiMkYM55VDLgFKcLnzYs=; b=WfWzHMqIdMljaG6JMFe6pkdOlaCj9nFX8TXXl5BJpeu+TIg2rsG5xUCkAytDDLNA98 EPaGdM5Y02wb0qO6ZZTgQig6qPdLbXD5Ec5YLOz0PTzhXQg53FbxTTcaNoxS1SSgl3PC R6MmQNb1SSmZCUQwDOKXmVtKG7tS+2Tjijxx73zbMvLNOBGssQQOAn+x25jjsAHKun98 IPM8F1/x67LDRg2Kjv16L6UMpsWFU0vddjf/POGQuMAdvafLkNbXQg6isSpEQFOyus46 JWiASQm+3ZX+PF80FqpA3X49aCWtGV2vhULOOb3CAhPkEVuAWhRFRQs6KQ78vitwr5Kn 3kJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nlhB7Ixl; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o24-20020a509b18000000b00445a5ff6348si1555169edi.613.2022.08.23.04.28.59; Tue, 23 Aug 2022 04:29:24 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=nlhB7Ixl; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354820AbiHWK02 (ORCPT + 99 others); Tue, 23 Aug 2022 06:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353669AbiHWKLt (ORCPT ); Tue, 23 Aug 2022 06:11:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFD4E1CFE5; Tue, 23 Aug 2022 01:58:09 -0700 (PDT) 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 6F01DB81C39; Tue, 23 Aug 2022 08:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEA54C433C1; Tue, 23 Aug 2022 08:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245087; bh=3lexMGJKqNSSshBNGmPY6l9XMI4LRtysWKOU/2UhE5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nlhB7IxljUEwTzDziegjB5VLIb+nQTMQRF8Mr7g+RWmPsdy5jj4C22EaV3GKQrmLl G8EnRc7a+FUaxsMlKyXZncAaK7fUGQkuLS7/t+UO2FR9dBr43xbnXMq7JzgSA1pl65 4IURSBR9uAn/MhoJjV3IqduXqsXHyIYucEAugfNw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Schspa Shi , Cornelia Huck , Alex Williamson , Sasha Levin Subject: [PATCH 5.15 209/244] vfio: Clear the caps->buf to NULL after free Date: Tue, 23 Aug 2022 10:26:08 +0200 Message-Id: <20220823080106.483014565@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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,T_SCC_BODY_TEXT_LINE 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: Schspa Shi [ Upstream commit 6641085e8d7b3f061911517f79a2a15a0a21b97b ] On buffer resize failure, vfio_info_cap_add() will free the buffer, report zero for the size, and return -ENOMEM. As additional hardening, also clear the buffer pointer to prevent any chance of a double free. Signed-off-by: Schspa Shi Reviewed-by: Cornelia Huck Link: https://lore.kernel.org/r/20220629022948.55608-1-schspa@gmail.com Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/vfio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 3c034fe14ccb..818e47fc0896 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1850,6 +1850,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps, buf = krealloc(caps->buf, caps->size + size, GFP_KERNEL); if (!buf) { kfree(caps->buf); + caps->buf = NULL; caps->size = 0; return ERR_PTR(-ENOMEM); } -- 2.35.1