mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] kunit: fix reference count leak in kfree_at_end
@ 2021-09-09  7:24 Xiyu Yang
  2021-09-09 16:59 ` Daniel Latypov
  2021-09-28 21:27 ` Brendan Higgins
  0 siblings, 2 replies; 5+ messages in thread
From: Xiyu Yang @ 2021-09-09  7:24 UTC (permalink / raw)
  To: Brendan Higgins, linux-kselftest, kunit-dev, linux-kernel
  Cc: yuanxzhang, Xiyu Yang, Xin Tan

The reference counting issue happens in the normal path of
kfree_at_end(). When kunit_alloc_and_get_resource() is invoked, the
function forgets to handle the returned resource object, whose refcount
increased inside, causing a refcount leak.

Fix this issue by calling kunit_alloc_resource() instead of
kunit_alloc_and_get_resource().

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 lib/kunit/executor_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
index cdbe54b16501..c2dcfb1f6e97 100644
--- a/lib/kunit/executor_test.c
+++ b/lib/kunit/executor_test.c
@@ -116,7 +116,7 @@ static void kfree_at_end(struct kunit *test, const void *to_free)
 	/* kfree() handles NULL already, but avoid allocating a no-op cleanup. */
 	if (IS_ERR_OR_NULL(to_free))
 		return;
-	kunit_alloc_and_get_resource(test, NULL, kfree_res_free, GFP_KERNEL,
+	kunit_alloc_resource(test, NULL, kfree_res_free, GFP_KERNEL,
 				     (void *)to_free);
 }
 
-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-01 19:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  7:24 [PATCH v2] kunit: fix reference count leak in kfree_at_end Xiyu Yang
2021-09-09 16:59 ` Daniel Latypov
2021-09-09 17:15   ` Daniel Latypov
2021-09-28 21:27 ` Brendan Higgins
2021-10-01 19:59   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®