public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/kcmp03: work around bug in C library
@ 2017-09-05 20:40 Steve Muckle
  2017-09-06 10:09 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Muckle @ 2017-09-05 20:40 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Steve Muckle <smuckle.linux@gmail.com>
---
 testcases/kernel/syscalls/kcmp/kcmp03.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/testcases/kernel/syscalls/kcmp/kcmp03.c b/testcases/kernel/syscalls/kcmp/kcmp03.c
index b6ca40cff..465cb1e8b 100644
--- a/testcases/kernel/syscalls/kcmp/kcmp03.c
+++ b/testcases/kernel/syscalls/kcmp/kcmp03.c
@@ -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"
-- 
2.14.1.581.gf28d330327-goog


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

end of thread, other threads:[~2017-09-07 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-05 20:40 [LTP] [PATCH] syscalls/kcmp03: work around bug in C library Steve Muckle
2017-09-06 10:09 ` Cyril Hrubis
2017-09-07 17:42   ` Steve Muckle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox