Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3414511rwa; Tue, 23 Aug 2022 04:30:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5X+dC/z2HalC5SX2BzMYttO39zdQISZbwD7sFVhx8y4h5NSkS+LrPPVgJBvXKHgSipJatq X-Received: by 2002:a05:6402:1ac4:b0:447:1288:4137 with SMTP id ba4-20020a0564021ac400b0044712884137mr2850185edb.291.1661254147239; Tue, 23 Aug 2022 04:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254147; cv=none; d=google.com; s=arc-20160816; b=I8CzayJFW1dp/P8fP9Uw3S+B1F4PzDWKThXZaahGN6PgPNOpTso8o+MwHa5cezXPyw v+ESPYGeJUcBuQ4r4bS05gKxjvm/B1FWJ5hlE8FIdnzdEZJhrksFbZ8f8vPaOH7ICT+f HqKnY0fBA5BW8i87DfYEXf2qUcYANPz6CQ+bJeHUlQCd/DSmOu+40pGRnRR5NL2Napua Y9RrM1z+ud3xtHlwY7mSObqoO3BvEvFmLT3/Yhb+9AbYhz4PGS9CT+Tu0ITBgyjQ/bVI nqYQs4mVDfewCQdTRycPfWU3YaOXt5CdzbnEeRUrRTQWNHVMwsbDJb0cfyQYzeJct6K5 b7uA== 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=qxjJR3u60bfr/iSTP+8yUZ1Pk8Rsv6UemwK3Zk78AEg=; b=baDHLjb1uQGzKpotEeoMNAwd56gguB9VnOjRJKb508BpXPtjzryfu5hmVBHgGFHDcH jZhmOWvyIz/P2jhJlLUF0KunTyjT3hZx10R8ehEHRiPqY+3Z3rIaeWBEEN9WsEgI4U4Y Aga0Gpwz1JJUkkKBkZdrbABLXfkiTR5wvz9KwGp0ASkU4LrNoiZ/R/5F9OmXsb/DRKGG lJvBRRV0e+l5fjYhmf4XQeFBcc/J+w3OJSLj4S14d9e/etCzFIYgpFnOv3YQAs1mGzRf 4XB8toh1oDdUojMjQO7YubUIGomHsx24JfImoLNMj3PCVYRdmVczsiRPh8pslyI5CLcT 5Feg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LwFNWLry; 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 v5-20020a50d085000000b004468c7c8b2fsi1751627edd.230.2022.08.23.04.28.40; Tue, 23 Aug 2022 04:29:07 -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=LwFNWLry; 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 S1349512AbiHWJXE (ORCPT + 99 others); Tue, 23 Aug 2022 05:23:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350121AbiHWJV3 (ORCPT ); Tue, 23 Aug 2022 05:21:29 -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 181D78B9B4; Tue, 23 Aug 2022 01:34:23 -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 0E6A0B81C1B; Tue, 23 Aug 2022 08:33:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31760C43141; Tue, 23 Aug 2022 08:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243582; bh=PF8SufQ7tmxL2pVFNfXHYqLarhxmKG0VFpQoYTmqd98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwFNWLryWGdMFSqfbk0o50/kCG+mIhL7QOUAEQUcHQda/mvJZfhIIoUjj3yk1NV9F zyh3v4ie3yWdjbxOBDSDdbrW07Bg7dUCSDK2N/xG5wxg1xuMvQg2M65wpqTx8VjU+x WLgGSB7H38s/sGLchSoa3K3FrFtCNHqCWTirz1JA= 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.19 322/365] vfio: Clear the caps->buf to NULL after free Date: Tue, 23 Aug 2022 10:03:43 +0200 Message-Id: <20220823080131.650582945@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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 18fc0916587e..277cd1152dd8 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1814,6 +1814,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