Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3324865rwa; Tue, 23 Aug 2022 02:52:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4X6pIbiKcXxQ6ti2qFVnp5DMyKI81lvLrE9A08NhtreUsWNIqviYHWAg4gvqbthmc2yzvO X-Received: by 2002:a65:6b95:0:b0:420:2cb1:68e5 with SMTP id d21-20020a656b95000000b004202cb168e5mr19995354pgw.220.1661248354260; Tue, 23 Aug 2022 02:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248354; cv=none; d=google.com; s=arc-20160816; b=LJaNQUiH/CLji9y3kusgAuSsN9aNcPvh0s5jeE5k4OkIPSjaO94L+G91HqNTA6Zn/B +MvuoxPwk7bRLV5F4Japx+g7BeIuuLoiIEZyfF+VIQODfnJUtJUNa/kslJ/DyiTvczbK AzWF9hpCHWUYEnq6SWMNCGYJlGxLsXkM8gboF8MPSPm3W3O0vJdQ7dhUu9yUbaGv1S1v Dakgeg+paT8tEVsfAhzWHh8ZSZ+6O8kxA/edX9C3EIIKGn6Lmw4Ew7Xugut6fMBorlQ9 tuedY+/XIgoShq0/NBSDy1X6458MYwRq2n4uU+n7Da5DAvMmBlMzsX0LTh9nYHG9Ueoi 42RA== 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=AtTpojSUxXtCKgxvnm3P2NDIscZl2Bql7mT1NSN6cbw=; b=RorldXnIDa9EbK4oKZ/uwIB+tWgGQhtklV6kzD6//ofjFv5lMbSaxAmVb8VSwLpAf0 8m1RMKqSUALq9GqsYYRZxx/3HNwUr69ruQWehU7a8wKJhicwF2Ue9JovDxOrdNyZv0th nvl5LcnC+ousKT0aUFCfjIuEvgVZ1w6SVBnVw10BV6bPSCy0a68cdHpdFavdr96HTZpS +3WY0eFawBRLKC5rMr9F4cizWUTfaMwOWUTP6Al5MxrB12wJ/mFYUNct/hD7ZrajDAuR KpIPiK05t79ZBY8Jixy0Ge91pegm2UbF9QO0X2HrW0wNaSUukSU0/NS+JTiRcTRYDHSc FEgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XEfW3uGW; 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 19-20020aa79253000000b00535b3ed44c0si13943739pfp.97.2022.08.23.02.52.23; Tue, 23 Aug 2022 02:52:34 -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=XEfW3uGW; 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 S1344375AbiHWIf1 (ORCPT + 99 others); Tue, 23 Aug 2022 04:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347254AbiHWIcS (ORCPT ); Tue, 23 Aug 2022 04:32:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEAE4FEF; Tue, 23 Aug 2022 01:16:26 -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 CCBF4B81C36; Tue, 23 Aug 2022 08:16:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E957C433C1; Tue, 23 Aug 2022 08:16:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242584; bh=j3Uq1S6p1wxJpc6tFreDzh8tlF7KqJESrAe7E/cF9bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XEfW3uGWgZC8JSvw8Hs5+lLI8uPWiORQw7fyFZ/YKLrdlBt8Y47cY+U8G2w8DUU9t w8YAjr96vBF4x7CS927PKegBVc48Pzj7aVnVu7P3GIX0AI2/NBnITaHLPbeJA3lzEn Ic2/k+Mn9ZPo7FqGE3cIPuEGLyJ3b+vv2PsqZJck= 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.9 095/101] vfio: Clear the caps->buf to NULL after free Date: Tue, 23 Aug 2022 10:04:08 +0200 Message-Id: <20220823080038.199805303@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080034.579196046@linuxfoundation.org> References: <20220823080034.579196046@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 881fc3a55edc..5798965f42b5 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1793,6 +1793,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