Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow invalid memfd_create *name arguments #3739

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ set(BASIC_TESTS
map_shared_syscall
membarrier
memfd_create
memfd_create_efault
memfd_create_shared
memfd_create_shared_huge
mincore
Expand Down
7 changes: 5 additions & 2 deletions src/record_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4383,8 +4383,11 @@ static Switchable rec_prepare_syscall_arch(RecordTask* t,
}

case Arch::memfd_create: {
string name = t->read_c_str(remote_ptr<char>(regs.arg1()));
if (is_blacklisted_memfd(name.c_str())) {
bool ok = true;
string name = t->read_c_str(remote_ptr<char>(regs.arg1()), &ok);
if (!ok) {
syscall_state.expect_errno = EFAULT;
} else if (is_blacklisted_memfd(name.c_str())) {
LOG(warn) << "Cowardly refusing to memfd_create " << name;
Registers r = regs;
r.set_arg1(0);
Expand Down
19 changes: 19 additions & 0 deletions src/test/memfd_create_efault.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "util.h"

int main(void) {
int fd;

/* There's no libc helper for this syscall. */
fd = syscall(RR_memfd_create, NULL, 0);
if (ENOSYS == errno) {
atomic_puts("SYS_memfd_create not supported on this kernel");
} else {
test_assert(fd == -1);
test_assert(errno == EFAULT);
}

atomic_puts("EXIT-SUCCESS");
return 0;
}
Loading