Skip to content

Commit 6731b72

Browse files
committed
Don't die when is_privileged_executable fails
Resolves #3894
1 parent db5faf8 commit 6731b72

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,8 @@ set(BASIC_TESTS
10681068
fd_cleanup
10691069
fd_tracking_across_threads
10701070
fds_clean
1071+
fexecve
1072+
fexecve_memfd
10711073
flock
10721074
flock_ofd
10731075
flock2

src/record_syscall.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5566,12 +5566,15 @@ static bool is_privileged_executable(RecordTask* t, const string& path) {
55665566
return true;
55675567
}
55685568
} else {
5569-
ASSERT(t, errno == ENODATA || errno == ENOTSUP);
5570-
struct stat buf;
5571-
stat(path.c_str(), &buf);
5572-
if (buf.st_mode & (S_ISUID | S_ISGID)) {
5573-
return true;
5569+
if (errno == ENOENT) {
5570+
return false;
55745571
}
5572+
ASSERT(t, errno == ENODATA || errno == ENOTSUP);
5573+
}
5574+
struct stat buf;
5575+
stat(path.c_str(), &buf);
5576+
if (buf.st_mode & (S_ISUID | S_ISGID)) {
5577+
return true;
55755578
}
55765579
return false;
55775580
}

src/test/fexecve.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
2+
3+
#include "util.h"
4+
5+
int main(int argc, char* argv[]) {
6+
test_assert(argc == 1 || (argc == 2 && !strcmp("self", argv[1])));
7+
8+
if (argc != 2) {
9+
int fd = open("/proc/self/exe", O_RDONLY);
10+
test_assert(fd >= 0);
11+
char* new_args[] = { argv[0], "self", NULL };
12+
int ret = syscall(RR_execveat, fd, "", new_args, environ, AT_EMPTY_PATH);
13+
if (ret < 0 && errno == ENOSYS) {
14+
atomic_puts("execveat not supported, skipping test");
15+
atomic_puts("EXIT-SUCCESS");
16+
return 0;
17+
}
18+
test_assert("Not reached" && 0);
19+
}
20+
21+
atomic_puts("EXIT-SUCCESS");
22+
return 0;
23+
}

src/test/fexecve_memfd.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
2+
3+
#include "util.h"
4+
5+
static void copy_file(int from_fd, int to_fd) {
6+
char buf[4096];
7+
ssize_t ret;
8+
9+
while ((ret = read(from_fd, buf, sizeof(buf))) > 0) {
10+
test_assert(write(to_fd, buf, ret) == ret);
11+
}
12+
test_assert(ret == 0);
13+
}
14+
15+
int main(int argc, char* argv[]) {
16+
test_assert(argc == 1 || (argc == 2 && !strcmp("self", argv[1])));
17+
18+
if (argc != 2) {
19+
int fd = open("/proc/self/exe", O_RDONLY);
20+
test_assert(fd >= 0);
21+
int memfd = syscall(RR_memfd_create, "test", 0);
22+
copy_file(fd, memfd);
23+
char* new_args[] = { argv[0], "self", NULL };
24+
int ret = syscall(RR_execveat, memfd, "", new_args, environ, AT_EMPTY_PATH);
25+
if (ret < 0 && errno == ENOSYS) {
26+
atomic_puts("execveat not supported, skipping test");
27+
atomic_puts("EXIT-SUCCESS");
28+
return 0;
29+
}
30+
test_assert("Not reached" && 0);
31+
}
32+
33+
atomic_puts("EXIT-SUCCESS");
34+
return 0;
35+
}

0 commit comments

Comments
 (0)