extern int fini(void) { thread_shutdown = true; pthread_join(job_handler_thread, NULL); _save_state(); list_destroy(jobslist); xfree(log_url); return SLURM_SUCCESS; }
extern int container_p_delete(uint32_t job_id) { #ifdef HAVE_NATIVE_CRAY rid_t resv_id = job_id; DEF_TIMERS; #endif int rc = 0; int i, found = -1; bool job_id_change = false; if (debug_flags & DEBUG_FLAG_JOB_CONT) info("%s: deleting(%u)", plugin_type, job_id); slurm_mutex_lock(&context_lock); for (i = 0; i < job_id_count; i++) { if (job_id_array[i] == job_id) { job_id_array[i] = 0; job_id_change = true; found = i; } } if (found == -1) info("%s: no job for delete(%u)", plugin_type, job_id); if (job_id_change) _save_state(state_dir); slurm_mutex_unlock(&context_lock); #ifdef HAVE_NATIVE_CRAY START_TIMER; rc = job_end_reservation(resv_id, DELETE_FLAGS); if (debug_flags & DEBUG_FLAG_TIME_CRAY) { END_TIMER; INFO_LINE("call took: %s", TIME_STR); } else END_TIMER3("container_p_delete: job_end_reservation took", 3000000); #endif if (rc == 0) return SLURM_SUCCESS; if ((errno == ENOENT) || (errno == EINPROGRESS) || (errno == EALREADY)) return SLURM_SUCCESS; /* Not fatal error */ error("%s: delete(%u): %m", plugin_type, job_id); return SLURM_ERROR; }
extern int container_p_create(uint32_t job_id) { #ifdef HAVE_NATIVE_CRAY rid_t resv_id = job_id; int rc; #endif int i, empty = -1, found = -1; DEF_TIMERS; START_TIMER; if (debug_flags & DEBUG_FLAG_JOB_CONT) info("%s: creating(%u)", plugin_type, job_id); slurm_mutex_lock(&context_lock); for (i = 0; i < job_id_count; i++) { if (job_id_array[i] == 0) { empty = i; } else if (job_id_array[i] == job_id) { found = i; break; } } if (found == -1) { if (empty == -1) { empty = job_id_count; job_id_count += 4; job_id_array = xrealloc(job_id_array, sizeof(uint32_t)*job_id_count); } job_id_array[empty] = job_id; _save_state(state_dir); } slurm_mutex_unlock(&context_lock); if (debug_flags & DEBUG_FLAG_TIME_CRAY) { END_TIMER; INFO_LINE("call took: %s", TIME_STR); } else { END_TIMER3("container_p_create: saving state took", 3000000); } #ifdef HAVE_NATIVE_CRAY START_TIMER; rc = job_create_reservation(resv_id, CREATE_FLAGS); if (debug_flags & DEBUG_FLAG_TIME_CRAY) { END_TIMER; INFO_LINE("call took: %s", TIME_STR); } else END_TIMER3("container_p_create: job_create_reservation took", 3000000); if ((rc == 0) || (errno == EEXIST)) { if ((found == -1) && (rc != 0) && (errno == EEXIST)) { error("%s: create(%u): Reservation already exists", plugin_type, job_id); } if (debug_flags & DEBUG_FLAG_JOB_CONT) _stat_reservation("create", resv_id); return SLURM_SUCCESS; } error("%s: create(%u): %m", plugin_type, job_id); return SLURM_ERROR; #else return SLURM_SUCCESS; #endif }
int inject_code(int pid, unsigned char *payload, size_t payload_len) { int ret = 0, status = 0; void *payload_addr = NULL, *stack = NULL, *code_cave = NULL, *payload_aligned = NULL; size_t payload_size; // align shellcode size to 32/64-bit boundary payload_size = payload_len + (sizeof(void*) - (payload_len % sizeof(void*))); payload_aligned = malloc(payload_size); CHECK(payload_aligned, "malloc() error"); memset(payload_aligned, 0x90, payload_size); // fill with NOPs memcpy(payload_aligned, payload, payload_len); printf("Injecting into target process %d\n", pid); // attach to process CHECK(ptrace_attach(pid), "Error attaching to target process %d", pid); dprintf("Attached to process"); // wait to make sure process is in ptrace-stop state before continuing, // otherwise we may inadvertently kill the process CHECK(wait_stopped(pid), "Failed to wait until target process in stopped state"); dprintf("Process is in stopped state"); // Wait until process has just returned from a system call before proceeding CHECK(ptrace_next_syscall(pid), "Failed to wait until after next syscall"); dprintf("Process exited from syscall"); // save state CHECK(_save_state(pid), "Failed to state target process state"); dprintf("Saved state of target process"); // allocate payload space CHECK(_mmap_data(pid, payload_size, NULL, 0, 0, &payload_addr), "Failed to allocate space for payload"); dprintf("Allocated space for payload at location %p", payload_addr); // copy payload CHECK(ptrace_writemem(pid, payload_addr, payload_aligned, payload_size), "Failed to copy payload to target process"); dprintf("Wrote payload to target process at address %p", payload_addr); // allocate new stack CHECK(_mmap_data(pid, STACK_SIZE, NULL, 0, 0, &stack), "Failed to allocate space for new stack"); stack += STACK_SIZE; // use top address as stack base, since stack grows downward dprintf("Allocated new stack at location %p", stack); // allocate space for code cave CHECK(_mmap_data(pid, MAX_CODE_SIZE, NULL, 0, 0, &code_cave), "Failed to allocate space for code cave"); dprintf("Allocated space for code cave at location %p", code_cave); // launch payload via clone(2) dprintf("Launching payload in new thread"); CHECK(_launch_payload(pid, code_cave, MAX_CODE_SIZE, stack, STACK_SIZE, payload_addr, payload_size, NULL, 0), "Failed to launch payload"); ret = 1; error: if (payload_aligned) free(payload_aligned); _restore_state(pid); ptrace_detach(pid); return ret; }