Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3463343rwa; Tue, 23 Aug 2022 05:18:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5dZH4bJD6suNDAWCM9WPrz0DmuBkVIBpVmS01ghnvL/EQimZuhA865Mko5rrs5IfarFoCN X-Received: by 2002:a17:907:a408:b0:73d:6696:50af with SMTP id sg8-20020a170907a40800b0073d669650afmr9846075ejc.369.1661257098501; Tue, 23 Aug 2022 05:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257098; cv=none; d=google.com; s=arc-20160816; b=sI2WX9Zl58c+9bfjkkKXYIQ6smdtO/FIfqhz5g9WkTbtED1njqXVLeuEDdf+nRVROS uPpb0LL1rBStaAruF6RnwGuIW22vgGiCYgCygG/MkmLJQBxCqzKU2EoK9PK6GpUc7ij8 f0S09a3Dbw0hTwXsV0bYtG9L7xTkkgrtEaYWwrgWfE6EbIvzSY7wgApSM+wnrOfaoWEN llQycMs8MiJ2P17pxi544FupZzsZnpJ68b9+6XO3yCR7L+ZXGSk0ML80fJXBXTdnJ29R 1eIg4+I3tNaaBXpTG5c0DEOyHIqjXvu6ZdzyVTLRqZZr8SNvNEARf5rRtWQgjZKuUJo3 wOQA== 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=FvtZk+gu07ddBwXTpnf8IcpH/p+8kP2qSk15W5tuKzE=; b=lQ/jcov+PCIXolL/HjZg+raLSsOIKFhwJBc498qehiZVcpriVbyVkRpahdlk3/ULMJ iMHXf9ZNqT/fJnUHD3e0gIiNvoS4PRV+hAJLv8fE1IhpwkmCm3WyBeCxsGdab+xMwLIn SSRsytx/E4nv+mAKLJ3eaqE4TlCtezx83dw2ZPiMfdCkZpjlL6EMkuhTql13v7Nv4sWo 5C6kQSFRW7aVi8UMcEl49GRZ7pZC3iF9a75c3S7F1rC6N50+cQBFckEZCVMzYbF15y7i hj/KWZALbyy6Njw71IvvZZ3cggDmawQjbgxaJAX/tSQtHsldlnD4tH3YJadqfwAXn4pQ jgFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YTkenXUP; 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 hw8-20020a170907a0c800b0073c5e27e109si10659540ejc.307.2022.08.23.05.17.51; Tue, 23 Aug 2022 05:18:18 -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=YTkenXUP; 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 S1354680AbiHWK0G (ORCPT + 99 others); Tue, 23 Aug 2022 06:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353655AbiHWKLs (ORCPT ); Tue, 23 Aug 2022 06:11:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3EB42AC4; Tue, 23 Aug 2022 01:58:06 -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 5F296B81C3B; Tue, 23 Aug 2022 08:58:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E3B2C433C1; Tue, 23 Aug 2022 08:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245084; bh=/rrdra+UNE0LoJsFdhBak/JV5VbATvgQuE34YKLAAEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YTkenXUP2X3s4SUwxsggpIYLFeFrrzFLEa8Kb+KJY6J5qZGWpkyfRZynKt2JA6NMK zGsJpjZqUylQ4z5WDPgCEzXAuV/1o/DBPMbqKV4zxVdEylye22q8Pp/S8LnSAbN5LP NYt8b98gQJ38g3P/DvnC5CVyrwyXNb0jRweN3B7Y= 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 4.14 222/229] vfio: Clear the caps->buf to NULL after free Date: Tue, 23 Aug 2022 10:26:23 +0200 Message-Id: <20220823080101.560890277@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 0d73d913c18b..747eb5c70238 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1813,6 +1813,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