Skip to content

Conversation

@etcwilde
Copy link
Member

ELF section headers are allowed to be left uninitialized when the section is empty and unused. LLD is a tad more aggressive about this. The ELF reader in the Swift runtime was a bit aggressive about converting the section headers to names and would not skip over these unused sections headers resulting in crashes due to operating on uninitialized memory in the sh_name field.

This patch teaches the ELF reader to skip over unused section header table entries.

(cherry picked from commit 14d2088)

  • Explanation: Fixes a bug where we would read uninitialized data from unused ELF section headers.
  • Scope: Affects ELF-based platforms and ELF file handling in tools like swift-reflection-dump.
  • Risk: Low -- Improves implementation according to the spec. Any data used from this was garbage anyway.
  • Testing: Tested on FreeBSD with LLD, which makes uses of unused section headers. Ensured that runtime and swift-reflection-dump don't crash anymore.
  • Reviewers: @compnerd, @al45tair

Cherry-Pick: #82698

ELF section headers are allowed to be left uninitialized when the
section is empty and unused. LLD is a tad more aggressive about this.
The ELF reader in the Swift runtime was a bit aggressive about
converting the section headers to names and would not skip over these
unused sections headers resulting in crashes due to operating on
uninitialized memory in the `sh_name` field.

This patch teaches the ELF reader to skip over unused section header
table entries.

(cherry picked from commit 14d2088)

 - Explanation: Fixes a bug where we would read uninitialized data from
                unused ELF section headers.
 - Scope: Affects ELF-based platforms and ELF file handling in tools
   like swift-reflection-dump.
 - Risk: Low -- Improves implementation according to the spec.
                Any data used from this was garbage anyway.
 - Testing: Tested on FreeBSD with LLD, which makes uses of unused
            section headers. Ensured that runtime and
            swift-reflection-dump don't crash anymore.
 - Reviewers: @compnerd, @al45tair

Cherry-Pick: swiftlang#82698
@etcwilde etcwilde requested a review from a team as a code owner July 10, 2025 21:50
@etcwilde etcwilde added swift 6.2 🍒 release cherry pick Flag: Release branch cherry picks labels Jul 10, 2025
@etcwilde etcwilde changed the title RemoteInspection: Skip unused ELF section headers [6.2🍒]: RemoteInspection: Skip unused ELF section headers Jul 10, 2025
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Thank you!

@etcwilde
Copy link
Member Author

@swift-ci please test

@etcwilde
Copy link
Member Author

@swift-ci please test Windows

@etcwilde etcwilde merged commit d438c88 into swiftlang:release/6.2 Jul 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍒 release cherry pick Flag: Release branch cherry picks swift 6.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants