From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381140; b=WSlrbRIv1XwONBBSAmGcKAYUx1gH0shJ7FWJWW6yeg/zV9tXX6zAu9kxW3HRZ3+rl7d5 V/J2KmgMDoMu0vLYb3mJiDQwt9eWrkrJJvM29sm/5R3yfAKnT70QLii5OZ8QmqUDa+0OW JZIIxKA0mb2yRXXlVTwovoHEifu+NOfQiIzL16omH5OsnCmL3LopWBfZQRR5T06Uobmuv qpOHoeEg53NxwaqXXoP3DLFwEcjHqInxZfX8yb4UxsSOh21zuhRf54sNwGLkuvjckm7En lc5DDV///t3YQ4ABIFgUPYRzdpNWPlreM1cCCuEME0bbB2JHDSLFex4JQ3VwrjrOwFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381140; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=uXpWegPFv7NPe1d9HbapOr9sAm8Tz9ixjLdaVqnzzTA=; b=OEsjpO3GJo/TGERUc6MGgdyShBC0jRuxsid8WZ1nURfe+YL+MIOzfYOgFjoq4yp5Ub52 JXFT/NMqnEv3e3Bv/tDE6VNi7j3T6mG73dR5gmtBI3gdXaDc9l7EVkqJx7GOYvhY7/6Qg F66S9Xc7u1tfP9M89FUVPjtMVg+cFgm4/HMFFVw7tXkzM0R/HzVaZUC51PAXnoAP8JzXv vn6zT9RO5iXCEixHG13rqUic9vrp/yJT4WnmFqHXgvRp134vpYOPCaYCK1DLyx8N0ZhLW XwSHcTDvfsUNgCeW1WCrnV6attF37mTL5cOrqxD9RYB8UTragL4gFtk+DM0MrTbwilg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CZ6uXil+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF063606A32D; Fri, 4 Dec 2026 10:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CZ6uXil+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 523E51F000CE; Fri, 4 Dec 2026 10:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381140; bh=uXpWegPFv7NPe1d9HbapOr9sAm8Tz9ixjLdaVqnzzTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CZ6uXil+HI1xfoJqfJ2SIXxRWynKJ8bfsN0Jc0S1jIKWhWAxx6UHLhuyEf313DMmQ 7ANGlifDkN5Wofp++C5EPmdjEEn79JK4AEKbgHIEoup5qaAJXdccsBNUWaZTjI5T5b X59QKFhLjz4wuLYBeJ4qu0Zte5MKPYzPgTkJy6Fo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wang Xiaolei , SJ Park , Andrew Morton , Michal Hocko , Mike Rapoport , Suren Baghdasaryan , Vlastimil Babka , "Liam R. Howlett" , Brendan Higgins , David Gow , Aveline Noir Subject: [PATCH 7.3 536/742] mm/damon/tests/sysfs-kunit: fix leaked pid reference in add_targets test Date: Fri, 4 Dec 2026 19:06:40 +0900 Message-ID: <20261204100649.414501047@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wang Xiaolei commit 9d2cc214935ad78b8f54bf886f0b4e3f387fa44f upstream. damon_sysfs_test_add_targets() creates its monitoring context with damon_new_ctx(), which leaves ctx->ops zero-initialized. Since DAMON_OPS_VADDR is zero, damon_target_has_pid() returns true for the context, and damon_sysfs_add_targets() therefore calls damon_set_target_pid() for each target it adds. That function grabs a reference to the target's struct pid via find_get_pid(). The test then tears the context down with damon_destroy_ctx(), which releases such a reference from ctx->ops.cleanup_target(). For the vaddr operations set that callback is damon_va_cleanup_target(), and it is the only place where the reference is put. The test never selects an operations set, though, so cleanup_target is NULL and both references -- one for each of the two damon_sysfs_add_targets() calls -- are leaked on every run of the test. Running the test with CONFIG_DEBUG_KMEMLEAK enabled reports the leaked struct pid objects as unreferenced. Fix this by selecting the vaddr operations set for the context before adding the targets, mirroring what the sysfs interface does. damon_select_ops() fails if the vaddr operations set is not registered, in which case the test cannot exercise the pid handling and skips itself. Link: https://lore.kernel.org/20261102144627.88843-3-sj@kernel.org Fixes: b8ee5575f763 ("mm/damon/sysfs-test: add a unit test for damon_sysfs_set_targets()") Signed-off-by: Wang Xiaolei Signed-off-by: SJ Park Signed-off-by: Andrew Morton Reviewed-by: SJ Park Cc: Michal Hocko Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Vlastimil Babka Cc: "Liam R. Howlett" Cc: Brendan Higgins Cc: David Gow Cc: Aveline Noir Cc: # 6.7.x Signed-off-by: Greg Kroah-Hartman --- mm/damon/tests/sysfs-kunit.h | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/mm/damon/tests/sysfs-kunit.h +++ b/mm/damon/tests/sysfs-kunit.h @@ -79,6 +79,15 @@ static void damon_sysfs_test_add_targets kunit_skip(test, "ctx alloc fail"); } + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + kfree(sysfs_targets->targets_arr); + kfree(sysfs_targets); + kfree(sysfs_target->regions); + kfree(sysfs_target); + kunit_skip(test, "vaddr ops not registered"); + } + damon_sysfs_add_targets(ctx, sysfs_targets); KUNIT_EXPECT_EQ(test, 1u, nr_damon_targets(ctx));