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_init_pid_ns() to replace open code.
This patch set has been applied on the mainline kernel and built for
Arm64 kernel with enabling all relevant modules.
Changes from v1:
* Renamed helper function from task_is_in_root_ns() to
task_is_in_init_pid_ns(). (Leon Romanovsky)
* Improved patches' commit logs for more neat.
Leo Yan (7):
pid: Introduce helper task_is_in_init_pid_ns()
coresight: etm3x: Use task_is_in_init_pid_ns()
coresight: etm4x: Use task_is_in_init_pid_ns()
connector/cn_proc: Use task_is_in_init_pid_ns()
coda: Use task_is_in_init_pid_ns()
audit: Use task_is_in_init_pid_ns()
taskstats: Use task_is_in_init_pid_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
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_init_pid_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 replaces open code with task_is_in_init_pid_ns() to check 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(-)
This patch replaces open code with task_is_in_init_pid_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(-)
This patch replaces open code with task_is_in_init_pid_ns() to check if
a 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_init_pid_ns(current))return;/* Can only change if privileged. */
@@ -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_init_pid_ns(current))return-EPERM;if(!netlink_capable(skb,CAP_AUDIT_CONTROL))
From: Leon Romanovsky <leon@kernel.org> Date: 2021-12-08 09:28:44
On Wed, Dec 08, 2021 at 04:33:14PM +0800, Leo Yan wrote:
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_init_pid_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(+)
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
From: Suzuki K Poulose <suzuki.poulose@arm.com> Date: 2021-12-08 10:25:13
On 08/12/2021 08:33, 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_init_pid_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(+)
On Wed, Dec 08, 2021 at 04:33:16PM +0800, Leo Yan wrote:
quoted hunk
This patch replaces open code with task_is_in_init_pid_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(-)
On Wed, Dec 08, 2021 at 04:33:15PM +0800, Leo Yan wrote:
quoted hunk
This patch replaces open code with task_is_in_init_pid_ns() to check 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(-)
On Wed, Dec 08, 2021 at 04:33:14PM +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_init_pid_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(+)
@@ -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_init_pid_ns(current))return-EPERM;if(!netlink_capable(skb,CAP_AUDIT_CONTROL))
On Wed, Dec 08, 2021 at 04:33:17PM +0800, Leo Yan wrote:
quoted hunk
This patch replaces open code with task_is_in_init_pid_ns() to check if
a 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(-)
On Tue, Dec 14, 2021 at 04:58:32PM +1100, Balbir Singh wrote:
On Wed, Dec 08, 2021 at 04:33:17PM +0800, Leo Yan wrote:
quoted
This patch replaces open code with task_is_in_init_pid_ns() to check if
a 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(-)
Sounds like there might scope for other wrappers - is_current_in_user_init_ns()
Indeed, for new wrapper is_current_in_user_init_ns(), I searched kernel
and located there have multiple places use open code. If no one works
on this refactoring, I will send a new patchset for it separately.
Acked-by: Balbir Singh <bsingharora@gmail.com>
Thank you for review, Balbir! Also thanks review from Leon and
Suzuki.
Leo
@@ -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_init_pid_ns(current))return-EPERM;if(!netlink_capable(skb,CAP_AUDIT_CONTROL))--
@@ -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_init_pid_ns(current))return-EPERM;if(!netlink_capable(skb,CAP_AUDIT_CONTROL))--
2.25.1
paul moore
- RGB
--
Richard Guy Briggs [off-list ref]
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Hi David,
On Wed, Dec 08, 2021 at 04:33:13PM +0800, Leo Yan wrote:
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_init_pid_ns() to replace open code.
This patch set has been applied on the mainline kernel and built for
Arm64 kernel with enabling all relevant modules.
I'd like sync for how to merging this patch set. Except patch 05/07,
all of other patches in this patch set have been received the reviewed
or acked tags. So could you pick up this patch set?
Furthermore, we have another patch set "coresight: etm: Correct PID
tracing for non-root namespace" [1], which is dependent on the current
patch set and it has been Acked by Suzuki.
I'd like to get opinions from David and CoreSight maintainers Mathieu
and Suzuki, should we merge the patch set [1] via David's tree as well
to avoid dependency issue, or prefer to merge it via CoreSight tree?
If David prefers the prior option, I can resend the patch set [1] with
looping David.
Thanks,
Leo
[1] https://lore.kernel.org/lkml/20211213121323.1887180-1-leo.yan@linaro.org/
On Wed, Jan 12, 2022 at 02:40:47PM +0800, Leo Yan wrote:
Hi David,
On Wed, Dec 08, 2021 at 04:33:13PM +0800, Leo Yan wrote:
quoted
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_init_pid_ns() to replace open code.
This patch set has been applied on the mainline kernel and built for
Arm64 kernel with enabling all relevant modules.
I'd like sync for how to merging this patch set. Except patch 05/07,
all of other patches in this patch set have been received the reviewed
or acked tags. So could you pick up this patch set?
Furthermore, we have another patch set "coresight: etm: Correct PID
tracing for non-root namespace" [1], which is dependent on the current
patch set and it has been Acked by Suzuki.
I'd like to get opinions from David and CoreSight maintainers Mathieu
and Suzuki, should we merge the patch set [1] via David's tree as well
to avoid dependency issue, or prefer to merge it via CoreSight tree?
If David prefers the prior option, I can resend the patch set [1] with
looping David.
Gentle ping, Dave.
I verified the current patch set and CoreSight patch set, both can apply
clearly on the latest mainline kernel (with last commit
dd81e1c7d5fb "Merge tag 'powerpc-5.17-2' of
git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux").
Thanks,
Leo