Skip to content

Commit 0fd5efb

Browse files
usatiukrocallahan
authored andcommitted
Allow invalid memfd_create *name arguments
Some applications might call it with e.g. NULL to check for memfd_create support, in these cases EFAULT should be returned
1 parent 5b7c1f4 commit 0fd5efb

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ set(BASIC_TESTS
10961096
map_shared_syscall
10971097
membarrier
10981098
memfd_create
1099+
memfd_create_efault
10991100
memfd_create_shared
11001101
memfd_create_shared_huge
11011102
mincore

src/record_syscall.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -4383,8 +4383,11 @@ static Switchable rec_prepare_syscall_arch(RecordTask* t,
43834383
}
43844384

43854385
case Arch::memfd_create: {
4386-
string name = t->read_c_str(remote_ptr<char>(regs.arg1()));
4387-
if (is_blacklisted_memfd(name.c_str())) {
4386+
bool ok = true;
4387+
string name = t->read_c_str(remote_ptr<char>(regs.arg1()), &ok);
4388+
if (!ok) {
4389+
syscall_state.expect_errno = EFAULT;
4390+
} else if (is_blacklisted_memfd(name.c_str())) {
43884391
LOG(warn) << "Cowardly refusing to memfd_create " << name;
43894392
Registers r = regs;
43904393
r.set_arg1(0);

src/test/memfd_create_efault.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
2+
3+
#include "util.h"
4+
5+
int main(void) {
6+
int fd;
7+
8+
/* There's no libc helper for this syscall. */
9+
fd = syscall(RR_memfd_create, NULL, 0);
10+
if (ENOSYS == errno) {
11+
atomic_puts("SYS_memfd_create not supported on this kernel");
12+
} else {
13+
test_assert(fd == -1);
14+
test_assert(errno == EFAULT);
15+
}
16+
17+
atomic_puts("EXIT-SUCCESS");
18+
return 0;
19+
}

0 commit comments

Comments
 (0)