From nobody Thu Dec 25 01:34:31 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 492E3BE71; Tue, 23 Jan 2024 01:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705972422; cv=none; b=gIAVwbxDTtHEjCMDvRbHp4Quh7m+pads84CKd/IIEY/2flMBeKrKWJHl30u0kEE6eujJ2Sgd1cwcyGiYimhVXUzYZmAC0rFbZzwnw0NseckWBbcZJCut66FMluHx76svvqkfcg8Lx8xzKC1h7X+EEgxUIcq+mqeRjuMWLO1+3Zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705972422; c=relaxed/simple; bh=eswOY/7LacnPItq2MBgGY1hsNbWUj9aRuO7FiWkWpZs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=kZtWCilkPuXxosJTqPrGvCg+6Ozm7ytYS8lSOPCknsK0P66iD4VsQCIYdj0Xg2w1Jnn89QEvnjI/N0IojoFNGfvZEHf1quYVFy5rXlJx567lkfedFl39PVFf3uv72whZJ1tW0dxf8oxD7u+OGm0IoSiDM6EpSF7u5b7kdv+358U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 725ac9349c914a659c5fe5d0b26b1356-20240123 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:d72e2702-ade4-47e0-8027-c05a7342ce5f,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.35,REQID:d72e2702-ade4-47e0-8027-c05a7342ce5f,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5d391d7,CLOUDID:ee268a8e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:240123091336YQ1JJ9EN,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 725ac9349c914a659c5fe5d0b26b1356-20240123 X-User: liucong2@kylinos.cn Received: from localhost.localdomain [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1484640778; Tue, 23 Jan 2024 09:13:33 +0800 From: Cong Liu To: Brett Creeley , Jason Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson Cc: Cong Liu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] vfio/pds: Potential memory leak in pds_vfio_dirty_enable() Date: Tue, 23 Jan 2024 09:13:19 +0800 Message-Id: <20240123011319.6954-1-liucong2@kylinos.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" the patch releases the region_info memory if the interval_tree_iter_first() function fails. Signed-off-by: Cong Liu Reviewed-by: Reviewed-by: Kevin Tian --- drivers/vfio/pci/pds/dirty.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/pds/dirty.c b/drivers/vfio/pci/pds/dirty.c index 8ddf4346fcd5..67919b5db127 100644 --- a/drivers/vfio/pci/pds/dirty.c +++ b/drivers/vfio/pci/pds/dirty.c @@ -291,8 +291,11 @@ static int pds_vfio_dirty_enable(struct pds_vfio_pci_d= evice *pds_vfio, len =3D num_ranges * sizeof(*region_info); =20 node =3D interval_tree_iter_first(ranges, 0, ULONG_MAX); - if (!node) - return -EINVAL; + if (!node) { + err =3D -EINVAL; + goto out_free_region_info; + } + for (int i =3D 0; i < num_ranges; i++) { struct pds_lm_dirty_region_info *ri =3D ®ion_info[i]; u64 region_size =3D node->last - node->start + 1; --=20 2.34.1