]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/livepatch: fix resource leak in test_klp_syscall init error path
authorRui Qi <qirui.001@bytedance.com>
Thu, 4 Jun 2026 08:32:08 +0000 (16:32 +0800)
committerPetr Mladek <pmladek@suse.com>
Tue, 9 Jun 2026 10:38:33 +0000 (12:38 +0200)
In livepatch_init(), if klp_enable_patch() fails, the previously
created kobject and sysfs file are never cleaned up, causing a
resource leak. Capture the return value and add proper cleanup
on the error path.

Signed-off-by: Rui Qi <qirui.001@bytedance.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://patch.msgid.link/20260604083208.1071428-1-qirui.001@bytedance.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c

index 0630ffd9d9a1a7de02fd0852a1e8d527e45cf430..08aacc0e14de9009c364f08db42f15d843c0762e 100644 (file)
@@ -109,7 +109,11 @@ static int livepatch_init(void)
         */
        npids = npids_pending;
 
-       return klp_enable_patch(&patch);
+       ret = klp_enable_patch(&patch);
+       if (ret)
+               kobject_put(klp_kobj);
+
+       return ret;
 }
 
 static void livepatch_exit(void)