Skip to content

Commit d5973d8

Browse files
committed
Tests: Add a test verifying that ptrace self-attaching fails
1 parent ea5d3a6 commit d5973d8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Tests/Kernel/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(LIBTEST_BASED_SOURCES
5050
TestPosixFallocate.cpp
5151
TestPosixSpawn.cpp
5252
TestPrivateInodeVMObject.cpp
53+
TestPtraceSelfAttach.cpp
5354
TestKernelAlarm.cpp
5455
TestKernelFilePermissions.cpp
5556
TestKernelPledge.cpp
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2026, the SerenityOS developers.
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <LibTest/TestCase.h>
8+
#include <errno.h>
9+
#include <pthread.h>
10+
#include <sys/ptrace.h>
11+
#include <unistd.h>
12+
13+
static void* thread_entry(void*)
14+
{
15+
while (1)
16+
continue;
17+
18+
return nullptr;
19+
}
20+
21+
TEST_CASE(ptrace_self_attach_fail)
22+
{
23+
pthread_t thread = 0;
24+
VERIFY(pthread_create(&thread, nullptr, thread_entry, nullptr) == 0);
25+
VERIFY(thread > 0);
26+
int ptrace_return = ptrace(PT_ATTACH, thread, 0, 0);
27+
int error = errno;
28+
EXPECT_EQ(ptrace_return, -1);
29+
EXPECT_EQ(error, EPERM);
30+
}

0 commit comments

Comments
 (0)