sched: load: add elf_check_compat
This commit is contained in:
parent
a85be6eb62
commit
591fdc5349
1 changed files with 29 additions and 15 deletions
44
sched/load.c
44
sched/load.c
|
|
@ -9,22 +9,9 @@
|
||||||
|
|
||||||
static const char elf_magic[] = { 0x7F, 'E', 'L', 'F' };
|
static const char elf_magic[] = { 0x7F, 'E', 'L', 'F' };
|
||||||
|
|
||||||
pid_t elf_load_proc(const char *proc_path)
|
int elf_check_compat(char *buf)
|
||||||
{
|
{
|
||||||
int fd = open(proc_path, O_RDONLY);
|
if (strncmp(buf, elf_magic, 4))
|
||||||
if (fd < 0)
|
|
||||||
return fd;
|
|
||||||
|
|
||||||
char *buf = kmalloc(4096, ALLOC_KERN);
|
|
||||||
if (!buf)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
int ret = read(fd, buf, 4096);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if(strncmp(buf, elf_magic, 4))
|
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
|
|
||||||
struct elf64_header *hdr = (struct elf64_header *)buf;
|
struct elf64_header *hdr = (struct elf64_header *)buf;
|
||||||
|
|
@ -48,3 +35,30 @@ pid_t elf_load_proc(const char *proc_path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t elf_load_proc(const char *proc_path)
|
||||||
|
{
|
||||||
|
int fd = open(proc_path, O_RDONLY);
|
||||||
|
if (fd < 0)
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
char *buf = kmalloc(4096, ALLOC_KERN);
|
||||||
|
if (!buf)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
int ret = read(fd, buf, 4096);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = elf_check_compat(buf);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
kfree(buf);
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue