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

Segfault due to unchecked return value #1107

Closed
smithzvk opened this issue Jun 13, 2019 · 2 comments · Fixed by #1378
Closed

Segfault due to unchecked return value #1107

smithzvk opened this issue Jun 13, 2019 · 2 comments · Fixed by #1378

Comments

@smithzvk
Copy link

closure = ffi_closure_alloc(sizeof(ffi_closure), &code);

I think I traced a segfault to this line. The return type stored in closure can be NULL on allocation failure. ffi_prep_closure_loc assumes that the value is valid, so passing NULL will produce a seg fault.

This happens on locked down systems with restricted execution and write permissions. The libffi closure API requires either trivially executable heap allocations or a location to mmap with both read-write and exec permissions. If it doesn't have this (e.g. selinux with no rw, exec mounts), it will fail to allocate the closure structure.

Perhaps this could fail more gracefully?

@twall
Copy link
Contributor

twall commented Jun 13, 2019 via email

@smithzvk
Copy link
Author

I'll take a look as time permits. I don't think I can get my company to sponsor this work, unfortunately, so it may take a while for the free time to surface.

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 a pull request may close this issue.

2 participants