int main(int argc, char **argv) { int lc; tst_parse_opts(argc, argv, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; /* Test the system call */ TEST(create_module(modname, MODSIZE)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL, "create_module() failed errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "create_module() returned 0x%x", TEST_RETURN); if (delete_module(modname) != 0) { tst_brkm(TBROK, NULL, "Failed to delete" "loadable module entry for %s", modname); } } } /* perform global cleanup and exit */ cleanup(); }
int rmmod_main(int argc, char **argv) { int ret; char *modname, *dot; /* make sure we've got an argument */ if (argc < 2) { fprintf(stderr, "usage: rmmod <module>\n"); return -1; } /* if given /foo/bar/blah.ko, make a weak attempt * to convert to "blah", just for convenience */ modname = strrchr(argv[1], '/'); if (!modname) modname = argv[1]; else modname++; dot = strchr(argv[1], '.'); if (dot) *dot = '\0'; /* pass it to the kernel */ ret = delete_module(modname, O_NONBLOCK | O_EXCL); if (ret != 0) { fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n", modname, errno); return -1; } return 0; }
static s32 rmmod(const s8 *modname) { #ifndef SDK_TEST s32 ret = 0; s32 maxtry = 10; while (maxtry-- > 0) { ret = delete_module(modname, O_NONBLOCK | O_EXCL); if (ret < 0 && errno == EAGAIN){ usleep(50000); } else { break; } } if (ret != 0) { LOGD("Unable to unload driver module \"%s\": %s\n", modname, strerror(errno)); } return ret; #else return 0; #endif }
static void delete_module_( void * xmodule, void * data ) { module_t *m = (module_t *)xmodule; delete_module( m ); object_free( m->name ); }
void modules_done() { hashenumerate( module_hash, delete_module_, (void *)0 ); hashdone( module_hash ); module_hash = 0; delete_module( &root ); }
struct module * find_module(struct carousel *car, uint16_t module_id, uint8_t version, uint32_t download_id) { unsigned int i; for(i=0; i<car->nmodules; i++) { if(car->modules[i].module_id == module_id && car->modules[i].download_id == download_id) { /* spot on */ if(car->modules[i].version == version) { return &car->modules[i]; } /* is it an update to one we already have */ else if(car->modules[i].version != version) { delete_module(car, i); return NULL; } } } return NULL; }
void cleanup2(void) { /* Remove loadable module entry */ if (delete_module(modname) == -1) { tst_brkm(TBROK, NULL, "Failed to delete module entry" " for %s", modname); } }
extern int rmmod_main(int argc, char **argv) { int n, ret = EXIT_SUCCESS; size_t nmod = 0; /* number of modules */ size_t pnmod = -1; /* previous number of modules */ void *buf; /* hold the module names which we ignore but must get */ size_t bufsize = 0; /* Parse command line. */ while ((n = getopt(argc, argv, "a")) != EOF) { switch (n) { case 'a': /* Unload _all_ unused modules via NULL delete_module() call */ /* until the number of modules does not change */ buf = xmalloc(bufsize = 256); while (nmod != pnmod) { if (delete_module(NULL)) bb_perror_msg_and_die("rmmod"); pnmod = nmod; /* 1 == QM_MODULES */ if (my_query_module(NULL, 1, &buf, &bufsize, &nmod)) { bb_perror_msg_and_die("QM_MODULES"); } } #ifdef CONFIG_FEATURE_CLEAN_UP free(buf); #endif return EXIT_SUCCESS; default: bb_show_usage(); } } if (optind == argc) bb_show_usage(); for (n = optind; n < argc; n++) { if (delete_module(argv[n]) < 0) { bb_perror_msg("%s", argv[n]); ret = EXIT_FAILURE; } } return(ret); }
int main(int argc, char **argv) { if (argc != 2) { puts("Usage ./prog mymodule"); return EXIT_FAILURE; } if (delete_module(argv[1], O_NONBLOCK) != 0) { perror("delete_module"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
void syscall_helper(int argc, char **argv) { (void) argc; if (strcmp(argv[2], "mount") == 0) { int rv = mount(NULL, NULL, NULL, 0, NULL); (void) rv; printf("\nUGLY: mount syscall permitted.\n"); } else if (strcmp(argv[2], "umount2") == 0) { umount2(NULL, 0); printf("\nUGLY: umount2 syscall permitted.\n"); } else if (strcmp(argv[2], "ptrace") == 0) { ptrace(0, 0, NULL, NULL); printf("\nUGLY: ptrace syscall permitted.\n"); } else if (strcmp(argv[2], "swapon") == 0) { swapon(NULL, 0); printf("\nUGLY: swapon syscall permitted.\n"); } else if (strcmp(argv[2], "swapoff") == 0) { swapoff(NULL); printf("\nUGLY: swapoff syscall permitted.\n"); } else if (strcmp(argv[2], "init_module") == 0) { init_module(NULL, 0, NULL); printf("\nUGLY: init_module syscall permitted.\n"); } else if (strcmp(argv[2], "delete_module") == 0) { delete_module(NULL, 0); printf("\nUGLY: delete_module syscall permitted.\n"); } else if (strcmp(argv[2], "chroot") == 0) { int rv = chroot("/blablabla-57281292"); (void) rv; printf("\nUGLY: chroot syscall permitted.\n"); } else if (strcmp(argv[2], "pivot_root") == 0) { pivot_root(NULL, NULL); printf("\nUGLY: pivot_root syscall permitted.\n"); } #if defined(__i386__) || defined(__x86_64__) else if (strcmp(argv[2], "iopl") == 0) { iopl(0L); printf("\nUGLY: iopl syscall permitted.\n"); } else if (strcmp(argv[2], "ioperm") == 0) { ioperm(0, 0, 0); printf("\nUGLY: ioperm syscall permitted.\n"); } #endif exit(0); }
char* RmModuleFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 1) return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); char *module_name; int retval; if (ReadArgs(state, argv, 1, &module_name) < 0) return NULL; retval = delete_module(module_name, O_NONBLOCK | O_EXCL); free(module_name); return (retval == 0? strdup("t") : strdup("")); }
PUBLIC BOOL HTAA_deleteModule (const char * scheme) { if (scheme) { HTAAModule * pres = find_module(scheme); if (pres) { HTList_removeObject(HTSchemes, pres); HTTRACE(AUTH_TRACE, "Auth Engine. deleted %p\n" _ pres); delete_module(pres); return YES; } } return NO; }
PUBLIC BOOL HTAA_deleteAllModules (void) { if (HTSchemes) { HTList * cur = HTSchemes; HTAAModule * pres; while ((pres = (HTAAModule *) HTList_nextObject(cur))) delete_module(pres); HTList_delete(HTSchemes); HTSchemes = NULL; return YES; } return NO; }
int main(int argc, char **argv) { int lc; char *msg; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; for (testno = 0; testno < TST_TOTAL; ++testno) { if ((tdat[testno].setup) && (tdat[testno].setup())) { /* setup() failed, skip this test */ continue; } /* Test the system call */ TEST(delete_module(tdat[testno].modname)); TEST_ERROR_LOG(TEST_ERRNO); printf("TEST_RETURN is %d, TEST_ERRNO is %d\n", TEST_RETURN, TEST_ERRNO); if ((TEST_RETURN == EXP_RET_VAL) && (TEST_ERRNO == tdat[testno].experrno) ) { tst_resm(TPASS, "Expected results for %s, " "errno: %d", tdat[testno].desc, TEST_ERRNO); } else { tst_resm(TFAIL, "Unexpected results for %s ; " "returned %d (expected %d), " "errno %d (expected %d)", tdat[testno].desc, TEST_RETURN, EXP_RET_VAL, TEST_ERRNO, tdat[testno].experrno); } if (tdat[testno].cleanup) { tdat[testno].cleanup(); } } } cleanup(); tst_exit(); }
/* * cleanup() * performs all ONE TIME cleanup for this test at * completion or premature exit */ void cleanup(void) { /* * If module entry is not removed (possible if create_module() * succeeds and signal is caught before execution of delete_module()) * attempt to remove it here */ if (delete_module(modname) == -1) { /* With errno, check module exists, if so send msg */ if (errno != ENOENT) { tst_resm(TWARN, "Failed to delete loadable module" "entry for %s errno returned %d", modname, errno); } } }
static int rmmod(const char *modname) { int ret = -1; int maxtry = 10; while (maxtry-- > 0) { ret = delete_module(modname, O_NONBLOCK | O_EXCL | O_TRUNC); if (ret < 0 && errno == EAGAIN) usleep(500000); else break; } if (ret != 0) LOGD("Unable to unload driver module \"%s\": %s\n", modname, strerror(errno)); return ret; }
int ModuleCtrl::rmmod(const char *modname) { int ret = -1; int maxtry = REMOVE_RETRY_COUNT; while ((maxtry--) > 0) { ret = delete_module(modname, O_NONBLOCK | O_EXCL); if (ret < 0 && errno == EAGAIN) usleep(REMOVE_RETRY_DELAY); else break; } if (ret != 0) ALOGD("Unable to unload driver module \"%s\": %s\n", modname, strerror(errno)); return ret; }
void rmmod_main(void) { unsigned int flags = O_NONBLOCK|O_EXCL; char * mod_name; int len; // Basename mod_name = basename(*toys.optargs); // Remove .ko if present len = strlen(mod_name); if (len > 3 && !strcmp(&mod_name[len-3], ".ko" )) mod_name[len-3] = 0; if (toys.optflags & FLAG_f) flags |= O_TRUNC; if (toys.optflags & FLAG_w) flags &= ~O_NONBLOCK; if (delete_module(mod_name, flags)) perror_exit("failed to unload %s", mod_name); }
int main(int argc, char **argv) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(argc, argv, NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* Test the system call */ TEST(create_module(modname,MODSIZE)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL, "create_module() failed errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "create_module() returned 0x%x", TEST_RETURN); if (delete_module(modname) != 0) { tst_brkm(TBROK, NULL, "Failed to delete" "loadable module entry for %s", modname); } } } /* perform global cleanup and exit */ cleanup(); }
static int rmmod(int log, int verbose, const char *path, int flags) { long ret; char name[strlen(path) + 1]; filename2modname(name, path); if ((flags & O_NONBLOCK) && !(flags & O_TRUNC)) { if (check_usage(log, name) != 0) return 1; } info(log, "rmmod %s, wait=%s%s\n", name, (flags & O_NONBLOCK) ? "no" : "yes", (flags & O_TRUNC) ? " force" : ""); ret = delete_module(name, flags); if (ret != 0) error(log, "Removing '%s': %s\n", name, strerror(errno)); return ret; }
int rmmod_main(int argc, char **argv) { int ret, i; char *modname, *dot; /* make sure we've got an argument */ if(argc < 2) { fprintf(stderr, "Usage: rmmod <module>\n"); return -1; } /* if given /foo/bar/blah.ko, make a weak attempt * to convert to "blah", just for convenience */ modname = strrchr(argv[1], '/'); if(!modname) modname = argv[1]; else modname++; dot = strchr(argv[1], '.'); if(dot) *dot = 0; /* Replace "-" with "_". This would keep rmmod * compatible with module-init-tools version of * rmmod */ for (i = 0; modname[i] != '\0'; i++) { if (modname[i] == '-') modname[i] = '_'; } /* pass it to the kernel */ ret = delete_module(modname, O_NONBLOCK | O_EXCL); if (ret != 0) { fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n", modname, errno); return -1; } return 0; }
static int rmmod(const char *modname) { int ret = -1; int maxtry = 10; /* Use rfkill if "module" is 'rfkill' */ if (!strncmp(DRIVER_MODULE_PATH, "rfkill", 6)) { return set_wifi_power(0); } while (maxtry-- > 0) { ret = delete_module(modname, O_NONBLOCK | O_EXCL | O_TRUNC); if (ret < 0 && errno == EAGAIN) usleep(500000); else break; } if (ret != 0) LOGD("Unable to unload driver module \"%s\": %s\n", modname, strerror(errno)); return ret; }
static int rmmod(const char *modname) { LOGE("zhiyuan add debug********* wifi_load_driver()->rmmod()*******return 0 **********"); return 0; int ret = -1; int maxtry = 10; while (maxtry-- > 0) { ret = delete_module(modname, O_NONBLOCK | O_EXCL); if (ret < 0 && errno == EAGAIN) usleep(500000); else break; } if (ret != 0) LOGD("Unable to unload driver module \"%s\": %s\n", modname, strerror(errno)); return ret; }
/* * cleanup() * performs all ONE TIME cleanup for this test at * completion or premature exit */ void cleanup(void) { /* * If module entry is not removed (possible if create_module() * succeeds and signal is caught before execution of delete_module()) * attempt to remove it here */ if (delete_module(modname) == -1) { /* With errno, check module exists, if so send msg */ if (errno != ENOENT) { tst_resm(TWARN, "Failed to delete loadable module" "entry for %s errno returned %d", modname, errno); } } /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; }
int FAST_FUNC bb_delete_module(const char *module, unsigned int flags) { return delete_module(module, flags); }
int FAST_FUNC bb_delete_module(const char *module, unsigned int flags) { errno = 0; delete_module(module, flags); return errno; }
static void stage_capability_test(void) { char tmp1[128]; char tmp2[128]; memset(tmp1, 0, sizeof(tmp1)); memset(tmp2, 0, sizeof(tmp2)); capability = "inet_tcp_create"; set_capability(); if (write_policy()) { int fd = socket(AF_INET, SOCK_STREAM, 0); show_result(fd, 1); if (fd != EOF) close(fd); delete_policy(); fd = socket(AF_INET, SOCK_STREAM, 0); show_result(fd, 0); if (fd != EOF) close(fd); } unset_capability(); { int fd1 = socket(AF_INET, SOCK_STREAM, 0); int fd2 = socket(AF_INET, SOCK_STREAM, 0); int fd3 = socket(AF_INET, SOCK_STREAM, 0); int fd4 = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in addr; socklen_t size = sizeof(addr); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(0); bind(fd1, (struct sockaddr *) &addr, sizeof(addr)); bind(fd2, (struct sockaddr *) &addr, sizeof(addr)); bind(fd3, (struct sockaddr *) &addr, sizeof(addr)); bind(fd4, (struct sockaddr *) &addr, sizeof(addr)); getsockname(fd1, (struct sockaddr *) &addr, &size); capability = "inet_tcp_listen"; set_capability(); if (write_policy()) { show_result(listen(fd1, 5), 1); delete_policy(); show_result(listen(fd2, 5), 0); } unset_capability(); capability = "inet_tcp_connect"; set_capability(); if (write_policy()) { show_result(connect(fd3, (struct sockaddr *) &addr, sizeof(addr)), 1); delete_policy(); show_result(connect(fd4, (struct sockaddr *) &addr, sizeof(addr)), 0); } unset_capability(); if (fd1 != EOF) close(fd1); if (fd2 != EOF) close(fd2); if (fd3 != EOF) close(fd3); if (fd4 != EOF) close(fd4); } capability = "use_inet_udp"; set_capability(); if (write_policy()) { int fd = socket(AF_INET, SOCK_DGRAM, 0); show_result(fd, 1); if (fd != EOF) close(fd); delete_policy(); fd = socket(AF_INET, SOCK_DGRAM, 0); show_result(fd, 0); if (fd != EOF) close(fd); } unset_capability(); capability = "use_inet_ip"; set_capability(); if (write_policy()) { int fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); show_result(fd, 1); if (fd != EOF) close(fd); delete_policy(); fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); show_result(fd, 0); if (fd != EOF) close(fd); } unset_capability(); capability = "use_route"; set_capability(); if (write_policy()) { int fd = socket(AF_ROUTE, SOCK_RAW, 0); show_result(fd, 1); if (fd != EOF) close(fd); delete_policy(); fd = socket(AF_ROUTE, SOCK_RAW, 0); show_result(fd, 0); if (fd != EOF) close(fd); } unset_capability(); capability = "use_packet"; set_capability(); if (write_policy()) { int fd = socket(AF_PACKET, SOCK_RAW, 0); show_result(fd, 1); if (fd != EOF) close(fd); delete_policy(); fd = socket(AF_PACKET, SOCK_RAW, 0); show_result(fd, 0); if (fd != EOF) close(fd); } unset_capability(); capability = "use_kernel_module"; set_capability(); if (write_policy()) { if (!is_kernel26) show_result((int) create_module("", 0), 1); show_result(init_module("", NULL), 1); show_result(delete_module(""), 1); delete_policy(); if (!is_kernel26) show_result((int) create_module("", 0), 0); show_result(init_module("", NULL), 0); show_result(delete_module(""), 0); } unset_capability(); capability = "create_fifo"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/XXXXXX"); close(mkstemp(tmp1)); unlink(tmp1); show_result(mknod(tmp1, S_IFIFO, 0), 1); unlink(tmp1); delete_policy(); show_result(mknod(tmp1, S_IFIFO, 0), 0); unlink(tmp1); } unset_capability(); capability = "create_block_dev"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/XXXXXX"); close(mkstemp(tmp1)); unlink(tmp1); show_result(mknod(tmp1, S_IFBLK, MKDEV(1, 0)), 1); unlink(tmp1); delete_policy(); show_result(mknod(tmp1, S_IFBLK, MKDEV(1, 0)), 0); unlink(tmp1); } unset_capability(); capability = "create_char_dev"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/XXXXXX"); close(mkstemp(tmp1)); unlink(tmp1); show_result(mknod(tmp1, S_IFCHR, MKDEV(1, 3)), 1); unlink(tmp1); delete_policy(); show_result(mknod(tmp1, S_IFCHR, MKDEV(1, 3)), 0); unlink(tmp1); } unset_capability(); capability = "create_unix_socket"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/XXXXXX"); close(mkstemp(tmp1)); unlink(tmp1); show_result(mknod(tmp1, S_IFSOCK, 0), 1); unlink(tmp1); delete_policy(); show_result(mknod(tmp1, S_IFSOCK, 0), 0); unlink(tmp1); } if (write_policy()) { struct sockaddr_un addr; int fd1 = socket(AF_UNIX, SOCK_STREAM, 0); int fd2 = socket(AF_UNIX, SOCK_STREAM, 0); memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strcpy(tmp1, "/tmp/XXXXXX"); strncpy(addr.sun_path, tmp1, sizeof(addr.sun_path) - 1); show_result(bind(fd1, (struct sockaddr *) &addr, sizeof(addr)), 1); unlink(tmp1); delete_policy(); show_result(bind(fd2, (struct sockaddr *) &addr, sizeof(addr)), 0); unlink(tmp1); if (fd1 != EOF) close(fd1); if (fd2 != EOF) close(fd2); } unset_capability(); capability = "SYS_MOUNT"; set_capability(); if (write_policy()) { show_result(mount("/", "/", "tmpfs", 0, NULL), 1); delete_policy(); show_result(mount("/", "/", "tmpfs", 0, NULL), 0); } unset_capability(); capability = "SYS_UMOUNT"; set_capability(); if (write_policy()) { mount("/tmp", "/tmp", "tmpfs", 0, NULL); show_result(umount("/tmp"), 1); delete_policy(); mount("/tmp", "/tmp", "tmpfs", 0, NULL); show_result(umount("/"), 0); } unset_capability(); capability = "SYS_REBOOT"; set_capability(); if (write_policy()) { FILE *fp = fopen("/proc/sys/kernel/ctrl-alt-del", "a+"); unsigned int c; if (fp && fscanf(fp, "%u", &c) == 1) { show_result(reboot(LINUX_REBOOT_CMD_CAD_ON), 1); delete_policy(); show_result(reboot(LINUX_REBOOT_CMD_CAD_ON), 0); fprintf(fp, "%u\n", c); } else { /* Use invalid value */ show_result(reboot(0x0000C0DE), 1); delete_policy(); show_result(reboot(0x0000C0DE), 0); } if (fp) fclose(fp); } unset_capability(); capability = "SYS_CHROOT"; set_capability(); if (write_policy()) { show_result(chroot("/"), 1); delete_policy(); show_result(chroot("/"), 0); } unset_capability(); capability = "SYS_PIVOT_ROOT"; set_capability(); if (write_policy()) { int error; char *stack = malloc(8192); pid_t pid = clone(child, stack + (8192 / 2), CLONE_NEWNS, NULL); while (waitpid(pid, &error, __WALL) == EOF && errno == EINTR) error += 0; /* Dummy. */ errno = WIFEXITED(error) ? WEXITSTATUS(error) : -1; show_result(errno ? EOF : 0, 1); delete_policy(); pid = clone(child, stack + (8192 / 2), CLONE_NEWNS, NULL); while (waitpid(pid, &error, __WALL) == EOF && errno == EINTR) error += 0; /* Dummy. */ errno = WIFEXITED(error) ? WEXITSTATUS(error) : -1; show_result(errno ? EOF : 0, 0); free(stack); } unset_capability(); signal(SIGINT, SIG_IGN); capability = "SYS_KILL"; set_capability(); if (write_policy()) { show_result(kill(pid, SIGINT), 1); show_result(tkill(gettid(), SIGINT), 1); #ifdef __NR_tgkill if (is_kernel26) show_result(tgkill(pid, gettid(), SIGINT), 1); #endif delete_policy(); show_result(kill(pid, SIGINT), 0); show_result(tkill(gettid(), SIGINT), 0); #ifdef __NR_tgkill if (is_kernel26) show_result(tgkill(pid, gettid(), SIGINT), 0); #endif } unset_capability(); signal(SIGINT, SIG_DFL); capability = "SYS_KEXEC_LOAD"; set_capability(); if (write_policy()) { #ifdef __NR_sys_kexec_load if (is_kernel26) show_result(sys_kexec_load(0, 0, NULL, 0), 1); #endif delete_policy(); #ifdef __NR_sys_kexec_load if (is_kernel26) show_result(sys_kexec_load(0, 0, NULL, 0), 0); #endif } unset_capability(); capability = "SYS_VHANGUP"; set_capability(); if (write_policy()) { int pty_fd = EOF, status = 0; int pipe_fd[2] = { EOF, EOF }; pipe(pipe_fd); switch (forkpty(&pty_fd, NULL, NULL, NULL)) { case 0: errno = 0; vhangup(); /* Unreachable if vhangup() succeeded. */ status = errno; write(pipe_fd[1], &status, sizeof(status)); _exit(0); case -1: fprintf(stderr, "forkpty() failed.\n"); break; default: close(pipe_fd[1]); read(pipe_fd[0], &status, sizeof(status)); wait(NULL); close(pipe_fd[0]); close(pty_fd); errno = status; show_result(status ? EOF : 0, 1); } delete_policy(); status = 0; pipe(pipe_fd); switch (forkpty(&pty_fd, NULL, NULL, NULL)) { case 0: errno = 0; vhangup(); /* Unreachable if vhangup() succeeded. */ status = errno; write(pipe_fd[1], &status, sizeof(status)); _exit(0); case -1: fprintf(stderr, "forkpty() failed.\n"); break; default: close(pipe_fd[1]); read(pipe_fd[0], &status, sizeof(status)); wait(NULL); close(pipe_fd[0]); close(pty_fd); errno = status; show_result(status ? EOF : 0, 0); } } unset_capability(); capability = "SYS_TIME"; set_capability(); if (write_policy()) { struct timeval tv; struct timezone tz; struct timex buf; time_t now = time(NULL); show_result(stime(&now), 1); gettimeofday(&tv, &tz); show_result(settimeofday(&tv, &tz), 1); memset(&buf, 0, sizeof(buf)); buf.modes = 0x100; /* Use invalid value so that the clock won't change. */ show_result(adjtimex(&buf), 1); delete_policy(); now = time(NULL); show_result(stime(&now), 0); gettimeofday(&tv, &tz); show_result(settimeofday(&tv, &tz), 0); memset(&buf, 0, sizeof(buf)); buf.modes = 0x100; /* Use invalid value so that the clock won't change. */ show_result(adjtimex(&buf), 0); } unset_capability(); capability = "SYS_NICE"; set_capability(); if (write_policy()) { show_result(nice(0), 1); show_result(setpriority(PRIO_PROCESS, pid, getpriority(PRIO_PROCESS, pid)), 1); delete_policy(); show_result(nice(0), 0); show_result(setpriority(PRIO_PROCESS, pid, getpriority(PRIO_PROCESS, pid)), 0); } unset_capability(); capability = "SYS_SETHOSTNAME"; set_capability(); if (write_policy()) { char buffer[4096]; memset(buffer, 0, sizeof(buffer)); gethostname(buffer, sizeof(buffer) - 1); show_result(sethostname(buffer, strlen(buffer)), 1); getdomainname(buffer, sizeof(buffer) - 1); show_result(setdomainname(buffer, strlen(buffer)), 1); delete_policy(); gethostname(buffer, sizeof(buffer) - 1); show_result(sethostname(buffer, strlen(buffer)), 0); getdomainname(buffer, sizeof(buffer) - 1); show_result(setdomainname(buffer, strlen(buffer)), 0); } unset_capability(); capability = "SYS_LINK"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/link_source_XXXXXX"); close(mkstemp(tmp1)); strcpy(tmp2, "/tmp/link_target_XXXXXX"); show_result(link(tmp1, tmp2), 1); unlink(tmp2); unlink(tmp1); delete_policy(); strcpy(tmp1, "/tmp/link_source_XXXXXX"); close(mkstemp(tmp1)); strcpy(tmp2, "/tmp/link_target_XXXXXX"); show_result(link(tmp1, tmp2), 0); unlink(tmp2); unlink(tmp1); } unset_capability(); capability = "SYS_SYMLINK"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/symlink_target_XXXXXX"); close(mkstemp(tmp1)); strcpy(tmp2, "/tmp/symlink_source_XXXXXX"); show_result(symlink(tmp1, tmp2), 1); unlink(tmp2); unlink(tmp1); delete_policy(); strcpy(tmp1, "/tmp/symlink_target_XXXXXX"); close(mkstemp(tmp1)); strcpy(tmp2, "/tmp/symlink_source_XXXXXX"); show_result(symlink(tmp1, tmp2), 0); unlink(tmp2); unlink(tmp1); } unset_capability(); capability = "SYS_RENAME"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/rename_old_XXXXXX"); close(mkstemp(tmp1)); strcpy(tmp2, "/tmp/rename_new_XXXXXX"); show_result(rename(tmp1, tmp2), 1); unlink(tmp2); unlink(tmp1); delete_policy(); strcpy(tmp1, "/tmp/rename_old_XXXXXX"); close(mkstemp(tmp1)); strcpy(tmp2, "/tmp/rename_new_XXXXXX"); show_result(rename(tmp1, tmp2), 0); unlink(tmp2); unlink(tmp1); } unset_capability(); capability = "SYS_UNLINK"; set_capability(); if (write_policy()) { strcpy(tmp1, "/tmp/unlinkXXXXXX"); close(mkstemp(tmp1)); show_result(unlink(tmp1), 1); delete_policy(); strcpy(tmp1, "/tmp/unlinkXXXXXX"); close(mkstemp(tmp1)); show_result(unlink(tmp1), 0); } unset_capability(); unlink(tmp1); capability = "SYS_CHMOD"; set_capability(); if (write_policy()) { show_result(chmod("/dev/null", 0222), 1); delete_policy(); show_result(chmod("/dev/null", 0444), 0); } unset_capability(); chmod("/dev/null", 0666); capability = "SYS_CHOWN"; set_capability(); if (write_policy()) { show_result(chown("/dev/null", 1, 1), 1); delete_policy(); show_result(chown("/dev/null", 2, 2), 0); } unset_capability(); chown("/dev/null", 0, 0); capability = "SYS_IOCTL"; set_capability(); if (0 && write_policy()) { int fd = open("/dev/null", O_RDONLY); show_result(ioctl(fd, 0 /* Use invalid value so that nothing happen. */), 1); delete_policy(); show_result(ioctl(fd, 0 /* Use invalid value so that nothing happen. */), 0); close(fd); } if (write_policy()) { struct ifreq ifreq; int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); memset(&ifreq, 0, sizeof(ifreq)); snprintf(ifreq.ifr_name, sizeof(ifreq.ifr_name) - 1, "lo"); show_result(ioctl(fd, 35123, &ifreq), 1); delete_policy(); show_result(ioctl(fd, 35123, &ifreq), 0); close(fd); } unset_capability(); capability = "SYS_PTRACE"; set_capability(); if (write_policy()) { int status = 0; int pipe_fd[2] = { EOF, EOF }; pipe(pipe_fd); switch (fork()) { case 0: errno = 0; ptrace(PTRACE_TRACEME, 0, NULL, NULL); status = errno; write(pipe_fd[1], &status, sizeof(status)); _exit(0); case -1: fprintf(stderr, "fork() failed.\n"); break; default: close(pipe_fd[1]); read(pipe_fd[0], &status, sizeof(status)); wait(NULL); close(pipe_fd[0]); errno = status; show_result(status ? EOF : 0, 1); } delete_policy(); status = 0; pipe(pipe_fd); switch (fork()) { case 0: errno = 0; ptrace(PTRACE_TRACEME, 0, NULL, NULL); status = errno; write(pipe_fd[1], &status, sizeof(status)); _exit(0); case -1: fprintf(stderr, "fork() failed.\n"); break; default: close(pipe_fd[1]); read(pipe_fd[0], &status, sizeof(status)); wait(NULL); close(pipe_fd[0]); errno = status; show_result(status ? EOF : 0, 0); } } unset_capability(); }
bool Modules::unload(char const * const name, bool force, bool wait) { // TODO Check /proc/modules for module usage return delete_module(name, (force ? O_TRUNC : 0) | (wait ? 0 : O_NONBLOCK)) == 0; }
int main(int argc, char **argv) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ char cmd[50]; /* parse standard options */ if ((msg = parse_opts(argc, argv, (option_t*) NULL, NULL)) != (char *) NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } if(STD_COPIES != 1) { tst_resm(TINFO, "-c option has no effect for this testcase - " "doesn't allow running more than one instance " "at a time"); STD_COPIES = 1; } /* Load first kernel module */ if( sprintf(cmd, "/sbin/insmod %s/%s.ko", dirname(argv[0]), DUMMY_MOD) <= 0) { tst_resm(TBROK, "sprintf failed"); return 1; } if( (system(cmd)) != 0 ) { tst_resm(TBROK, "Failed to load %s module", DUMMY_MOD); return 1; } /* Load dependant kernel module */ if( sprintf(cmd, "/sbin/insmod %s/%s.ko", dirname(argv[0]), DUMMY_MOD_DEP) <= 0) { tst_resm(TBROK, "sprintf failed"); goto END; } if( (system(cmd)) != 0 ) { tst_resm(TBROK, "Failed to load %s module", DUMMY_MOD_DEP); goto END; } tst_tmpdir(); if(setup() != 0) { return 1; } /* check looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; /* Test the system call */ TEST(delete_module(DUMMY_MOD)); TEST_ERROR_LOG(TEST_ERRNO); if ( (TEST_RETURN == (int) EXP_RET_VAL ) && (TEST_ERRNO == EXP_ERRNO) ) { tst_resm(TPASS, "Expected failure for module in-use, " "errno: %d", TEST_ERRNO); } else { tst_resm(TFAIL, "Unexpected results for module in-use; " "returned %d (expected %d), errno %d " "(expected %d)", TEST_RETURN, EXP_RET_VAL, TEST_ERRNO, EXP_ERRNO); } } cleanup(); END: if(system("rmmod "DUMMY_MOD) != 0) { tst_resm(TBROK, "Failed to unload %s module", DUMMY_MOD); return 1; } /*NOTREACHED*/ return 0; }
static int manual_rmmod(const char *name) { return delete_module(name, O_NONBLOCK|O_EXCL); }