Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 0461538C42B; Sat, 12 Sep 2026 09:27:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205234; cv=none; b=UOoPK7eZnAOgqUCNotbkgJA+LVXMnn/SBmL3F8ZQPiwm7yZpsgR4iNrzLo24IYpkQJeKGNnh4ZMBki6xL8SO1PWW/o1BixDh4jOMtodzdiA3OkcdTxvxfa6gtnzQ/raXuYhWRS+bh2UB0JMP9Ga6OhcTPhagdoyjRfvx397Nsvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205234; c=relaxed/simple; bh=WGzydC16mwxjRrYDP8dJCZhtxeL7jgXtpWZYFBxIWvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P2InBGo4IMcuLXsAT6e4wrC+afivsBUlxtpq0L2vqcEco60MDLjn8QuUiIiCiIyM9pGBWsjVaEgIq+7tjFWasN7KU67gTQCYaTgQT8rjMDiGr8nLGWpySF2cQxWZToyiV2UvEnCM/IijltYVuX20sDGXmBMxKVE/DYCteedOfuA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hrgnHJT/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hrgnHJT/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD0041F000FF; Sat, 12 Sep 2026 09:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789205232; bh=gq/rx1zrNTqu3sFRUpubt0Rd4osrJvFIw5ftDCASV9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hrgnHJT/21hbAwwXlf1R4AyDOuP7yyileOiA8XPyczADireJ4TBiCU/l8y4PePq2Q I5bPBNTa3EmdMdB+rIhjg2lZBFd0i3y/zQFrYK0AGGRwAE1xPjzpPxW4vTKJ9KyWVy kEChBnm5EgyiLXPZAj0q+i/6H3VVh+3JNeavNL1g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Steven Rostedt , Haotian Zhang , Sasha Levin Subject: [PATCH 7.2 1775/1815] samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-multi-modify Date: Sat, 12 Sep 2026 08:58:45 +0200 Message-ID: <20260912065730.681042510@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Haotian Zhang [ Upstream commit 6727b7618f49401acf373fa3ec5712e2ec52e5cf ] ftrace_direct_multi_init() assigns kthread_run()'s return value to simple_tsk without an IS_ERR() check. When kthread_run() fails it returns ERR_PTR(-ENOMEM), but init still returns 0, so the module loads with simple_tsk holding an error pointer. On unload, ftrace_direct_multi_exit() then passes that ERR_PTR to kthread_stop(), leading to a null-pointer-dereference. Check the return value of kthread_run() with IS_ERR(); on failure, unregister the ftrace direct call and propagate the error code. Link: https://patch.msgid.link/20260826015050.10772-1-vulab@iscas.ac.cn Fixes: e1067a07cfbc ("ftrace/samples: Add module to test multi direct modify interface") Suggested-by: Steven Rostedt Signed-off-by: Haotian Zhang Signed-off-by: Steven Rostedt Signed-off-by: Sasha Levin --- samples/ftrace/ftrace-direct-multi-modify.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/samples/ftrace/ftrace-direct-multi-modify.c b/samples/ftrace/ftrace-direct-multi-modify.c index 7a7822dfeb50a..b03766c6217bc 100644 --- a/samples/ftrace/ftrace-direct-multi-modify.c +++ b/samples/ftrace/ftrace-direct-multi-modify.c @@ -364,9 +364,15 @@ static int __init ftrace_direct_multi_init(void) ret = register_ftrace_direct(&direct, my_tramp); - if (!ret) - simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn"); - return ret; + if (ret) + return ret; + simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn"); + if (IS_ERR(simple_tsk)) { + unregister_ftrace_direct(&direct, my_tramp, true); + return PTR_ERR(simple_tsk); + } + + return 0; } static void __exit ftrace_direct_multi_exit(void) -- 2.53.0