lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <26F4E8D1-4DDF-48EC-AE21-478EDF4C65C3@alien8.de>
Date: Sat, 26 Apr 2025 14:08:46 +0300
From: Borislav Petkov <bp@...en8.de>
To: Steven Rostedt <rostedt@...dmis.org>, linux-kernel@...r.kernel.org,
 linux-trace-kernel@...r.kernel.org
CC: Masami Hiramatsu <mhiramat@...nel.org>, Mark Rutland <mark.rutland@....com>,
 Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
 Andrew Morton <akpm@...ux-foundation.org>,
 Peter Zijlstra <peterz@...radead.org>,
 Linus Torvalds <torvalds@...ux-foundation.org>,
 Ingo Molnar <mingo@...hat.com>, x86@...nel.org, Kees Cook <kees@...nel.org>,
 bpf@...r.kernel.org, Tejun Heo <tj@...nel.org>,
 Julia Lawall <Julia.Lawall@...ia.fr>, Nicolas Palix <nicolas.palix@...g.fr>,
 cocci@...ia.fr
Subject: Re: [RFC][PATCH 1/2] kthread: Add is_user_thread() and is_kernel_thread() helper functions

On April 25, 2025 11:41:21 PM GMT+03:00, Steven Rostedt <rostedt@...dmis.org> wrote:
>From: Steven Rostedt <rostedt@...dmis.org>
>
>In order to know if a task is a user thread or a kernel thread it is
>recommended to test the task flags for PF_KTHREAD. The old way was to
>check if the task mm pointer is NULL.
>
>It is an easy mistake to not test the flag correctly, as:
>
>	if (!(task->flag & PF_KTHREAD))
>
>Is not immediately obvious that it's testing for a user thread.
>
>Add helper functions:
>
>  is_user_thread()
>  is_kernel_thread()
>
>that can make seeing what is being tested for much more obvious:
>
>	if (is_user_thread(task))
>
>Link: https://lore.kernel.org/all/20250425133416.63d3e3b8@gandalf.local.home/
>
>Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>
>---
> include/linux/sched.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
>diff --git a/include/linux/sched.h b/include/linux/sched.h
>index f96ac1982893..823f38b0fd3e 100644
>--- a/include/linux/sched.h
>+++ b/include/linux/sched.h
>@@ -1785,6 +1785,16 @@ static __always_inline bool is_percpu_thread(void)
> #endif
> }
> 
>+static __always_inline bool is_user_thread(struct task_struct *task)
>+{
>+	return !(task->flags & PF_KTHREAD);
>+}
>+
>+static __always_inline bool is_kernel_thread(struct task_struct *task)
>+{
>+	return task->flags & PF_KTHREAD;

return !is_user_thread(task);

or the other way around. 

🙂

-- 
Sent from a small device: formatting sucks and brevity is inevitable. 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ