On Mon, 9 Mar 2026 at 09:37, Linus Torvalds
<[email protected]> wrote:
>
> Now, there are real exports in this area that are actually strange and
> should be removed: for some historical reason we export 'free_task()'
> which makes no sense to me at all (but probably did at some point).
>
> Now *that* is a strange export that can mess up another task in major ways.
>
> [ Ok, I was intrigued and I went and dug into history: we used to do
> it in the oprofile driver many many moons ago. ]
It looks like it should not only no longer be exported, it should
actually be static to kernel/fork.c. As far as I can tell, that
historic oprofile use was the only reason ever this was exposed in any
way.
IOW, a patch like the attached is probably a good idea.
Somebody should probably remind me next merge window (I'm not going to
make 7.0 bigger, and I find examples of people using
kretprobe/free_task, which *should* still work just fine with a static
function, but for all I know if the compiler inlines things it will
cause issues).
Or just add this patch to one of the trees scheduled for next merge
window. I'm not currently carrying a linux-next branch (I actively
deleted it because it caused problems due to messing up other peoples
linux-next branches, so if I ever introduce one I will have to come up
with a better name anyway)
Linus
include/linux/sched/task.h | 2 --
kernel/fork.c | 3 +--
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index 41ed884cffc9..0edb36107ac5 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -106,8 +106,6 @@ extern pid_t user_mode_thread(int (*fn)(void *), void *arg, unsigned long flags)
extern long kernel_wait4(pid_t, int __user *, int, struct rusage *);
int kernel_wait(pid_t pid, int *stat);
-extern void free_task(struct task_struct *tsk);
-
/* sched_exec is called by processes performing an exec */
extern void sched_exec(void);
diff --git a/kernel/fork.c b/kernel/fork.c
index 65113a304518..385d80432a89 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -526,7 +526,7 @@ void put_task_stack(struct task_struct *tsk)
}
#endif
-void free_task(struct task_struct *tsk)
+static void free_task(struct task_struct *tsk)
{
#ifdef CONFIG_SECCOMP
WARN_ON_ONCE(tsk->seccomp.filter);
@@ -555,7 +555,6 @@ void free_task(struct task_struct *tsk)
bpf_task_storage_free(tsk);
free_task_struct(tsk);
}
-EXPORT_SYMBOL(free_task);
void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm)
{