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 fuzzer target #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

rbran
Copy link
Contributor

@rbran rbran commented Nov 24, 2023

This is the target that I used to find #359 and #363.

Maybe there is something wrong with my setup, but the fuzzer is only able to get a few hundred executions per second.

This implementation is also limited by the fact that some Paths that are bigger then 255 bytes result in panic and not error. So we are limited to fuzzing paths that are 255 bytes or shorter.

I suppose having the Deku assertions being transformed from panics into errors could improve fuzzing in the future, let me know what you think.

Copy link

codecov bot commented Nov 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d8cc6f1) 73.19% compared to head (1a3eee3) 73.07%.
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
- Coverage   73.19%   73.07%   -0.12%     
==========================================
  Files          21       21              
  Lines        2917     2908       -9     
  Branches     2917     2908       -9     
==========================================
- Hits         2135     2125      -10     
  Misses        515      515              
- Partials      267      268       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wcampbell0x2a
Copy link
Owner

Maybe there is something wrong with my setup, but the fuzzer is only able to get a few hundred executions per second.

Even on my somewhat modern computer I get only 630 exec/s.

@wcampbell0x2a
Copy link
Owner

I suppose having the Deku assertions being transformed from panics into errors could improve fuzzing in the future, let me know what you think.

What do you mean by this? Do these exist in backhand, or deku ?

@rbran
Copy link
Contributor Author

rbran commented Dec 2, 2023

Even on my somewhat modern computer I get only 630 exec/s

I tried to find the time sink in the execution with flamegraph, but most of the time it was spent executing "unknowns". Once I have more time available, I'll investigate where is the slow code

What do you mean by this? Do these exist in backhand, or deku ?

Sorry, I meant the deku assertions, like in https://github.com/wcampbell0x2a/backhand/blob/master/backhand/src/dir.rs#L22

They usually result in panic, and not Result::Error, which limits the fuzzer capability to differentiate invalid input and errors on the lib.

I assume this project wants to convert those panics into errors, because the user of the lib may want to continue the execution of the program if he finds a corrupted/invalid file.

@wcampbell0x2a
Copy link
Owner

Sorry, I meant the deku assertions, like in https://github.com/wcampbell0x2a/backhand/blob/master/backhand/src/dir.rs#L22

They usually result in panic, and not Result::Error, which limits the fuzzer capability to differentiate invalid input and errors on the lib.

I assume this project wants to convert those panics into errors, because the user of the lib may want to continue the execution of the program if he finds a corrupted/invalid file.

They shouldn't result in a panic: https://github.com/sharksforarms/deku/blob/d1827d1b4ddf34def616263f0a642de9a58b1653/deku-derive/src/macros/deku_read.rs#L550C11-L550C11

@rbran
Copy link
Contributor Author

rbran commented Dec 2, 2023

They shouldn't result in a panic: https://github.com/sharksforarms/deku/blob/d1827d1b4ddf34def616263f0a642de9a58b1653/deku-derive/src/macros/deku_read.rs#L550C11-L550C11

If you remove the 255 limit from the fuzzer, you get this panic:

thread '<unnamed>' panicked at /home/rbran/src/backhand/backhand/src/inode.rs:49:10:
called `Result::unwrap()` on an `Err` value: Assertion("BasicSymlink.target_size field failed assertion: * target_size < 256")

This is caused by this unwrap resulted from the DekuWrite

@wcampbell0x2a
Copy link
Owner

They shouldn't result in a panic: https://github.com/sharksforarms/deku/blob/d1827d1b4ddf34def616263f0a642de9a58b1653/deku-derive/src/macros/deku_read.rs#L550C11-L550C11

If you remove the 255 limit from the fuzzer, you get this panic:

thread '<unnamed>' panicked at /home/rbran/src/backhand/backhand/src/inode.rs:49:10:
called `Result::unwrap()` on an `Err` value: Assertion("BasicSymlink.target_size field failed assertion: * target_size < 256")

This is caused by this unwrap resulted from the DekuWrite

Oh! Yes that sneaky unwrap shouldn't exist.

@rbran
Copy link
Contributor Author

rbran commented Dec 10, 2023

Yes that sneaky unwrap shouldn't exist

I thought about that, actually this unwrap should exist.

An error should be returned when trying to add a file with path > 255, not when trying to write a valid struct.

This unwrap is an "assert" and should only be reachable if a mistake was made in a previous part of the execution.

@wcampbell0x2a
Copy link
Owner

Yes that sneaky unwrap shouldn't exist

I thought about that, actually this unwrap should exist.

An error should be returned when trying to add a file with path > 255, not when trying to write a valid struct.

This unwrap is an "assert" and should only be reachable if a mistake was made in a previous part of the execution.

I would be of the opinion that is changed to return an Err, as it's library code I would rather return an error than unwrap/panic that users entire program.

@rbran
Copy link
Contributor Author

rbran commented Dec 10, 2023

I would be of the opinion that is changed to return an Err, as it's library code I would rather return an error than unwrap/panic that users entire program.

My point is that only unreachable (or equivalent) panics are allowed. In this case, the filename with more than 255 bytes should not be allowed to be added to the struct in the first place, so the unwrap can never be reached.

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