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

Refactor - Restrict callx to registered functions #397

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

Lichtso
Copy link

@Lichtso Lichtso commented Oct 28, 2022

Depends on Config::static_syscalls, because it needs function symbols to be registered by their PC not their hash.

In the interpreter, simply throw EbpfError::UnsupportedInstruction in callx if the lookup_bpf_function of the target_pc fails. In the JIT, mark all instructions which are not a function symbol as ANCHOR_CALLX_UNSUPPORTED_INSTRUCTION in jit.result.pc_section.

Unfortunately, that also means that the host to guest PC translation (ANCHOR_TRANSLATE_PC) used by ANCHOR_MEMORY_ACCESS_VIOLATION won't work anymore and needs to be replaced by an explicit push of the guest / vm PC (resulting in more instructions emitted per memory access, thus longer executables produced by the JIT).

if *offset == call_unsupported_instruction {
*offset = callx_unsupported_instruction;
if self.config.static_syscalls {
let mut prev_pc = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be faster to memset the pc_section slice when we mmap, before we set the valid entries?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During compilation the pc_section is used for relocation of jumps & calls. Only at the end it is steamrolled for the most part to be used at runtime.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh true yeah fair enough

Copy link

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@Lichtso Lichtso merged commit 184499f into main Nov 2, 2022
@Lichtso Lichtso deleted the refactor/restrict_callx_to_registered_functions branch November 2, 2022 07:35
@Lichtso Lichtso mentioned this pull request Nov 2, 2022
18 tasks
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

Successfully merging this pull request may close these issues.

2 participants