this repo has no description
1
fork

Configure Feed

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

Place the /dev/mach descriptor to the highest fd number and obscure it

+33 -2
+5
src/kernel/emulation/linux/misc/getrlimit.c
··· 16 16 if (ret < 0) 17 17 ret = errno_linux_to_bsd(ret); 18 18 19 + if (which == LINUX_RLIMIT_NOFILE) 20 + { 21 + rlp->rlim_cur--; 22 + rlp->rlim_max--; 23 + } 19 24 return ret; 20 25 } 21 26
+8 -1
src/kernel/emulation/linux/misc/setrlimit.c
··· 7 7 long sys_setrlimit(unsigned int which, const struct rlimit* rlp) 8 8 { 9 9 int ret; 10 + struct rlimit lim = { rlp->rlim_cur, rlp->rlim_max }; 10 11 11 12 which = rlimit_bsd_to_linux(which); 12 13 if (which == -1) 13 14 return -EINVAL; 14 15 15 - ret = LINUX_SYSCALL(__NR_prlimit64, 0, which, rlp, 0); 16 + if (which == LINUX_RLIMIT_NOFILE) 17 + { 18 + lim.rlim_cur++; 19 + lim.rlim_max++; 20 + } 21 + 22 + ret = LINUX_SYSCALL(__NR_prlimit64, 0, which, &lim, 0); 16 23 if (ret < 0) 17 24 ret = errno_linux_to_bsd(ret); 18 25
+1 -1
src/kernel/emulation/linux/unistd/getdtablesize.c
··· 16 16 if (ret < 0) 17 17 return ret; 18 18 19 - return min(lim.rlim_max, INT_MAX); 19 + return min(lim.rlim_cur, INT_MAX); 20 20 } 21 21
+19
src/kernel/mach_server/client/lkm.c
··· 2 2 #include "../../lkm/api.h" 3 3 #include <fcntl.h> 4 4 #include <unistd.h> 5 + #include <sys/resource.h> 5 6 #include "../../libsyscall/wrappers/_libkernel_init.h" 6 7 7 8 int driver_fd = -1; ··· 11 12 extern int sys_close(int); 12 13 extern int sys_write(int, const void*, int); 13 14 extern int sys_kill(int, int); 15 + extern int sys_getrlimit(int, struct rlimit*); 16 + extern int sys_dup2(int, int); 17 + extern int sys_fcntl(int, int, int); 14 18 extern _libkernel_functions_t _libkernel_functions; 15 19 16 20 void mach_driver_init(void) 17 21 { 22 + struct rlimit lim; 23 + 18 24 if (driver_fd != -1) 19 25 sys_close(driver_fd); 20 26 #ifndef VARIANT_DYLD ··· 46 52 47 53 sys_write(2, msg, strlen(msg)); 48 54 sys_kill(0, 6); 55 + } 56 + 57 + if (sys_getrlimit(RLIMIT_NOFILE, &lim) == 0) 58 + { 59 + // sys_getrlimit intentionally reports a limit lower by 1 60 + // so that our fd remains "hidden" to applications. 61 + // It also means rlim_cur is not above the limit 62 + // in the following statement. 63 + int d = sys_dup2(driver_fd, lim.rlim_cur); 64 + sys_close(driver_fd); 65 + 66 + driver_fd = d; 67 + sys_fcntl(driver_fd, F_SETFD, O_CLOEXEC); 49 68 } 50 69 } 51 70