Пример #1
0
int64_t
private_check_segments(struct bfelf_file_t *ef)
{
    bfelf64_xword i = 0;

    for (i = 0; i < ef->ehdr->e_phnum; i++)
    {
        struct bfelf_phdr *phdr = private_get_segment(ef, i);

        if (phdr->p_type != bfpt_load)
            continue;

        if (ef->num_loadable_segments >= BFELF_MAX_SEGMENTS)
            return loader_full("increase BFELF_MAX_SEGMENTS");

        if (phdr->p_memsz < phdr->p_filesz)
            return invalid_segment("segment mem size is less then file size");

        if (phdr->p_vaddr != phdr->p_paddr)
            return invalid_segment("expect p_vaddr == p_paddr");

        if (phdr->p_align != 0x1000 && phdr->p_align != 0x200000)
            return invalid_segment("expect 4k or 2M alignment");

        if (phdr->p_offset >= ef->fsize)
            return invalid_segment("segment offset out of bounds");

        ef->loadable_segments[ef->num_loadable_segments] = phdr;
        ef->num_loadable_segments++;
    }

    return BFELF_SUCCESS;
}
Пример #2
0
static bfelf64_sword
private_check_segments(struct bfelf_file_t *ef)
{
    bfelf64_sword i = 0;

    for (i = 0; i < ef->ehdr->e_phnum; i++)
    {
        struct bfelf_phdr *phdr = private_get_segment(ef, i);

        if (phdr->p_type != bfpt_load)
            continue;

        if (ef->num_loadable_segments >= BFELF_MAX_SEGMENTS)
            return loader_full("increase BFELF_MAX_SEGMENTS");

        if (phdr->p_memsz < phdr->p_filesz)
            return invalid_segment("segment mem size is less then file size");

        if (phdr->p_vaddr != phdr->p_paddr)
            return invalid_segment("expect p_vaddr == p_paddr");

        /*
         * At the moment, libc++.so has an alignment of 20, which is really
         * strange. Will need to find out why at some point
         *
         * if (phdr->p_align != 0x1000 && phdr->p_align != 0x200000)
         *     return invalid_segment("expect 4k or 2M alignment");
         */

        if (phdr->p_offset >= ef->fsize)
            return invalid_segment("segment offset out of bounds");

        ef->loadable_segments[ef->num_loadable_segments] = phdr;
        ef->num_loadable_segments++;
    }

    return BFELF_SUCCESS;
}