tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Tests requiring MD hooks



On 11.07.2011 20:13, David Holland wrote:
> How about something like this:
> 
> void testme(void) {
>    char buf[32768];
>    uintptr_t addr = (uintptr_t)&buf;
>    int fd;
> 
>    system("gcc -c victim.c");
>    system("ld -mumble -static -Ttext %lu victim.o -o victim", addr);
> 
>    fd = open("victim");
>    /* read elf headers, get offset and size of text and entrypoint */
>    lseek(fd, text_offset, SEEK_SET);
>    read(fd, buf, text_size);
>    close(fd);
>    mprotect(buf, sizeof(buf), whatever);
>    entrypoint(argc, argv);
> }
> 
> This requires some elf-specific code but not very much, and there
> might be issues with linker scripts, but it should all be fairly
> manageable.
> 
> (victim.o could also be built in advance, it's only the link that matters)

That will work yes, but IMHO this is overkill; it does have the
advantage of avoiding function descriptors games, thanks to ld.

-- 
Jean-Yves Migeon
jeanyves.migeon%free.fr@localhost


Home | Main Index | Thread Index | Old Index