Skip to content

Fill between executable sections with trap instructions #31575

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

Closed
rui314 opened this issue Mar 10, 2017 · 5 comments
Closed

Fill between executable sections with trap instructions #31575

rui314 opened this issue Mar 10, 2017 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla lld:ELF

Comments

@rui314
Copy link
Member

rui314 commented Mar 10, 2017

Bugzilla Link 32227
Resolution FIXED
Resolved on Apr 07, 2017 05:27
Version unspecified
OS All
CC @emaste,@jh7370

Extended Description

Currently, LLD leaves padding between executable sections as-is, so they are 0. That is not desirable for a few reasons.

  1. Disassemblers would interpret the sequences of 0 bytes at end of each function as machine instructions and print out bogus disassembly.

  2. Leaving executable 0 bytes could potentially make some attack easier.

We want to fill gaps with trap instructions. On x86 and x86-64, that is 0xcc, for example.

@rui314
Copy link
Member Author

rui314 commented Mar 10, 2017

assigned to @jh7370

@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2017

Interesting that gold/bfd implementation is slightly more complicated than just adding some gap bytes.

For example if you have just a nop in a section that is 32 bytes size:
_start
nop

output can be:
080481a0 <_start>:
80481a0: 90 nop
80481a1: e9 1a 00 00 00 jmp 80481c0 <_start+0x20>
80481a6: 90 nop

So they even modify code to insert jump here and skip the nops. I do not know the reason why they do all that, but that was done from initial commit for x64: "From Craig Silverstein: x86_64 support." (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gold/x86_64.cc;hb=2e30d253b71680ea2f09203ad412f0eb7d3f7ff3#l1531).

I think filling with some trap bytes should be enough for start. Since we anyways did not have valid nops here.

@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2017

Patch: D30901

@jh7370
Copy link
Collaborator

jh7370 commented Mar 16, 2017

George and I started working on this independently before I had bugzilla access and my patch ended up for review first, so we are working on that one now instead - D30886.

@jh7370
Copy link
Collaborator

jh7370 commented Apr 7, 2017

Fixed in r299755/D30886.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:ELF
Projects
None yet
Development

No branches or pull requests

3 participants