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

elf: handle some invalid sizes #121

Merged
merged 2 commits into from
Mar 9, 2019
Merged

elf: handle some invalid sizes #121

merged 2 commits into from
Mar 9, 2019

Conversation

philipc
Copy link
Collaborator

@philipc philipc commented Mar 7, 2019

This fixes all the errors that I could reproduce from #120.

TODO:

  • validate all other Vec::with_capacity
  • validate all other arithmetic for overflows

@@ -466,6 +472,7 @@ macro_rules! elf_dyn_std_impl {
pub fn from_fd(mut fd: &File, phdrs: &[$phdr]) -> Result<Option<Vec<Dyn>>> {
for phdr in phdrs {
if phdr.p_type == PT_DYNAMIC {
// FIXME: validate filesz before allocating
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know how to validate this. Probably we could do fd.take(filesz).read_to_end() (and then check the correct length was read?), but then need to convert that Vec[u8] into a Vec[Dyn].

Copy link
Owner

Choose a reason for hiding this comment

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

I think this method is only used by things that load off disk like a dynamic linker so it shouldn’t be on the parser code path; however yes we should do something here but I wouldn’t worry about it for now

Copy link
Owner

@m4b m4b left a comment

Choose a reason for hiding this comment

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

This is great thanks for taking this up @philipc !

let size = count * Sym::size_with(&ctx);
let size = count
.checked_mul(Sym::size_with(&ctx))
.ok_or(::error::Error::Malformed(format!("Too many ELF symbols (offset {:#x}, count {})",
Copy link
Owner

Choose a reason for hiding this comment

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

Are we 2018 in this crate ? We should update soon if not

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, so rust 2018 + rustfmt?

Copy link
Owner

Choose a reason for hiding this comment

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

the only thing is we’ve had a really great story for supporting older compilers so I’d like to see what the Linux distros are shipping at the moment. If we can target a minimum rustc/ cargo combination which does 2018 that would be ideal. Need to investigate.

@@ -466,6 +472,7 @@ macro_rules! elf_dyn_std_impl {
pub fn from_fd(mut fd: &File, phdrs: &[$phdr]) -> Result<Option<Vec<Dyn>>> {
for phdr in phdrs {
if phdr.p_type == PT_DYNAMIC {
// FIXME: validate filesz before allocating
Copy link
Owner

Choose a reason for hiding this comment

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

I think this method is only used by things that load off disk like a dynamic linker so it shouldn’t be on the parser code path; however yes we should do something here but I wouldn’t worry about it for now

@m4b
Copy link
Owner

m4b commented Mar 8, 2019

I’ll let you push the merge button since it feels good :)

@philipc philipc merged commit d0ce0ad into m4b:master Mar 9, 2019
@philipc philipc deleted the issue-120 branch March 9, 2019 01:39
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