From nobody Thu Apr 2 20:26:39 2026 Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) (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 9975E31F988 for ; Thu, 26 Mar 2026 21:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.10.14.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774561809; cv=none; b=NtTUMM/FABm56w2pZVtjRK9VIKhdjnw5Ap8PKpLxhn+n+cQyrkMyohjNX+D9Zn4wMXuVi3huR+U3Ka9/bz3YhTvBoVkENdjo7FZk/HfmWn9Y+QkYt3ErQ/hv8MNOjkQgMEIX2nZoSi49zPf8PSoOfK0FqcVHQRFkwjs7WcpfhFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774561809; c=relaxed/simple; bh=qBdb4sKfmFcI3Bd8QhXn6f/HK5yrx8opiqiAmEzG9wM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S/kJh+XLlFbh9ZoMRTGFqc5++a8Yyx8Wa20Rn1hKTLcH/03VXlazZM/HBSyAP5/h+MNHI1NUgRT8Oc6JWV3jdjG88luzS+VjbhurcCq+7mo422lLTAWYKA+sxwXrwhox0kjBBdTvNpdTDJQ0ookOHTi3JH6DEp75YRAh8d0jOl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de; spf=pass smtp.mailfrom=c--e.de; arc=none smtp.client-ip=217.10.14.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=c--e.de Received: by cae.in-ulm.de (Postfix, from userid 1000) id 0361614005A; Thu, 26 Mar 2026 22:50:04 +0100 (CET) From: "Christian A. Ehrhardt" To: David Howells , Andrew Morton , linux-kernel@vger.kernel.org Cc: "Christian A. Ehrhardt" , Kees Cook , Petr Mladek , David Gow Subject: [PATCH v3 3/5] lib: kunit_iov_iter: Fix memory leaks Date: Thu, 26 Mar 2026 22:49:03 +0100 Message-Id: <20260326214905.818170-4-lk@c--e.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260326214905.818170-1-lk@c--e.de> References: <20260326214905.818170-1-lk@c--e.de> 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" Use vfree() instead of vunmap() to free the buffer allocated by iov_kunit_create_buffer() because vunmap() does not honour VM_MAP_PUT_PAGES. In order for this to work the page array itself must not be managed by kunit. Remove the folio_put() when destroying a folioq. This is handled by vfree(), now. Pointed out by sashiko.dev on a previous iteration of this series. Tested by running the kunit test 10000 times in a loop. Cc: David Howells Cc: Andrew Morton Fixes: 2d71340ff1d4 ("iov_iter: Kunit tests for copying to/from an iterator= ") Signed-off-by: Christian A. Ehrhardt --- lib/tests/kunit_iov_iter.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tests/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c index bb847e5010eb..d16449bdb833 100644 --- a/lib/tests/kunit_iov_iter.c +++ b/lib/tests/kunit_iov_iter.c @@ -42,7 +42,7 @@ static inline u8 pattern(unsigned long x) =20 static void iov_kunit_unmap(void *data) { - vunmap(data); + vfree(data); } =20 static void *__init iov_kunit_create_buffer(struct kunit *test, @@ -53,17 +53,22 @@ static void *__init iov_kunit_create_buffer(struct kuni= t *test, unsigned long got; void *buffer; =20 - pages =3D kunit_kcalloc(test, npages, sizeof(struct page *), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); + pages =3D kzalloc_objs(struct page *, npages, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); *ppages =3D pages; =20 got =3D alloc_pages_bulk(GFP_KERNEL, npages, pages); if (got !=3D npages) { release_pages(pages, got); + kvfree(pages); KUNIT_ASSERT_EQ(test, got, npages); } =20 buffer =3D vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL); + if (buffer =3D=3D NULL) { + release_pages(pages, got); + kvfree(pages); + } KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); =20 kunit_add_action_or_reset(test, iov_kunit_unmap, buffer); @@ -369,9 +374,6 @@ static void iov_kunit_destroy_folioq(void *data) =20 for (folioq =3D data; folioq; folioq =3D next) { next =3D folioq->next; - for (int i =3D 0; i < folioq_nr_slots(folioq); i++) - if (folioq_folio(folioq, i)) - folio_put(folioq_folio(folioq, i)); kfree(folioq); } } --=20 2.43.0