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

Offset checking #11

Closed
pinkforest opened this issue Nov 1, 2022 · 12 comments
Closed

Offset checking #11

pinkforest opened this issue Nov 1, 2022 · 12 comments

Comments

@pinkforest
Copy link

Hi @vincenthouyi Would you mind commenting on the offset checking

rustsec/advisory-db#1450

There was some fuzzing done and has found potential issues

I raised originally in the wrong repo

cole14/rust-elf#23

Thanks!

@vincenthouyi
Copy link
Owner

Hi @pinkforest, what exactly should I do in the thread?
I don't have too much time to update the repo recently. If you are in hurry, you can raise PR and I would review and merge it as soon as possible.

@atulkharerivos
Copy link

@pinkforest @vincenthouyi I can certainly try and raise a PR. Note that I will be traveling internationally for the next few days, so it might be a little delayed.

@pinkforest
Copy link
Author

@atulkharerivos any idea of the upcoming fix if you would have a moment to work on this ? thanks

@atulkharerivos
Copy link

atulkharerivos commented Jan 15, 2023 via email

@vincenthouyi
Copy link
Owner

Hi @pinkforest @atulkharerivos , I just pushed a new version in 3ec9935 to solve crashes I found in fuzz test. Please take a look and tell me if any further crashes you find.

@atulkharerivos
Copy link

atulkharerivos commented Jan 16, 2023 via email

@vincenthouyi
Copy link
Owner

Hi @atulkharerivos, Can you give me your sample or command to reproduce the crashes on invalid ELF headers? I can try to fix them in the future releases as well. Thanks!

@atulkharerivos
Copy link

atulkharerivos commented Jan 17, 2023 via email

@vincenthouyi
Copy link
Owner

vincenthouyi commented Jan 17, 2023

Hi @atulkharerivos, your tests panics because the program asserts reading ELF file always successes as in this line:
let elf = Elf::from_bytes(elf_buf).expect("load elf file failed");
where Elf::from_bytes returns an Err due to reading an invalid ELF magic, ELF class etc. It's the caller's responsibility to handle these errors. A panic is expected when you call expect.
This is the result I run the example readelf program with your inputs:

➜  elf_rs git:(master) ✗ cargo run --example readelf ./tests/data/id\ 000000,sig\ 06,src\ 000000,time\ 120,execs\ 3859,op\ havoc,rep\ 4 
   Compiling elf_rs v0.3.0 (/Users/vincenthou/git_repo/elf_rs)
    Finished dev [unoptimized + debuginfo] target(s) in 1.04s
     Running `target/debug/examples/readelf './tests/data/id 000000,sig 06,src 000000,time 120,execs 3859,op havoc,rep 4'`
failed to extract elf file ./tests/data/id 000000,sig 06,src 000000,time 120,execs 3859,op havoc,rep 4: InvalidMagic
Error: ()
➜  elf_rs git:(master) ✗ cargo run --example readelf ./tests/data/id\ 000001,sig\ 06,src\ 000000,time\ 340,execs\ 10222,op\ havoc,rep\ 8 
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/examples/readelf './tests/data/id 000001,sig 06,src 000000,time 340,execs 10222,op havoc,rep 8'`
failed to extract elf file ./tests/data/id 000001,sig 06,src 000000,time 340,execs 10222,op havoc,rep 8: InvalidClass
Error: ()
➜  elf_rs git:(master) ✗ cargo run --example readelf ./tests/data/id\ 000002,sig\ 06,src\ 000072,time\ 1510,execs\ 43776,op\ havoc,rep\ 16 
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/readelf './tests/data/id 000002,sig 06,src 000072,time 1510,execs 43776,op havoc,rep 16'`
failed to extract elf file ./tests/data/id 000002,sig 06,src 000072,time 1510,execs 43776,op havoc,rep 16: BufferTooShort
Error: ()
➜  elf_rs git:(master) ✗ cargo run --example readelf ./tests/data/id\ 000003,sig\ 06,src\ 000072,time\ 1519,execs\ 44152,op\ havoc,rep\ 16 
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/readelf './tests/data/id 000003,sig 06,src 000072,time 1519,execs 44152,op havoc,rep 16'`
failed to extract elf file ./tests/data/id 000003,sig 06,src 000072,time 1519,execs 44152,op havoc,rep 16: BufferTooShort
Error: ()
➜  elf_rs git:(master) ✗ cargo run --example readelf ./tests/data/id\ 000004,sig\ 06,src\ 000072+000135,time\ 2142,execs\ 68881,op\ splice,rep\ 16 
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/readelf './tests/data/id 000004,sig 06,src 000072+000135,time 2142,execs 68881,op splice,rep 16'`
failed to extract elf file ./tests/data/id 000004,sig 06,src 000072+000135,time 2142,execs 68881,op splice,rep 16: BufferTooShort
Error: ()
➜  elf_rs git:(master) ✗ cargo run --example readelf ./tests/data/id\ 000005,sig\ 06,src\ 000161,time\ 2154,execs\ 69192,op\ havoc,rep\ 4         
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/readelf './tests/data/id 000005,sig 06,src 000161,time 2154,execs 69192,op havoc,rep 4'`
failed to extract elf file ./tests/data/id 000005,sig 06,src 000161,time 2154,execs 69192,op havoc,rep 4: BufferTooShort
Error: ()

jschwe added a commit to jschwe/advisory-db that referenced this issue Jan 17, 2023
The issue was confirmed to be fixed in v0.3.0 by the person who reported the issue:
vincenthouyi/elf_rs#11 (comment)
@atulkharerivos
Copy link

atulkharerivos commented Jan 17, 2023 via email

@atulkharerivos
Copy link

atulkharerivos commented Jan 17, 2023 via email

@vincenthouyi
Copy link
Owner

@atulkharerivos @pinkforest Thank you very much for hardening the quality of the lib!

Closing the issue as fixed.

pinkforest pushed a commit to rustsec/advisory-db that referenced this issue Jan 18, 2023
The issue was confirmed to be fixed in v0.3.0 by the person who reported the issue:
vincenthouyi/elf_rs#11 (comment)
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

3 participants