From nobody Mon Jun 8 04:25:56 2026 Received: from va-1-115.ptr.blmpb.com (va-1-115.ptr.blmpb.com [209.127.230.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 012D03AE183 for ; Thu, 4 Jun 2026 08:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780561959; cv=none; b=iPETHTMIOr6/aKQFrg8KfKQAPUEdmxmd68SNbhofcAn/evkncGAf2Xc1QYXzCvzbVTvvdb93o11PSUmk8UTns7ZUc0yjl6uRsEoLc8W9IR85vBU29FwTYPZ5pN85rhpvl4Y+w5aNtd8WU+Fcg1C7nwgH/7k9dFDG/Dvq21Qw8cA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780561959; c=relaxed/simple; bh=O/XLm6yquJb792lZu6TBmtaiO7oVMd52d25xxc25xMA=; h=Mime-Version:Cc:References:Subject:Message-Id:Content-Type:To: From:Date:In-Reply-To; b=PIecjTVTNLt7MErfY52kzKpaWVKYo8EgZQLciX2sjSMsGZOplcfz0btfIUpn9nfjDQGvMmXf2UkPe0kjBfoQI//iK/Cq89XL1yp99mw5fNR1FDu6HTs34w0CxUrdSaeXr3gYfDoS1C6gb+0dkmKw4Uwdt4e1CUkX7APSuiYXuvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=RPyvSUrr; arc=none smtp.client-ip=209.127.230.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="RPyvSUrr" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780561947; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=MGjzTvz9nTBXvTHdzC8Aih+cYvdT1nut4fI4CSXMV5Q=; b=RPyvSUrr0pNbb0A809BSU3kWis6IN4cihJpkgLHqkeOrM92Pr3QGbGIgbPNesc+QyUqV1A q4vwRBP9ZVLf7xmA+F15bSX8LCMCt0HH55ECmq/blRVewWjk5hYTk2DcO9uu8oE+A2eLMQ iKfrSQRpwZc7QbKWn5pbCg/kLxfhjcNQMvIsSoPS525j2+5dLITmcGmeblYM+C4fikLBZw G00cBsyO5EVb5B9RN5LYCt7p5UbGKMD8tiG7myAIh4Jkf1MVkGuaGgidq0pxOYYVYLaLJ/ B+FRAq+EuBQtXbgyfAB32KUAkwJEFbrKlkyNVYqUo/yDg4aZDbS1Y06hDKUMQQ== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Cc: , , , , , , , , "Rui Qi" X-Lms-Return-Path: X-Mailer: git-send-email 2.20.1 References: <20260602124509.365996-1-qirui.001@bytedance.com> Subject: [PATCH v2] selftests/livepatch: fix resource leak in test_klp_syscall init error path Message-Id: <20260604083208.1071428-1-qirui.001@bytedance.com> Content-Transfer-Encoding: quoted-printable To: From: "Rui Qi" Date: Thu, 4 Jun 2026 16:32:08 +0800 X-Original-From: Rui Qi In-Reply-To: <20260602124509.365996-1-qirui.001@bytedance.com> Content-Type: text/plain; charset="utf-8" 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 Acked-by: Miroslav Benes Reviewed-by: Petr Mladek --- Changes in v2: - Remove sysfs_remove_file() from the error path as suggested by Miroslav Benes. kobject_put() alone is sufficient because it eventually calls kobject_cleanup() -> __kobject_del() -> sysfs_remove_dir(), which removes the entire directory including all files created under it. .../selftests/livepatch/test_modules/test_klp_syscall.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_syscal= l.c b/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c index 0630ffd9d9a1..08aacc0e14de 100644 --- a/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_syscall.c @@ -109,7 +109,11 @@ static int livepatch_init(void) */ npids =3D npids_pending; =20 - return klp_enable_patch(&patch); + ret =3D klp_enable_patch(&patch); + if (ret) + kobject_put(klp_kobj); + + return ret; } =20 static void livepatch_exit(void) --=20 2.20.1