From 81b9884180af688d29fe915e79788c29eb3a4d62 Mon Sep 17 00:00:00 2001 From: Yuta Imazu Date: Fri, 8 Nov 2024 21:57:44 +0900 Subject: [PATCH] exec: accept ELF file type ET_DYN --- kernel/api/elf.h | 2 ++ kernel/exec.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/api/elf.h b/kernel/api/elf.h index 79b33524..6c2b9269 100644 --- a/kernel/api/elf.h +++ b/kernel/api/elf.h @@ -37,6 +37,8 @@ typedef uint16_t Elf32_Half; (ehdr).e_ident[EI_MAG2] == ELFMAG2 && (ehdr).e_ident[EI_MAG3] == ELFMAG3) #define ET_EXEC 2 +#define ET_DYN 3 + #define EM_386 3 #define EV_CURRENT 1 diff --git a/kernel/exec.c b/kernel/exec.c index 02ed9051..97259e04 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -169,9 +169,7 @@ static int execve(const char* pathname, struct string_vec* argv, struct file* file = NULL; struct kstat stat; - mutex_lock(¤t->fs->lock); - ret = vfs_stat_at(current->fs->cwd, pathname, &stat, 0); - mutex_unlock(¤t->fs->lock); + ret = vfs_stat(pathname, &stat, 0); if (IS_ERR(ret)) goto fail_exe; if (!S_ISREG(stat.st_mode)) { @@ -215,7 +213,7 @@ static int execve(const char* pathname, struct string_vec* argv, ehdr->e_ident[EI_DATA] != ELFDATA2LSB || ehdr->e_ident[EI_VERSION] != EV_CURRENT || ehdr->e_ident[EI_ABIVERSION] != 0 || ehdr->e_machine != EM_386 || - ehdr->e_type != ET_EXEC || ehdr->e_version != EV_CURRENT) { + ehdr->e_version != EV_CURRENT) { ret = -ENOEXEC; goto fail_exe; } @@ -227,6 +225,14 @@ static int execve(const char* pathname, struct string_vec* argv, ret = -ENOEXEC; goto fail_exe; } + switch (ehdr->e_type) { + case ET_EXEC: + case ET_DYN: + break; + default: + ret = -ENOEXEC; + goto fail_exe; + } struct vm* prev_vm = current->vm;