Skip to content

RemoteInspection: Skip unused ELF section headers #82698

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

Merged

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Jul 1, 2025

ELF section headers are allowed to be left uninitialized when the section is empty and unused. LLD on FreeBSD 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.

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.
@etcwilde etcwilde requested review from compnerd and al45tair July 1, 2025 21:29
@etcwilde
Copy link
Member Author

etcwilde commented Jul 1, 2025

@swift-ci please test

@etcwilde etcwilde self-assigned this Jul 1, 2025
@etcwilde etcwilde moved this to In Progress in Swift on FreeBSD Jul 1, 2025
@compnerd compnerd changed the title FreeBSD: Skip unused ELF section headers RemoteInspection: Skip unused ELF section headers Jul 1, 2025
@etcwilde
Copy link
Member Author

etcwilde commented Jul 2, 2025

@swift-ci please test Windows

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

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

FWIW, I have the exact same issue in my ELF code in the Runtime module :-D

@etcwilde etcwilde merged commit 576a378 into swiftlang:main Jul 3, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Swift on FreeBSD Jul 3, 2025
etcwilde added a commit to etcwilde/swift that referenced this pull request Jul 10, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants