this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Resolve absolute symlinks relative to the prefix

This requires a change in libelfloader to ensure the interpreter is resolved according to the Linux root and not the prefix.

+69 -13
+1
Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/darling/emulation/ext/for-libelfloader.h
··· 1 + ../../../../../../../../../../../src/kernel/emulation/linux/ext/for-libelfloader.h
+1
src/kernel/emulation/linux/CMakeLists.txt
··· 266 266 ext/file_handle.c 267 267 ext/fanotify.c 268 268 ext/for-xtrace.c 269 + ext/for-libelfloader.c 269 270 bsdthread/bsdthread_register.c 270 271 bsdthread/bsdthread_create.c 271 272 bsdthread/bsdthread_ctl.c
+43
src/kernel/emulation/linux/ext/for-libelfloader.c
··· 1 + #include "for-libelfloader.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include "../bsdthread/cancelable.h" 5 + #include "../bsdthread/per_thread_wd.h" 6 + #include "../fcntl/open.h" 7 + 8 + VISIBLE 9 + long _open_for_libelfloader(const char* path, int flags, unsigned int mode) { 10 + int linux_flags; 11 + int wd; 12 + int ret; 13 + 14 + CANCELATION_POINT(); 15 + 16 + linux_flags = oflags_bsd_to_linux(flags); 17 + wd = oflags_bsd_to_linux(flags); 18 + 19 + if (sizeof(void*) == 4) { 20 + linux_flags |= LINUX_O_LARGEFILE; 21 + } 22 + 23 + ret = LINUX_SYSCALL(__NR_openat, wd, path, linux_flags, mode); 24 + if (ret < 0) 25 + ret = errno_linux_to_bsd(ret); 26 + 27 + return ret; 28 + }; 29 + 30 + VISIBLE 31 + long _access_for_libelfloader(const char* path, int mode) { 32 + int ret; 33 + int wd; 34 + 35 + wd = get_perthread_wd(); 36 + 37 + ret = LINUX_SYSCALL(__NR_faccessat, wd, path, mode, 0); 38 + 39 + if (ret < 0) 40 + ret = errno_linux_to_bsd(ret); 41 + 42 + return ret; 43 + };
+14
src/kernel/emulation/linux/ext/for-libelfloader.h
··· 1 + #ifndef _DARLING_EMULATION_FOR_LIBELFLOADER_H_ 2 + #define _DARLING_EMULATION_FOR_LIBELFLOADER_H_ 3 + 4 + #include <darling/emulation/base.h> 5 + 6 + // these are non-vchrooted calls for libelfloader 7 + 8 + VISIBLE 9 + long _open_for_libelfloader(const char* path, int flags, unsigned int mode); 10 + 11 + VISIBLE 12 + long _access_for_libelfloader(const char* path, int mode); 13 + 14 + #endif // _DARLING_EMULATION_FOR_LIBELFLOADER_H_
+6
src/kernel/emulation/linux/vchroot_userspace.c
··· 423 423 ctxt->follow = true; 424 424 ctxt->symlink_depth++; 425 425 426 + // resolve absolute symlinks within the prefix 427 + if (link[0] == '/') { 428 + ctxt->current_root = prefix_path; 429 + ctxt->current_root_len = prefix_path_len; 430 + } 431 + 426 432 rv = vchroot_run(link, ctxt); 427 433 428 434 ctxt->symlink_depth--;
+4 -13
src/libelfloader/loader.c
··· 28 28 #include <setjmp.h> 29 29 #include <sys/random.h> 30 30 #include <elf.h> 31 + #include <darling/emulation/ext/for-libelfloader.h> 31 32 #include "auxvec.h" 32 33 #include "loader.h" 33 34 #include "native/elfcalls.h" ··· 235 236 ElfW(Ehdr) elfHdr; 236 237 void* phdrs = NULL; 237 238 238 - int fd = open(path, O_RDONLY); 239 + // the interpreter path should be relative to the Linux root, not the Darling prefix 240 + int fd = isInterp ? _open_for_libelfloader(path, O_RDONLY, 0) : open(path, O_RDONLY); 239 241 uintptr_t slide, base; 240 242 241 243 if (fd == -1) ··· 389 391 interp[phdr->p_filesz] = '\0'; 390 392 391 393 // Load interpreter 392 - if (access(interp, F_OK) != 0) 393 - { 394 - char* prefixed = (char*) malloc(phdr->p_filesz + sizeof(SYSTEM_ROOT)); 395 - 396 - strcpy(prefixed, SYSTEM_ROOT); 397 - strcat(prefixed, interp); 398 - 399 - free(interp); 400 - interp = prefixed; 401 - } 402 - 403 - if (access(interp, F_OK) != 0) 394 + if (_access_for_libelfloader(interp, F_OK) != 0) 404 395 { 405 396 fprintf(stderr, "Cannot load interpreter at %s\n", interp); 406 397 free(interp);