From nobody Fri Sep 5 20:15:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25D49C32792 for ; Tue, 23 Aug 2022 11:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358947AbiHWL7x (ORCPT ); Tue, 23 Aug 2022 07:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359394AbiHWL4t (ORCPT ); Tue, 23 Aug 2022 07:56: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 9F19DD7CD8; Tue, 23 Aug 2022 02:34:27 -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 21617B81B1F; Tue, 23 Aug 2022 09:34:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C884C433D7; Tue, 23 Aug 2022 09:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661247265; bh=noI0SHTyTyoNWmj0FmTe9S6Tq2D9OmFbIBtBdSw+lgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RT+KNO/bkLKqKiMctUquf7d7nM8PYdMhRE1oanZ/hxQnaoek3eov6+mxd0BkxmF6B kX1vbiBb4ZraxbB2LlxFD/zyPZPxmX21nI2LPYY7EGDJCl9McKKFpZJosRUfhrhIfG 7gcJ847ofsdtY8DY8d7cd8rDsAAWDzIzGyxwGUts= 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.4 371/389] vfio: Clear the caps->buf to NULL after free Date: Tue, 23 Aug 2022 10:27:29 +0200 Message-Id: <20220823080131.044874275@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 388597930b64..efd3782ead97 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1802,6 +1802,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct= vfio_info_cap *caps, buf =3D krealloc(caps->buf, caps->size + size, GFP_KERNEL); if (!buf) { kfree(caps->buf); + caps->buf =3D NULL; caps->size =3D 0; return ERR_PTR(-ENOMEM); } --=20 2.35.1