Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions with char * arguments #2

Open
GerardGarcia opened this issue Jan 27, 2016 · 2 comments
Open

Functions with char * arguments #2

GerardGarcia opened this issue Jan 27, 2016 · 2 comments

Comments

@GerardGarcia
Copy link

I don't know if that is a limitation of the eBPF instruction set or a limitation of the ubpf virtual machine but seems that is not possible to load programs that use external functions that have arguments type char *. Clang can compile the programs correctly but when loaded the ubp_load_elf functions exits with the error: Fialed to load code: bad relocation type.

If it is not a limitation of the eBPF instruction set I could try to look into it.

@rlane
Copy link
Owner

rlane commented Feb 4, 2016

This should be doable. Right now the ELF loader only loads the text sections but it could do the same for data/rodata/bss.

A simple testcase:

extern int strcmp_ext(const char *a, const char *b);

int entry(int *mem)
{
    return strcmp_ext("abcx", "abcy");
}

produces this assembly:

lddw r1, 0x0
lddw r2, 0x0
call 0x0
exit

and a few relocations:

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE 
0000000000000000 UNKNOWN           .L.str
0000000000000010 UNKNOWN           .L.str.1
0000000000000020 UNKNOWN           strcmp_ext

The relocation type is 1. This could mean "absolute 64-bit".

@GerardGarcia
Copy link
Author

I guess then that the simplest way would be to just keep the loaded strings form the data segment stored somewhere in the vm struct and then reference them into the lddw instructions when relocating. But although this would work, I'm not sure this would be legal eBPF code as the verifier should not allow arbitrary pointers.

iovisor/bcc tools first write the strings into the stack and then the stack address pointing to the string is passed to the external function but this involves generating code and seems that they have modified Clang/LLVM to achieve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants