From f957fb23cf68e72084c7b50569242a07997f96bc Mon Sep 17 00:00:00 2001 From: "chris.zn" Date: Thu, 20 Jun 2019 15:19:05 +0800 Subject: Return ENOENT when reading /proc/{pid}/task of an exited process There will be a deadloop when we use getdents to read /proc/{pid}/task of an exited process Like this: Process A is running Process B: open /proc/{pid of A}/task Process A exits Process B: getdents /proc/{pid of A}/task Then, process B will fall into deadloop, and return "." and ".." in loops and never ends. This patch returns ENOENT when use getdents to read /proc/{pid}/task if the process is just exited. Signed-off-by: chris.zn --- test/syscalls/linux/proc.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/syscalls/linux') diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc index 924b98e3a..2177665c8 100644 --- a/test/syscalls/linux/proc.cc +++ b/test/syscalls/linux/proc.cc @@ -1908,6 +1908,25 @@ void CheckDuplicatesRecursively(std::string path) { TEST(Proc, NoDuplicates) { CheckDuplicatesRecursively("/proc"); } +TEST(Proc, Getdents) { + int child_pid = fork(); + ASSERT_GE(child_pid, 0); + if (child_pid == 0) { + while(1){ + sleep(100); + } + } + ASSERT_THAT(child_pid, SyscallSucceeds()); + char name[100]; + char buf[1024]; + int fd; + sprintf(name, "/proc/%d/task", child_pid); + fd = open(name, O_RDONLY | O_DIRECTORY); + ASSERT_THAT(kill(child_pid, SIGKILL), SyscallSucceeds()); + ASSERT_THAT(waitpid(child_pid, NULL, 0), SyscallSucceedsWithValue(child_pid)); + ASSERT_THAT(syscall(SYS_getdents, fd, buf, 1024), SyscallFailsWithErrno(ENOENT)); +} + // Most /proc/PID files are owned by the task user with SUID_DUMP_USER. TEST(ProcPid, UserDumpableOwner) { int before; -- cgit v1.2.3