Skip to content

Commit e7fe0ee

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

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
void* thread_entry(void*)
14+
{
15+
while (1)
16+
continue;
17+
}
18+
19+
TEST_CASE(ptrace_self_attach_fail)
20+
{
21+
pthread_t thread = 0;
22+
VERIFY(pthread_create(&thread, nullptr, thread_entry, nullptr) == 0);
23+
VERIFY(thread > 0);
24+
int ptrace_return = ptrace(PT_ATTACH, thread, 0, 0);
25+
int error = errno;
26+
EXPECT_EQ(ptrace_return, -1);
27+
EXPECT_EQ(error, EPERM);
28+
}

0 commit comments

Comments
 (0)