Skip to content

Commit

Permalink
exec: accept ELF file type ET_DYN
Browse files Browse the repository at this point in the history
  • Loading branch information
mosmeh committed Nov 8, 2024
1 parent 2f118f2 commit 81b9884
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions kernel/api/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions kernel/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ static int execve(const char* pathname, struct string_vec* argv,
struct file* file = NULL;

struct kstat stat;
mutex_lock(&current->fs->lock);
ret = vfs_stat_at(current->fs->cwd, pathname, &stat, 0);
mutex_unlock(&current->fs->lock);
ret = vfs_stat(pathname, &stat, 0);
if (IS_ERR(ret))
goto fail_exe;
if (!S_ISREG(stat.st_mode)) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand Down

0 comments on commit 81b9884

Please sign in to comment.