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

Add memfd shmem backend #2647

Merged
merged 1 commit into from
Nov 6, 2024
Merged

Add memfd shmem backend #2647

merged 1 commit into from
Nov 6, 2024

Conversation

bernhl
Copy link
Contributor

@bernhl bernhl commented Oct 31, 2024

memfd backed shmprovider. Tested on android with ForkserverExecutor but should be usable on other Linux flavors. Minor caveat: Android 7 and older as well as old linux kernel (AFAICT < 3.17) are unsupported.

@bernhl
Copy link
Contributor Author

bernhl commented Oct 31, 2024

The advantage of using memfd over default POSIX shared memory is automatic cleanup when killing fuzzer instances. This prevents the accumulation of leftover shm files. On android, memfd is the designated successor to ashmem and attempts have been made (but reverted) to remove ashmem. Still, supporting on the successor future-proofs libafl.

libafl_bolts/src/shmem.rs Outdated Show resolved Hide resolved
@domenukk
Copy link
Member

domenukk commented Nov 1, 2024

Should we switch the default Android to be Memfd?

@bernhl
Copy link
Contributor Author

bernhl commented Nov 1, 2024

I would refrain from switching to memfd on android, because the afl-compiler-rt.o.c is not yet compatible.

@bernhl
Copy link
Contributor Author

bernhl commented Nov 1, 2024

Alternatively, memfd could be made default on android but forkserver examples use ashmem instead.

@domenukk
Copy link
Member

domenukk commented Nov 1, 2024

Alternatively, memfd could be made default on android but forkserver examples use ashmem instead.

That's already the case; In many cases Forkserver uses UnixShMemProvider on MacOS etc

let shmem_provider = UnixShMemProvider::new().expect("Failed to init shared memory");

(not sure if this even works on Android? :D )

libafl_bolts/src/shmem.rs Outdated Show resolved Hide resolved
@domenukk
Copy link
Member

domenukk commented Nov 5, 2024

We'll release 0.14 soon, anything left to do here?

@bernhl
Copy link
Contributor Author

bernhl commented Nov 5, 2024

I converted this to a draft because there seems to be an issue with memfd based on nix (instead of syscall from libc). I'll investigate later today.

@domenukk
Copy link
Member

domenukk commented Nov 5, 2024

Else we can also go with the syscall method for now if nyx is acting up :)

@bernhl bernhl force-pushed the main branch 3 times, most recently from b1c4643 to af8fcc0 Compare November 5, 2024 15:44
@bernhl bernhl marked this pull request as ready for review November 5, 2024 15:44
@bernhl
Copy link
Contributor Author

bernhl commented Nov 5, 2024

Actually, using nix instead of syscall works if one understands the difference between as_raw_fd and into_raw_fd...

libafl_bolts/src/shmem.rs Outdated Show resolved Hide resolved
libafl_bolts/src/shmem.rs Outdated Show resolved Hide resolved
libafl_bolts/src/shmem.rs Outdated Show resolved Hide resolved
@domenukk
Copy link
Member

domenukk commented Nov 6, 2024

Merging, but we may want to
a) have a testcase or example fuzzer for this
b) maybe make this the default at some point

@domenukk domenukk merged commit cfe1240 into AFLplusplus:main Nov 6, 2024
100 checks passed
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