Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3416267rwa; Tue, 23 Aug 2022 04:32:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR5u2z7reIPbGMr1dpnfj33c8VGhhYpKwbsob7hAO2xCVlkxZg9EcHWCNwObkLYg5Pv9OwfQ X-Received: by 2002:a05:6402:4311:b0:447:9fb:b710 with SMTP id m17-20020a056402431100b0044709fbb710mr3179967edc.272.1661254245984; Tue, 23 Aug 2022 04:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254245; cv=none; d=google.com; s=arc-20160816; b=JfAE3sqg5x8CfV3RYDSPq5OY+KnDQgmgAs1TyJHaDgHwKuzj0Alx93r5ittTaC3Zh+ Yayxh5oCA148+8WLu4/+ObtYSHIal07KvvmB5DCCtxRgm805YqhSfqqLbowJwCmD2Egx psQGYrigSjRZ7rPxQG9sYdT60+WHPmUkDZELU0KwTTBD6z7yzaltdilxoh2BPfF3h7vt YDfqgto6X6q7qCd9HIBwFicMJnrPra1ljnV7dBWDF8BnMsHrFrvSut/Tq0HPIIeTZsf7 OhfRDN29wc+2PrV4Du4yt6rRoVmq2BxFgqSNiolgOL8SCf9fdYGIrJjjDj+gf8hoAAKs 0rIg== 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=pNtclsQhTBMlVqzfyvejMIqw9TdvzSPprdiNW+jZe6E=; b=XUND1NIHG/x6HGbdaagwJQqGvt7D+8QbLdroYk55AJBkUZYAeK8aNnwjiqveBGr/uc RHou9b+eaD0XKWwY5Qut6T/si4sEUBmgeSiRfZ0Z/fAaD1UhoGvf2Gbl7Tg1KS5GVMdN pqAZJaONlyIGLjg3e3PRVtXVTfOEJ51ye8gr0HTJb6EtycBNmLSKlbPTGRZQaOQdmq16 35pluQTKqwUh6l1mHxFubXOhfQuFoUK0ggm/TIzSHeeXyXAe40wbd4sgH1mwi++FiD3+ RjQXp/6KedIGnlF1kxvWcHVYOadjW0X7XaSYMh4EzpyC5cjzAQod3VQtoX2NK47QG5to nj5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rkZ68ZnT; 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 eb11-20020a0564020d0b00b0043ddebb56a0si2314916edb.61.2022.08.23.04.30.20; Tue, 23 Aug 2022 04:30:45 -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=rkZ68ZnT; 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 S1357392AbiHWLGt (ORCPT + 99 others); Tue, 23 Aug 2022 07:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356905AbiHWLEK (ORCPT ); Tue, 23 Aug 2022 07:04:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2993B2D8C; Tue, 23 Aug 2022 02:15:13 -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 75719B81C89; Tue, 23 Aug 2022 09:14:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D66EAC433D7; Tue, 23 Aug 2022 09:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246069; bh=MCE+uIiIuB/Uh9Iht3jUtdPKJvJ8Z8u25fHMsaDGZCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rkZ68ZnTeQs2+iWkLpdJsRG4yjxTpH/Neglz1ge2XKH8yc/0zw28MdzFZRd3u8Cyp +S/2e8fXOHKSxJnSI1LxJi4qvi5QtLYxhC30RkU0PXcNQh03CFkQ+6TbnW9fCHqEBX jaKnsUfijVfWspbzzIDjZ4NPokGYzBc9dGNaYCIg= 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.19 272/287] vfio: Clear the caps->buf to NULL after free Date: Tue, 23 Aug 2022 10:27:21 +0200 Message-Id: <20220823080110.542528037@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 7a386fb30bf1..0d146b45e0b4 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1808,6 +1808,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