The kernel uses open code to check if a process is in root PID namespace
or not in several places.
Suggested by Suzuki, this patch set is to create a helper function
task_is_in_root_ns() so we can use it replace open code.
To test this patch set, I built Arm64 kernel with enabling all relevant
modules, and verified the kernel with CoreSight module on Arm64 Juno
board.
Leo Yan (7):
pid: Introduce helper task_is_in_root_ns()
coresight: etm3x: Use task_is_in_root_ns() to check PID namespace
coresight: etm4x: Use task_is_in_root_ns() to check PID namespace
connector/cn_proc: Use task_is_in_root_ns() to check PID namespace
coda: Use task_is_in_root_ns()
audit: Use task_is_in_root_ns()
taskstats: Use task_is_in_root_ns()
drivers/connector/cn_proc.c | 2 +-
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 8 ++++----
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 8 ++++----
fs/coda/inode.c | 2 +-
fs/coda/psdev.c | 2 +-
include/linux/pid_namespace.h | 5 +++++
kernel/audit.c | 2 +-
kernel/taskstats.c | 2 +-
8 files changed, 18 insertions(+), 13 deletions(-)
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Currently the kernel uses open code in multiple places to check if a
task is in the root PID namespace with the kind of format:
if (task_active_pid_ns(current) == &init_pid_ns)
do_something();
This patch creates a new helper function, task_is_in_root_ns(), it
returns true if a passed task is in the root PID namespace, otherwise
returns false. So it will be used to replace open codes.
Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Leo Yan <redacted>
---
include/linux/pid_namespace.h | 5 +++++
1 file changed, 5 insertions(+)
This patch uses helper task_is_in_root_ns() to replace open code for
checking if a task is in root PID namespace.
Signed-off-by: Leo Yan <redacted>
---
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
To avoid open code, this patch uses the helper task_is_in_root_ns() to
check if a task is in root PID namespace.
Signed-off-by: Leo Yan <redacted>
---
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
To avoid open code, this patch uses the helper task_is_in_root_ns() to
check if task is in root PID namespace.
Signed-off-by: Leo Yan <redacted>
---
drivers/connector/cn_proc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -358,7 +358,7 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,*othernamespaces.*/if((current_user_ns()!=&init_user_ns)||-(task_active_pid_ns(current)!=&init_pid_ns))+!task_is_in_root_ns(current))return;/* Can only change if privileged. */
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
@@ -1034,7 +1034,7 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)caseAUDIT_MAKE_EQUIV:/* Only support auditd and auditctl in initial pid namespace*fornow.*/-if(task_active_pid_ns(current)!=&init_pid_ns)+if(!task_is_in_root_ns(current))return-EPERM;if(!netlink_capable(skb,CAP_AUDIT_CONTROL))
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Leon Romanovsky <leon@kernel.org> Date: 2021-12-06 06:49:17
On Sun, Dec 05, 2021 at 10:50:59PM +0800, Leo Yan wrote:
quoted hunk
Currently the kernel uses open code in multiple places to check if a
task is in the root PID namespace with the kind of format:
if (task_active_pid_ns(current) == &init_pid_ns)
do_something();
This patch creates a new helper function, task_is_in_root_ns(), it
returns true if a passed task is in the root PID namespace, otherwise
returns false. So it will be used to replace open codes.
Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Leo Yan <redacted>
---
include/linux/pid_namespace.h | 5 +++++
1 file changed, 5 insertions(+)
It is bad that this name doesn't reflect PID nature of this namespace.
Won't it better to name it task_is_in_init_pid_ns()?
Yes, task_is_in_init_pid_ns() is more clear.
Will respin for this. Thank you for suggestion!
Leo
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel