servers/rs: Add sanity check on executable size

RS used to do a stat, and check that the stat was successful, but it
didn't check that the executable was not actually empty.

This patch adds a check to detect file which are smaller than the minimum
ELF size possible.

Change-Id: I22b004084f17e7d395e2c1377add7bc8b51c3d5e
This commit is contained in:
Lionel Sambuc 2014-07-30 16:10:03 +02:00
parent f1778d4cdd
commit 37f29f557a
2 changed files with 7 additions and 0 deletions

View file

@ -58,6 +58,8 @@ static int elf_ph_sane(Elf_Phdr *phdr)
static int elf_unpack(char *exec_hdr,
int hdr_len, Elf_Ehdr **hdr, Elf_Phdr **phdr)
{
assert(hdr_len >= sizeof(Elf_Ehdr));
*hdr = (Elf_Ehdr *) exec_hdr;
if(!elf_sane(*hdr)) {
return ENOEXEC;

View file

@ -7,6 +7,8 @@
#include <paths.h>
#include <sys/exec_elf.h>
#include "inc.h"
#include "kernel/proc.h"
@ -1272,6 +1274,9 @@ struct rproc *rp;
if (r != 0)
return -errno;
if (sb.st_size < sizeof(Elf_Ehdr))
return ENOEXEC;
fd= open(e_name, O_RDONLY);
if (fd == -1)
return -errno;