diff options
-rw-r--r-- | pkg/sentry/kernel/task_context.go | 1 | ||||
-rw-r--r-- | test/syscalls/linux/prctl.cc | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/pkg/sentry/kernel/task_context.go b/pkg/sentry/kernel/task_context.go index d1c82f2aa..1b4d4cf2f 100644 --- a/pkg/sentry/kernel/task_context.go +++ b/pkg/sentry/kernel/task_context.go @@ -74,6 +74,7 @@ func (tc *TaskContext) release() { // of the original's. func (tc *TaskContext) Fork(ctx context.Context, k *Kernel, shareAddressSpace bool) (*TaskContext, error) { newTC := &TaskContext{ + Name: tc.Name, Arch: tc.Arch.Fork(), st: tc.st, } diff --git a/test/syscalls/linux/prctl.cc b/test/syscalls/linux/prctl.cc index 44f3df6a3..854dec714 100644 --- a/test/syscalls/linux/prctl.cc +++ b/test/syscalls/linux/prctl.cc @@ -52,6 +52,30 @@ TEST(PrctlTest, SetNameLongName) { ASSERT_EQ(long_name.substr(0, truncated_length), std::string(truncated_name)); } +TEST(PrctlTest, ChildProcessName) { + constexpr size_t kMaxNameLength = 15; + + char parent_name[kMaxNameLength + 1] = {}; + memset(parent_name, 'a', kMaxNameLength); + + ASSERT_THAT(prctl(PR_SET_NAME, parent_name), SyscallSucceeds()); + + pid_t child_pid = fork(); + TEST_PCHECK(child_pid >= 0); + if (child_pid == 0) { + char child_name[kMaxNameLength + 1] = {}; + TEST_PCHECK(prctl(PR_GET_NAME, child_name) >= 0); + TEST_CHECK(memcmp(parent_name, child_name, sizeof(parent_name)) == 0); + _exit(0); + } + + int status; + ASSERT_THAT(waitpid(child_pid, &status, 0), + SyscallSucceedsWithValue(child_pid)); + EXPECT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0) + << "status =" << status; +} + // Offset added to exit code from test child to distinguish from other abnormal // exits. constexpr int kPrctlNoNewPrivsTestChildExitBase = 100; |