All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] pidns13: Use getpid syscall directly instead of glibc wrapper
@ 2021-03-16  9:50 Yang Xu
  2021-03-16 10:15 ` Yang Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Xu @ 2021-03-16  9:50 UTC (permalink / raw)
  To: ltp

As clone(2) man-pages said "GNU C library versions 2.3.4 up to and including
2.24 contained a wrapper function for getpid(2) that performed caching of PIDs.
This caching relied on support in the glibc wrapper for clone(), but limitations
in the implementation meant that the cache was not up to date in some circumstances".

Because of the stale-cache problem, as well as other problems noted in getpid(2), the
PID caching feature was removed in glibc 2.25

To get the truth, always use getpid syscall instead of getting value from cache.
It fixes failure on centos7.

Reported-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 testcases/kernel/containers/pidns/pidns13.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/containers/pidns/pidns13.c b/testcases/kernel/containers/pidns/pidns13.c
index 12aee917b..c27ef51b4 100644
--- a/testcases/kernel/containers/pidns/pidns13.c
+++ b/testcases/kernel/containers/pidns/pidns13.c
@@ -54,7 +54,7 @@ static void child_fn(unsigned int cinit_no)
 	pid_t pid, ppid;
 	int flags;
 
-	pid = getpid();
+	pid = tst_syscall(__NR_getpid);
 	ppid = getppid();
 	if (pid != CHILD_PID || ppid != PARENT_PID)
 		tst_brk(TBROK, "cinit%u: pidns not created.", cinit_no);
-- 
2.23.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] pidns13: Use getpid syscall directly instead of glibc wrapper
  2021-03-16  9:50 [LTP] [PATCH] pidns13: Use getpid syscall directly instead of glibc wrapper Yang Xu
@ 2021-03-16 10:15 ` Yang Xu
  2021-03-17  7:01   ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Xu @ 2021-03-16 10:15 UTC (permalink / raw)
  To: ltp

Hi All
I guess the following commit message is more clear.
"
From  glibc  version  2.3.4  up  to  and  including version 2.24, the glibc wrapper function for getpid() cached PIDs, 
with the goal of avoiding additional system calls when a process calls getpid()repeatedly.  Normally this caching was
invisible, but its correct operation relied on support in the wrapper functions for fork(2), vfork(2), and clone(2):
if an application bypassed the glibc wrappers for these system calls by using syscall(2), then a call to getpid()
in the child would return the wrong value (to be precise: it would return the PID of the parent process).  In addition,
there were cases where getpid() could return the wrong value even when invoking clone(2) via the glibc wrapper function. 
"(For a discussion of one such case, see BUGS in clone(2).)"

Because of the aforementioned problems, since glibc version 2.25, the PID cache is removed: calls to getpid() always invoke
the actual system call, rather than returning a cached value.
"
On old api, pidns13 doesn't fail because we use clone and getpid glibc wrapper, now we use clone3 syscall directly and use 
getpid glibc wrapper, so it fails on older glibc ie glibc-2.17.

> As clone(2) man-pages said "GNU C library versions 2.3.4 up to and including
> 2.24 contained a wrapper function for getpid(2) that performed caching of PIDs.
> This caching relied on support in the glibc wrapper for clone(), but limitations
> in the implementation meant that the cache was not up to date in some circumstances".
>
> Because of the stale-cache problem, as well as other problems noted in getpid(2), the
> PID caching feature was removed in glibc 2.25
>
> To get the truth, always use getpid syscall instead of getting value from cache.
> It fixes failure on centos7.
>
> Reported-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> ---
>  testcases/kernel/containers/pidns/pidns13.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/containers/pidns/pidns13.c b/testcases/kernel/containers/pidns/pidns13.c
> index 12aee917b..c27ef51b4 100644
> --- a/testcases/kernel/containers/pidns/pidns13.c
> +++ b/testcases/kernel/containers/pidns/pidns13.c
> @@ -54,7 +54,7 @@ static void child_fn(unsigned int cinit_no)
>  	pid_t pid, ppid;
>  	int flags;
>  
> -	pid = getpid();
> +	pid = tst_syscall(__NR_getpid);
>  	ppid = getppid();
>  	if (pid != CHILD_PID || ppid != PARENT_PID)
>  		tst_brk(TBROK, "cinit%u: pidns not created.", cinit_no);




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] pidns13: Use getpid syscall directly instead of glibc wrapper
  2021-03-16 10:15 ` Yang Xu
@ 2021-03-17  7:01   ` Petr Vorel
  2021-03-17 10:38     ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2021-03-17  7:01 UTC (permalink / raw)
  To: ltp

Hi Xu,

good catch, thanks!

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] pidns13: Use getpid syscall directly instead of glibc wrapper
  2021-03-17  7:01   ` Petr Vorel
@ 2021-03-17 10:38     ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2021-03-17 10:38 UTC (permalink / raw)
  To: ltp

Hi Xu,

> good catch, thanks!

Merged with slightly changed and reformatted commit message.
Thanks!

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-17 10:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16  9:50 [LTP] [PATCH] pidns13: Use getpid syscall directly instead of glibc wrapper Yang Xu
2021-03-16 10:15 ` Yang Xu
2021-03-17  7:01   ` Petr Vorel
2021-03-17 10:38     ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.