Skip to contentSkip to conversation

syscalls/kcmp03: work around bug in C library

PATCH New Steve Muckle 2 participants 3 messages Sep 5, 2017 – Sep 7, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/kcmp03: work around bug in C library

Some versions of glibc and bionic report the same PID for parent and child when clone() is called with CLONE_VM but not CLONE_THREAD. This causes an issue in the cleanup path which is supposed to execute in the parent. If kcmp() support is not present, the child aborts and then erroneously runs the cleanup handler, freeing its own stack.

Avoid this by statically allocating the stack.

---
 testcases/kernel/syscalls/kcmp/kcmp03.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/kcmp/kcmp03.c +7 -13
index b6ca40cff..465cb1e8b 100644
@@ -40,7 +40,13 @@
 
 static int pid1;
 static int pid2;
-static void *stack;
+
+/*
+ * The cleanup handler may be run in the child due to a bug in some versions of
+ * glibc and bionic when clone() is called with CLONE_VM but not CLONE_THREAD.
+ * Use static allocation of stack to avoid this.
+ */
+static char stack[STACK_SIZE];
 
 static struct tcase {
 	int clone_type;
@@ -52,16 +58,6 @@ static struct tcase {
 	{CLONE_SYSVSEM, KCMP_SYSVSEM}
 };
 
-static void setup(void)
-{
-	stack = SAFE_MALLOC(STACK_SIZE);
-}
-
-static void cleanup(void)
-{
-	free(stack);
-}
-
 static int do_child(void *arg)
 {
 	pid2 = getpid();
@@ -96,8 +92,6 @@ static void verify_kcmp(unsigned int n)
 
 static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
-	.setup = setup,
-	.cleanup = cleanup,
 	.forks_child = 1,
 	.test = verify_kcmp,
 	.min_kver = "3.5.0"
Signature · 1 line
2.14.1.581.gf28d330327-goog
#1 lore raw

PATCH 1/1 syscalls/kcmp03: work around bug in C library

Hi!

Quoted 2 lines

Some versions of glibc and bionic report the same PID for parent and child when clone() is called with CLONE_VM but not CLONE_THREAD.

Is that the result of the infamous pid caching? Can we fix that by using the raw getpid() syscall in the test library? If so I guess that using raw syscall in the test library may be a safer bet.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 syscalls/kcmp03: work around bug in C library

Quoted 6 lines · Cyril Hrubis

Hi!

Quoted 3 lines

Some versions of glibc and bionic report the same PID for parent and child when clone() is called with CLONE_VM but not CLONE_THREAD.

Is that the result of the infamous pid caching?

In bionic yes, I can't say for sure in glibc but I'd assume so. I haven't tested a glibc version that had pid caching removed.

Quoted 3 lines

Can we fix that by using the raw getpid() syscall in the test library? If so I guess that using raw syscall in the test library may be a safer bet.

Probably. I'll try it.

thanks,
Steve