pidns: introduce syscall getvpid
Subsystems (6)
RFC PATCH v2 1/1 pidns: introduce syscall getvpid
pid_t getvpid(pid_t pid, int source, int target);
This syscall converts pid from source pid-namespace into pid in target pid-namespace. Namespaces are defined by file descriptors pointing to namespace entries in proc (/proc/[pid]/ns/pid). If source / target is negative then current pid namespace is used.
If pid is negative then getvpid() returns pid of parent task for -pid.
If pid is unreachable from target namespace then syscall returns zero.
Errors:
ESRCH task not found EBADF closed file descriptor EINVAL not pid-namespace file descriptor
Examples:
getvpid(pid, ns, -1) -> pid in our pid namespace getvpid(pid, -1, ns) -> pid in container getvpid(1, ns1, ns2) > 0 -> ns1 inside ns2 getvpid(1, ns1, ns2) == 0 -> ns1 outside ns2 getvpid(1, ns, -1) -> init task of pid-namespace getvpid(-1, ns, -1) -> task in parent pid-namespace getvpid(-pid, -1, -1) -> get ppid by pid
---
v2:
* use namespace-fd as second/third argument
* add -pid for getting parent pid
* move code into kernel/sys.c next to getppid
* drop ifdef CONFIG_PID_NS
* add generic syscall
--- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 1 + include/uapi/asm-generic/unistd.h | 4 ++ kernel/sys.c | 63 ++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -382,3 +382,4 @@ 373 i386 shutdown sys_shutdown 374 i386 userfaultfd sys_userfaultfd 375 i386 membarrier sys_membarrier +376 i386 getvpid sys_getvpid
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -331,6 +331,7 @@ 322 64 execveat stub_execveat 323 common userfaultfd sys_userfaultfd 324 common membarrier sys_membarrier +325 common getvpid sys_getvpid # # x32-specific system call numbers start at 512 to avoid cache impact
include/linux/syscalls.h +1 -0
@@ -222,6 +222,7 @@ asmlinkage long sys_nanosleep(struct timespec __user *rqtp, struct timespec __usasmlinkage long sys_alarm (unsigned int seconds);asmlinkage long sys_getpid (void );asmlinkage long sys_getppid (void ); +asmlinkage long sys_getvpid (pid_t pid,int source,int target);asmlinkage long sys_getuid (void );asmlinkage long sys_geteuid (void );asmlinkage long sys_getgid (void );
include/uapi/asm-generic/unistd.h +3 -1
@@ -711,9 +711,11 @@ __SYSCALL(__NR_bpf, sys_bpf) __SC_COMP(__NR_execveat, sys_execveat, compat_sys_execveat)#define __NR_membarrier 282 __SYSCALL(__NR_membarrier, sys_membarrier) +#define __NR_getvpid 283 +__SYSCALL(__NR_getvpid, sys_getvpid)#undef __NR_syscalls -#define __NR_syscalls 283 +#define __NR_syscalls 284/* * All syscalls below here should go away really,
kernel/sys.c +63 -0
75 lines not on this page · raw message
Quoted 25 lines · Konstantin Khlebnikov
(quoted diff) +24
-0+SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) +{ + struct file *source_file = NULL, *target_file = NULL; + struct pid_namespace *source_ns, *target_ns; + struct pid *struct_pid; + struct ns_common *ns; + pid_t result; + + if (source >= 0) { + source_file = proc_ns_fget(source); + result = PTR_ERR(source_file); + if (IS_ERR(source_file)) + goto out; + ns = get_proc_ns(file_inode(source_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID) + goto out; + source_ns = container_of(ns, struct pid_namespace, ns); + } else + source_ns = task_active_pid_ns(current); + + if (target >= 0) { + target_file = proc_ns_fget(target); + result = PTR_ERR(target_file);
Review
Quoted 10 lines
(quoted diff) +10
-0+ if (IS_ERR(target_file)) + goto out; + ns = get_proc_ns(file_inode(target_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID) + goto out; + target_ns = container_of(ns, struct pid_namespace, ns); + } else + target_ns = task_active_pid_ns(current); +
Hmm. Eric, Konstantin, how about (uncompiled/untested) patch below in a preparation? The code above doesn't look very readable.
In fact I think another helper
#define proc_ns_xxx(file, type) \ container_of(get_proc_ns(file_inode(file)), \ struct type, ns)
makes sense too.
Oleg.
---
fs/nsfs.c +6 -1
@@ -118,9 +118,10 @@ int ns_get_name(char *buf, size_t size, struct task_struct *task,return res; } -struct file *proc_ns_fget (int fd) +struct file *proc_ns_fget (int fd,int nstype) {struct file *file; +struct ns_common *ns; file =fget (fd);if (!file)
@@ -129,6 +130,10 @@ struct file *proc_ns_fget(int fd)if (file->f_op != &ns_file_operations) goto out_invalid; + ns =get_proc_ns (file_inode (file)); +if (nstype && (ns->ops->type != nstype)) + goto out_invalid; +return file; out_invalid:
include/linux/proc_ns.h +1 -1
@@ -65,7 +65,7 @@ static inline int ns_alloc_inum(struct ns_common *ns)#define ns_free_inum (ns) proc_free_inum((ns)->inum) -extern struct file *proc_ns_fget (int fd); +extern struct file *proc_ns_fget (int fd,int nstype);#define get_proc_ns (inode) ((struct ns_common *)(inode)->i_private)extern void *ns_get_path (struct path *path,struct task_struct *task,const struct proc_ns_operations *ns_ops);
kernel/nsproxy.c +2 -6
@@ -226,21 +226,17 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)struct ns_common *ns;int err; - file =proc_ns_fget (fd); + file =proc_ns_fget (fd, nstype);if (IS_ERR (file))return PTR_ERR (file); - err = -EINVAL ; - ns =get_proc_ns (file_inode (file)); -if (nstype && (ns->ops->type != nstype)) - goto out; - new_nsproxy =create_new_namespaces (0 , tsk,current_user_ns (), tsk->fs);if (IS_ERR (new_nsproxy)) { err =PTR_ERR (new_nsproxy); goto out; } + ns =get_proc_ns (file_inode (file)); err = ns->ops->install (new_nsproxy, ns);if (err) {free_nsproxy (new_nsproxy);
net/core/net_namespace.c +2 -5
@@ -424,15 +424,12 @@ struct net *get_net_ns_by_fd(int fd)struct ns_common *ns;struct net *net; - file =proc_ns_fget (fd); + file =proc_ns_fget (fd,CLONE_NEWNET );if (IS_ERR (file))return ERR_CAST (file); ns =get_proc_ns (file_inode (file)); -if (ns->ops == &netns_operations) - net = get_net(container_of(ns, struct net, ns)); -else - net =ERR_PTR (-EINVAL ); + net = get_net(container_of(ns, struct net, ns));fput (file);return net;
Quoted 31 lines · Oleg Nesterov
Quoted 30 lines · Konstantin Khlebnikov
(quoted diff) +29
-0+SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) +{ + struct file *source_file = NULL, *target_file = NULL; + struct pid_namespace *source_ns, *target_ns; + struct pid *struct_pid; + struct ns_common *ns; + pid_t result; + + if (source >= 0) { + source_file = proc_ns_fget(source); + result = PTR_ERR(source_file); + if (IS_ERR(source_file)) + goto out; + ns = get_proc_ns(file_inode(source_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID) + goto out; + source_ns = container_of(ns, struct pid_namespace, ns); + } else + source_ns = task_active_pid_ns(current); + + if (target >= 0) { + target_file = proc_ns_fget(target); + result = PTR_ERR(target_file); + if (IS_ERR(target_file)) + goto out; + ns = get_proc_ns(file_inode(target_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID)
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ goto out; + target_ns = container_of(ns, struct pid_namespace, ns); + } else + target_ns = task_active_pid_ns(current); +Hmm. Eric, Konstantin, how about (uncompiled/untested) patch below in a preparation? The code above doesn't look very readable.
I've tried to do something like that but that comes too far so send patch as is. Actually we can go deeper and replace struct file* with struct fd: this saves couple atomic ops for singlethreaded task.
Quoted 107 lines
In fact I think another helper
#define proc_ns_xxx(file, type) \ container_of(get_proc_ns(file_inode(file)), \ struct type, ns)makes sense too.
Oleg.
---fs/nsfs.c +6
-1@@ -118,9 +118,10 @@ int ns_get_name(char *buf, size_t size, struct task_struct *task,return res; } -struct file *proc_ns_fget (int fd) +struct file *proc_ns_fget (int fd,int nstype) {struct file *file; +struct ns_common *ns; file =fget (fd);if (!file)@@ -129,6 +130,10 @@ struct file *proc_ns_fget(int fd)if (file->f_op != &ns_file_operations) goto out_invalid; + ns =get_proc_ns (file_inode (file)); +if (nstype && (ns->ops->type != nstype)) + goto out_invalid; +return file; out_invalid:include/linux/proc_ns.h +1
-1@@ -65,7 +65,7 @@ static inline int ns_alloc_inum(struct ns_common *ns)#define ns_free_inum (ns) proc_free_inum((ns)->inum) -extern struct file *proc_ns_fget (int fd); +extern struct file *proc_ns_fget (int fd,int nstype);#define get_proc_ns (inode) ((struct ns_common *)(inode)->i_private)extern void *ns_get_path (struct path *path,struct task_struct *task,const struct proc_ns_operations *ns_ops);kernel/nsproxy.c +2
-6@@ -226,21 +226,17 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)struct ns_common *ns;int err; - file =proc_ns_fget (fd); + file =proc_ns_fget (fd, nstype);if (IS_ERR (file))return PTR_ERR (file); - err = -EINVAL ; - ns =get_proc_ns (file_inode (file)); -if (nstype && (ns->ops->type != nstype)) - goto out; - new_nsproxy =create_new_namespaces (0 , tsk,current_user_ns (), tsk->fs);if (IS_ERR (new_nsproxy)) { err =PTR_ERR (new_nsproxy); goto out; } + ns =get_proc_ns (file_inode (file)); err = ns->ops->install (new_nsproxy, ns);if (err) {free_nsproxy (new_nsproxy);net/core/net_namespace.c +2
-6@@ -424,15 +424,12 @@ struct net *get_net_ns_by_fd(int fd)struct ns_common *ns;struct net *net; - file =proc_ns_fget (fd); + file =proc_ns_fget (fd,CLONE_NEWNET );if (IS_ERR (file))return ERR_CAST (file); ns =get_proc_ns (file_inode (file)); -if (ns->ops == &netns_operations) - net = get_net(container_of(ns, struct net, ns)); -else - net =ERR_PTR (-EINVAL ); + net = get_net(container_of(ns, struct net, ns));fput (file);return net; --To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 42 lines · Konstantin Khlebnikov
Quoted 31 lines · Oleg Nesterov
Quoted 30 lines · Konstantin Khlebnikov
(quoted diff) +29
-0+SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) +{ + struct file *source_file = NULL, *target_file = NULL; + struct pid_namespace *source_ns, *target_ns; + struct pid *struct_pid; + struct ns_common *ns; + pid_t result; + + if (source >= 0) { + source_file = proc_ns_fget(source); + result = PTR_ERR(source_file); + if (IS_ERR(source_file)) + goto out; + ns = get_proc_ns(file_inode(source_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID) + goto out; + source_ns = container_of(ns, struct pid_namespace, ns); + } else + source_ns = task_active_pid_ns(current); + + if (target >= 0) { + target_file = proc_ns_fget(target); + result = PTR_ERR(target_file); + if (IS_ERR(target_file)) + goto out; + ns = get_proc_ns(file_inode(target_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID)Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ goto out; + target_ns = container_of(ns, struct pid_namespace, ns); + } else + target_ns = task_active_pid_ns(current); +Hmm. Eric, Konstantin, how about (uncompiled/untested) patch below in a preparation? The code above doesn't look very readable.
Quoted 1 line
I've tried to do something like that but that comes too far so send patch as is.
OK, I won't insist.
The code above asks for cleanup/factorization, but we can do this later.
Quoted 2 lines
Actually we can go deeper and replace struct file* with struct fd: this saves couple atomic ops for singlethreaded task.
it's not about performance...
But yes, we can do more and create get_pid_ns_by_fd() similar to get_net_ns_by_fd(). We do not need file at all, we need pid_ns.
Oleg.
A message that is not in the archive (sent off-list or not yet received): CALYGNiPCVFNLi=1iL1gOf411iU6tT+DbVx1JuGG+f73Rpvx3dw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 42 lines · Konstantin Khlebnikov
Quoted 31 lines · Oleg Nesterov
Quoted 30 lines · Konstantin Khlebnikov
(quoted diff) +29
-0+SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) +{ + struct file *source_file = NULL, *target_file = NULL; + struct pid_namespace *source_ns, *target_ns; + struct pid *struct_pid; + struct ns_common *ns; + pid_t result; + + if (source >= 0) { + source_file = proc_ns_fget(source); + result = PTR_ERR(source_file); + if (IS_ERR(source_file)) + goto out; + ns = get_proc_ns(file_inode(source_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID) + goto out; + source_ns = container_of(ns, struct pid_namespace, ns); + } else + source_ns = task_active_pid_ns(current); + + if (target >= 0) { + target_file = proc_ns_fget(target); + result = PTR_ERR(target_file); + if (IS_ERR(target_file)) + goto out; + ns = get_proc_ns(file_inode(target_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID)Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ goto out; + target_ns = container_of(ns, struct pid_namespace, ns); + } else + target_ns = task_active_pid_ns(current); +Hmm. Eric, Konstantin, how about (uncompiled/untested) patch below in a preparation? The code above doesn't look very readable.
Quoted 1 line
I've tried to do something like that but that comes too far so send patch as is.
OK, I won't insist.
The code above asks for cleanup/factorization, but we can do this later.
Quoted 2 lines
Actually we can go deeper and replace struct file* with struct fd: this saves couple atomic ops for singlethreaded task.
it's not about performance...
But yes, we can do more and create get_pid_ns_by_fd() similar to get_net_ns_by_fd(). We do not need file at all, we need pid_ns.
Oleg.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 31 lines · Oleg Nesterov
Quoted 30 lines · Konstantin Khlebnikov
(quoted diff) +29
-0+SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) +{ + struct file *source_file = NULL, *target_file = NULL; + struct pid_namespace *source_ns, *target_ns; + struct pid *struct_pid; + struct ns_common *ns; + pid_t result; + + if (source >= 0) { + source_file = proc_ns_fget(source); + result = PTR_ERR(source_file); + if (IS_ERR(source_file)) + goto out; + ns = get_proc_ns(file_inode(source_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID) + goto out; + source_ns = container_of(ns, struct pid_namespace, ns); + } else + source_ns = task_active_pid_ns(current); + + if (target >= 0) { + target_file = proc_ns_fget(target); + result = PTR_ERR(target_file); + if (IS_ERR(target_file)) + goto out; + ns = get_proc_ns(file_inode(target_file)); + result = -EINVAL; + if (ns->ops->type != CLONE_NEWPID)
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ goto out; + target_ns = container_of(ns, struct pid_namespace, ns); + } else + target_ns = task_active_pid_ns(current); +Hmm. Eric, Konstantin, how about (uncompiled/untested) patch below in a preparation? The code above doesn't look very readable.
I've tried to do something like that but that comes too far so send patch as is. Actually we can go deeper and replace struct file* with struct fd: this saves couple atomic ops for singlethreaded task.
Quoted 107 lines
In fact I think another helper
#define proc_ns_xxx(file, type) \ container_of(get_proc_ns(file_inode(file)), \ struct type, ns)makes sense too.
Oleg.
---fs/nsfs.c +6
-1@@ -118,9 +118,10 @@ int ns_get_name(char *buf, size_t size, struct task_struct *task,return res; } -struct file *proc_ns_fget (int fd) +struct file *proc_ns_fget (int fd,int nstype) {struct file *file; +struct ns_common *ns; file =fget (fd);if (!file)@@ -129,6 +130,10 @@ struct file *proc_ns_fget(int fd)if (file->f_op != &ns_file_operations) goto out_invalid; + ns =get_proc_ns (file_inode (file)); +if (nstype && (ns->ops->type != nstype)) + goto out_invalid; +return file; out_invalid:include/linux/proc_ns.h +1
-1@@ -65,7 +65,7 @@ static inline int ns_alloc_inum(struct ns_common *ns)#define ns_free_inum (ns) proc_free_inum((ns)->inum) -extern struct file *proc_ns_fget (int fd); +extern struct file *proc_ns_fget (int fd,int nstype);#define get_proc_ns (inode) ((struct ns_common *)(inode)->i_private)extern void *ns_get_path (struct path *path,struct task_struct *task,const struct proc_ns_operations *ns_ops);kernel/nsproxy.c +2
-6@@ -226,21 +226,17 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)struct ns_common *ns;int err; - file =proc_ns_fget (fd); + file =proc_ns_fget (fd, nstype);if (IS_ERR (file))return PTR_ERR (file); - err = -EINVAL ; - ns =get_proc_ns (file_inode (file)); -if (nstype && (ns->ops->type != nstype)) - goto out; - new_nsproxy =create_new_namespaces (0 , tsk,current_user_ns (), tsk->fs);if (IS_ERR (new_nsproxy)) { err =PTR_ERR (new_nsproxy); goto out; } + ns =get_proc_ns (file_inode (file)); err = ns->ops->install (new_nsproxy, ns);if (err) {free_nsproxy (new_nsproxy);net/core/net_namespace.c +2
-6@@ -424,15 +424,12 @@ struct net *get_net_ns_by_fd(int fd)struct ns_common *ns;struct net *net; - file =proc_ns_fget (fd); + file =proc_ns_fget (fd,CLONE_NEWNET );if (IS_ERR (file))return ERR_CAST (file); ns =get_proc_ns (file_inode (file)); -if (ns->ops == &netns_operations) - net = get_net(container_of(ns, struct net, ns)); -else - net =ERR_PTR (-EINVAL ); + net = get_net(container_of(ns, struct net, ns));fput (file);return net; --To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 133 lines · Konstantin Khlebnikov
pid_tgetvpid(pid_t pid, int source, int target);This syscall converts pid from source pid-namespace into pid in target pid-namespace. Namespaces are defined by file descriptors pointing to namespace entries in proc (/proc/[pid]/ns/pid). If source / target is negative then current pid namespace is used.
If pid is negative then
getvpid()returns pid of parent task for -pid.If pid is unreachable from target namespace then syscall returns zero.
Errors:
ESRCH task not found EBADF closed file descriptor EINVAL not pid-namespace file descriptorExamples:
getvpid(pid, ns, -1) -> pid in our pid namespace getvpid(pid, -1, ns) -> pid in container getvpid(1, ns1, ns2) > 0 -> ns1 inside ns2 getvpid(1, ns1, ns2) == 0 -> ns1 outside ns2 getvpid(1, ns, -1) -> init task of pid-namespace getvpid(-1, ns, -1) -> task in parent pid-namespace getvpid(-pid, -1, -1) -> get ppid by pidSigned-off-by Konstantin Khlebnikov <[email protected]>---
v2:
* use namespace-fd as second/third argument
* add -pid for getting parent pid
* move code intokernel/sys.cnext to getppid
* drop ifdefCONFIG_PID_NS
* add generic syscall--- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 1 + include/uapi/asm-generic/unistd.h | 4 ++ kernel/sys.c | 63 ++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-)arch/x86/entry/syscalls/syscall_32.tbl +1
-0@@ -382,3 +382,4 @@ 373 i386 shutdown sys_shutdown 374 i386 userfaultfd sys_userfaultfd 375 i386 membarrier sys_membarrier +376 i386 getvpid sys_getvpidarch/x86/entry/syscalls/syscall_64.tbl +1
-0@@ -331,6 +331,7 @@ 322 64 execveat stub_execveat 323 common userfaultfd sys_userfaultfd 324 common membarrier sys_membarrier +325 common getvpid sys_getvpid # # x32-specific system call numbers start at 512 to avoid cache impactinclude/linux/syscalls.h +1
-0@@ -222,6 +222,7 @@ asmlinkage long sys_nanosleep(struct timespec __user *rqtp, struct timespec __usasmlinkage long sys_alarm (unsigned int seconds);asmlinkage long sys_getpid (void );asmlinkage long sys_getppid (void ); +asmlinkage long sys_getvpid (pid_t pid,int source,int target);asmlinkage long sys_getuid (void );asmlinkage long sys_geteuid (void );asmlinkage long sys_getgid (void );include/uapi/asm-generic/unistd.h +3
-1@@ -711,9 +711,11 @@ __SYSCALL(__NR_bpf, sys_bpf) __SC_COMP(__NR_execveat, sys_execveat, compat_sys_execveat)#define __NR_membarrier 282 __SYSCALL(__NR_membarrier, sys_membarrier) +#define __NR_getvpid 283 +__SYSCALL(__NR_getvpid, sys_getvpid)#undef __NR_syscalls -#define __NR_syscalls 283 +#define __NR_syscalls 284/* * All syscalls below here should go away really, kernel/sys.c +25
-0@@ -46,6 +46,7 @@#include <linux/syscalls.h> #include <linux/kprobes.h> #include <linux/user_namespace.h> +#include <linux/proc_ns.h> #include <linux/binfmts.h> #include <linux/sched.h> @@ -855,6 +856,68 @@ SYSCALL_DEFINE0(getppid)return pid; } +SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) +{ +struct file *source_file =NULL , *target_file =NULL ; +struct pid_namespace *source_ns, *target_ns; +struct pid *struct_pid; +struct ns_common *ns; +pid_t result; + +if (source >=0 ) { + source_file =proc_ns_fget (source); + result =PTR_ERR (source_file); +if (IS_ERR (source_file)) + goto out; + ns =get_proc_ns (file_inode (source_file)); + result = -EINVAL ; +if (ns->ops->type !=CLONE_NEWPID ) + goto out; + source_ns = container_of(ns, struct pid_namespace, ns); + }else + source_ns =task_active_pid_ns (current); + +if (target >=0 ) { + target_file =proc_ns_fget (target); + result =PTR_ERR (target_file);
kernel/sys.c SYSCALL_DEFINE0(getppid) · line 892
Quoted 10 lines
kernel/sys.c +10
-0+if (IS_ERR (target_file)) + goto out; + ns =get_proc_ns (file_inode (target_file)); + result = -EINVAL ; +if (ns->ops->type !=CLONE_NEWPID ) + goto out; + target_ns = container_of(ns, struct pid_namespace, ns); + }else + target_ns =task_active_pid_ns (current); +
the source ns and target ns translation looks the same, why not extract a new method to do the job.
Thanks,
Chen
Quoted 34 lines
kernel/sys.c +28
-0+rcu_read_lock (); + struct_pid =find_pid_ns (abs (pid), source_ns); + +if (struct_pid && pid <0 ) { +struct task_struct *task; + + task =pid_task (struct_pid,PIDTYPE_PID ); +if (task) + task =rcu_dereference (task->real_parent); + struct_pid = task ?task_pid (task) :NULL ; + } + +if (struct_pid) + result =pid_nr_ns (struct_pid, target_ns); +else + result = -ESRCH ; +rcu_read_unlock (); + +out: +if (!IS_ERR_OR_NULL (target_file)) +fput (target_file); + +if (!IS_ERR_OR_NULL (source_file)) +fput (source_file); + +return result; +} +SYSCALL_DEFINE0 (getuid) {/* Only we change this so SMP safe */ .