1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2020 Bernd Edlinger <bernd.edlinger@hotmail.de>
6 * Check whether /proc/$pid/mem can be accessed without causing deadlocks
7 * when de_thread is blocked with ->cred_guard_mutex held.
10 #include "../kselftest_harness.h"
16 #include <sys/ptrace.h>
18 static void *thread(void *arg
)
20 ptrace(PTRACE_TRACEME
, 0, 0L, 0L);
32 pthread_create(&pt
, NULL
, thread
, NULL
);
33 pthread_join(pt
, NULL
);
34 execlp("true", "true", NULL
);
38 sprintf(mm
, "/proc/%d/mem", pid
);
39 f
= open(mm
, O_RDONLY
);
42 f
= kill(pid
, SIGCONT
);
48 int s
, k
, pid
= fork();
53 pthread_create(&pt
, NULL
, thread
, NULL
);
54 pthread_join(pt
, NULL
);
55 execlp("sleep", "sleep", "2", NULL
);
59 k
= ptrace(PTRACE_ATTACH
, pid
, 0L, 0L);
60 ASSERT_EQ(errno
, EAGAIN
);
62 k
= waitpid(-1, &s
, WNOHANG
);
66 ASSERT_EQ(WIFEXITED(s
), 1);
67 ASSERT_EQ(WEXITSTATUS(s
), 0);
69 k
= ptrace(PTRACE_ATTACH
, pid
, 0L, 0L);
71 k
= waitpid(-1, &s
, 0);
73 ASSERT_EQ(WIFSTOPPED(s
), 1);
74 ASSERT_EQ(WSTOPSIG(s
), SIGSTOP
);
75 k
= ptrace(PTRACE_DETACH
, pid
, 0L, 0L);
77 k
= waitpid(-1, &s
, 0);
79 ASSERT_EQ(WIFEXITED(s
), 1);
80 ASSERT_EQ(WEXITSTATUS(s
), 0);
81 k
= waitpid(-1, NULL
, 0);
83 ASSERT_EQ(errno
, ECHILD
);