execve(): return correct error value when failure (errno)
This commit is contained in:
@@ -344,16 +344,28 @@ int load_elf_desc(char *filename, struct program_load_desc **desc_p)
|
||||
char *interp_path;
|
||||
struct program_load_desc *desc;
|
||||
int ret = 0;
|
||||
struct stat sb;
|
||||
|
||||
if ((ret = access(filename, X_OK)) != 0) {
|
||||
fprintf(stderr, "Error: %s is not an executable?\n", filename);
|
||||
return ret;
|
||||
fprintf(stderr, "Error: %s is not an executable?, errno: %d\n",
|
||||
filename, errno);
|
||||
return errno;
|
||||
}
|
||||
|
||||
if ((ret = stat(filename, &sb)) == -1) {
|
||||
fprintf(stderr, "Error: failed to stat %s\n", filename);
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (sb.st_size == 0) {
|
||||
fprintf(stderr, "Error: file %s is zero length\n", filename);
|
||||
return ENOEXEC;
|
||||
}
|
||||
|
||||
fp = fopen(filename, "rb");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Error: Failed to open %s\n", filename);
|
||||
return 1;
|
||||
return errno;
|
||||
}
|
||||
|
||||
desc = load_elf(fp, &interp_path);
|
||||
@@ -1249,6 +1261,11 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
|
||||
if (!PATH) {
|
||||
PATH = getenv("PATH");
|
||||
}
|
||||
|
||||
if (strlen(filename) >= 255) {
|
||||
ret = ENAMETOOLONG;
|
||||
goto return_execve1;
|
||||
}
|
||||
|
||||
__dprintf("PATH: %s\n", PATH);
|
||||
|
||||
@@ -1278,7 +1295,15 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
|
||||
free(tofree);
|
||||
}
|
||||
else {
|
||||
error = snprintf(path, sizeof(path), "%s", filename);
|
||||
char *root = getenv("COKERNEL_EXEC_ROOT");
|
||||
|
||||
if (root) {
|
||||
error = snprintf(path, sizeof(path), "%s/%s", root, filename);
|
||||
}
|
||||
else {
|
||||
error = snprintf(path, sizeof(path), "%s", filename);
|
||||
}
|
||||
|
||||
if (error < 0 || error >= sizeof(path)) {
|
||||
fprintf(stderr, "execve(): array too small?\n");
|
||||
goto return_execve1;
|
||||
@@ -1290,6 +1315,7 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock)
|
||||
if (!found) {
|
||||
fprintf(stderr,
|
||||
"execve(): error finding file %s\n", filename);
|
||||
ret = ENOENT;
|
||||
goto return_execve1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1188,6 +1188,21 @@ SYSCALL_DECLARE(execve)
|
||||
|
||||
struct syscall_request request IHK_DMA_ALIGN;
|
||||
struct program_load_desc *desc;
|
||||
struct process_vm *vm = cpu_local_var(current)->vm;
|
||||
struct vm_range *range;
|
||||
|
||||
ihk_mc_spinlock_lock_noirq(&vm->memory_range_lock);
|
||||
|
||||
range = lookup_process_memory_range(vm, (unsigned long)filename,
|
||||
(unsigned long)filename+1);
|
||||
|
||||
if (range == NULL || !(range->flag & VR_PROT_READ)) {
|
||||
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
|
||||
kprintf("execve(): ERROR: filename is bad address\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
|
||||
|
||||
desc = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!desc) {
|
||||
@@ -1205,8 +1220,9 @@ SYSCALL_DECLARE(execve)
|
||||
ret = do_syscall(&request, ctx, ihk_mc_get_processor_id(), 0);
|
||||
|
||||
if (ret != 0) {
|
||||
kprintf("execve(): ERROR: host failed to load elf header\n");
|
||||
return -EINVAL;
|
||||
kprintf("execve(): ERROR: host failed to load elf header, errno: %d\n",
|
||||
ret);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
dkprintf("execve(): ELF desc received, num sections: %d\n",
|
||||
|
||||
Reference in New Issue
Block a user