/[path-sandbox]/trunk/libsandbox/wrapper-funcs/execve.c
Gentoo

Diff of /trunk/libsandbox/wrapper-funcs/execve.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 394 Revision 395
10 10
11#define WRAPPER_ARGS const char *filename, char *const argv[], char *const envp[] 11#define WRAPPER_ARGS const char *filename, char *const argv[], char *const envp[]
12extern int EXTERN_NAME(WRAPPER_ARGS); 12extern int EXTERN_NAME(WRAPPER_ARGS);
13static int (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS) = NULL; 13static int (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS) = NULL;
14 14
15/* See to see if this an ELF and if so, is it static which we can't wrap */
16void check_exec(const char *filename)
17{
18 int color = ((is_env_on(ENV_NOCOLOR)) ? 0 : 1);
19 int fd;
20 unsigned char *elf;
21 struct stat st;
22
23 fd = open(filename, O_RDONLY);
24 if (fd == -1)
25 return;
26 if (stat(filename, &st))
27 goto out_fd;
28 elf = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
29 if (elf == MAP_FAILED)
30 goto out_fd;
31
32 if (elf[EI_MAG0] != ELFMAG0 &&
33 elf[EI_MAG1] != ELFMAG1 &&
34 elf[EI_MAG2] != ELFMAG2 &&
35 elf[EI_MAG3] != ELFMAG3 &&
36 !(elf[EI_CLASS] != ELFCLASS32 ||
37 elf[EI_CLASS] != ELFCLASS64))
38 goto out_mmap;
39
40#define PARSE_ELF(n) \
41({ \
42 Elf##n##_Ehdr *ehdr = (void *)elf; \
43 Elf##n##_Phdr *phdr = (void *)(elf + ehdr->e_phoff); \
44 uint16_t p; \
45 for (p = 0; p < ehdr->e_phnum; ++p) \
46 if (phdr[p].p_type == PT_INTERP) \
47 goto done; \
48})
49 if (elf[EI_CLASS] == ELFCLASS32)
50 PARSE_ELF(32);
51 else
52 PARSE_ELF(64);
53 SB_EWARN(color, "QA: Static ELF", " %s\n", filename);
54 done:
55
56 out_mmap:
57 munmap(elf, st.st_size);
58 out_fd:
59 close(fd);
60}
61
15int WRAPPER_NAME(WRAPPER_ARGS) 62int WRAPPER_NAME(WRAPPER_ARGS)
16{ 63{
17 char **my_env = NULL; 64 char **my_env = NULL;
18 char *entry; 65 char *entry;
19 char *ld_preload = NULL; 66 char *ld_preload = NULL;
22 int result = -1; 69 int result = -1;
23 int count; 70 int count;
24 71
25 if (!FUNCTION_SANDBOX_SAFE(STRING_NAME, filename)) 72 if (!FUNCTION_SANDBOX_SAFE(STRING_NAME, filename))
26 return result; 73 return result;
74
75 check_exec(filename);
27 76
28 str_list_for_each_item(envp, entry, count) { 77 str_list_for_each_item(envp, entry, count) {
29 if (strstr(entry, LD_PRELOAD_EQ) != entry) 78 if (strstr(entry, LD_PRELOAD_EQ) != entry)
30 continue; 79 continue;
31 80

Legend:
Removed from v.394  
changed lines
  Added in v.395

  ViewVC Help
Powered by ViewVC 1.1.20