Skip to content

Commit b3993e2

Browse files
authored
Check if the binary is setuid root
Otherwise we can get mount failed: operation not permitted (e.g., on NixOS when the fusermount3 found on the $PATH is /run/current-system/sw/bin/fusermount3)
1 parent 932cb73 commit b3993e2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/runtime/runtime.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,20 @@ char* find_fusermount() {
443443
char* fusermount_full_path = malloc(strlen(dir) + strlen(entry->d_name) + 2);
444444
sprintf(fusermount_full_path, "%s/%s", dir, entry->d_name);
445445

446+
// Check if the binary is setuid root
447+
struct stat sb;
448+
if (stat(fusermount_full_path, &sb) == -1) {
449+
perror("stat");
450+
free(fusermount_full_path);
451+
continue;
452+
}
453+
454+
if (sb.st_uid != 0 || (sb.st_mode & S_ISUID) == 0) {
455+
// Not setuid root, skip this binary
456+
free(fusermount_full_path);
457+
continue;
458+
}
459+
446460
pid_t pid = fork();
447461
if (pid == -1) {
448462
perror("fork");

0 commit comments

Comments
 (0)