this repo has no description
1
fork

Configure Feed

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

Merge pull request #207 from X0rg/master

Support module loading from new darling executable

authored by

Luboš Doležel and committed by
GitHub
cf5e7e2b 2a0ace3e

+80 -2
+74
src/dyld/darling.c
··· 31 31 #include <sys/mount.h> 32 32 #include <sys/wait.h> 33 33 #include <sys/prctl.h> 34 + #include <sys/utsname.h> 35 + #include <sys/stat.h> 36 + #include <sys/syscall.h> 34 37 #include "darling.h" 35 38 #include "darling-config.h" 36 39 ··· 54 57 return 1; 55 58 }*/ 56 59 60 + if (loadKernelModule()) 61 + return 1; 62 + 57 63 // Temporarily drop root privileges 58 64 g_originalUid = getuid(); 59 65 seteuid(getuid()); ··· 110 116 } 111 117 112 118 // TODO: Spawn the executable in the namespace, wait for it and return its exit code 119 + unloadKernelModule(); 113 120 return 0; 114 121 } 115 122 ··· 350 357 exit(1); 351 358 } 352 359 } 360 + 361 + int isModuleLoaded() 362 + { 363 + size_t len = 0; 364 + ssize_t read = 0; 365 + char * line = NULL; 366 + FILE *fp = NULL; 367 + 368 + if ((fp = fopen("/proc/modules", "r")) == NULL) 369 + { 370 + fprintf(stderr, "Failure opening /proc/modules: %s\n", strerror(errno)); 371 + return 0; 372 + } 373 + 374 + while (!feof(fp)) 375 + { 376 + read = getline(&line, &len, fp); 377 + if (read > 0 && strstr(line, "darling_mach") != NULL) 378 + return 1; 379 + } 380 + 381 + return 0; 382 + } 383 + 384 + int loadKernelModule() 385 + { 386 + int fd; 387 + char path[128]; 388 + struct utsname name; 389 + 390 + if (isModuleLoaded()) 391 + return 0; 392 + 393 + uname(&name); 394 + sprintf(path, "/lib/modules/%s/kernel/misc/darling-mach.ko", name.release); 395 + if (access(path, F_OK)) 396 + { 397 + fprintf(stderr, "Cannot find kernel module at %s: %s\n", path, strerror(errno)); 398 + return 1; 399 + } 400 + 401 + fd = open(path, O_RDONLY|O_CLOEXEC); 402 + if (fd < 0) 403 + { 404 + fprintf(stderr, "Cannot open kernel module\n"); 405 + return 1; 406 + } 407 + 408 + if (syscall(SYS_finit_module, fd, "", 0)) 409 + { 410 + fprintf(stderr, "Cannot load kernel module: %s\n", strerror(errno)); 411 + return 1; 412 + } 413 + 414 + return 0; 415 + } 416 + 417 + int unloadKernelModule() 418 + { 419 + if(syscall(SYS_delete_module, "darling_mach", 0)) 420 + { 421 + fprintf(stderr, "Cannot unload kernel module: %s\n", strerror(errno)); 422 + return 1; 423 + } 424 + 425 + return 0; 426 + }
+5 -1
src/dyld/darling.h
··· 42 42 43 43 void checkPrefixOwner(const char* prefix); 44 44 45 - #endif 45 + int isModuleLoaded(void); 46 46 47 + int loadKernelModule(void); 47 48 49 + int unloadKernelModule(void); 50 + 51 + #endif
+1 -1
src/lkm/dkms.conf
··· 3 3 CLEAN="make clean" 4 4 MAKE[0]="make all KVERSION=$kernelver" 5 5 BUILT_MODULE_NAME[0]="darling-mach" 6 - DEST_MODULE_LOCATION[0]="/updates" 6 + DEST_MODULE_LOCATION[0]="/kernel/misc" 7 7 AUTOINSTALL="yes"