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

loader: x86_64: elf: Avoid reading beyond file end #125

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

likebreath
Copy link
Contributor

Summary of the PR

The ELF header contains offsets that the loader uses to find other structures. If those offsets are beyond the end of the file (or would go past the end of the file) it is essential to error out when attempting to read those. Using Read::read_exact() permits this.

Signed-off-by: Bo Chen chen.bo@intel.com
Co-authored-by: Rob Bradford robert.bradford@intel.com

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR are signed (with git commit -s), and the commit
    message has max 60 characters for the summary and max 75 characters for each
    description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

The ELF header contains offsets that the loader uses to find other
structures. If those offsets are beyond the end of the file (or would go
past the end of the file) it is essential to error out when attempting to
read those. Using `Read::read_exact()` permits this.

Signed-off-by: Bo Chen <chen.bo@intel.com>
Co-authored-by: Rob Bradford <robert.bradford@intel.com>
@likebreath
Copy link
Contributor Author

/cc @rbradford @sboeuf

@rbradford rbradford merged commit a44f152 into rust-vmm:main Dec 6, 2022
@likebreath likebreath mentioned this pull request Dec 7, 2022
4 tasks
andreeaflorescu added a commit to andreeaflorescu/vm-memory that referenced this pull request Jan 2, 2023
We cannot mark the returned usize as must use unfortunately. This
is what triggered the bug in linux-loader:
rust-vmm/linux-loader#125. The least we can
do is to validate that when there are more bytes requested than what
the reader has available, we do return the correct number of the read.
Unfortunately, when this result is not used it can lead to bugs.

Signed-off-by: Andreea Florescu <fandree@amazon.com>
andreeaflorescu added a commit to andreeaflorescu/vm-memory that referenced this pull request Jan 2, 2023
We cannot mark the returned usize as must use unfortunately. This
is what triggered the bug in linux-loader:
rust-vmm/linux-loader#125. The least we can
do is to validate that when there are more bytes requested than what
the reader has available, we do return the correct number of the read.
Unfortunately, when this result is not used it can lead to bugs.

Signed-off-by: Andreea Florescu <fandree@amazon.com>
andreeaflorescu added a commit to rust-vmm/vm-memory that referenced this pull request Jan 3, 2023
We cannot mark the returned usize as must use unfortunately. This
is what triggered the bug in linux-loader:
rust-vmm/linux-loader#125. The least we can
do is to validate that when there are more bytes requested than what
the reader has available, we do return the correct number of the read.
Unfortunately, when this result is not used it can lead to bugs.

Signed-off-by: Andreea Florescu <fandree@amazon.com>
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.

3 participants