Skip to content

[3.13] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864) (GH-150189)#150194

Open
miss-islington wants to merge 1 commit into
python:3.13from
miss-islington:backport-c863e96-3.13
Open

[3.13] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864) (GH-150189)#150194
miss-islington wants to merge 1 commit into
python:3.13from
miss-islington:backport-c863e96-3.13

Conversation

@miss-islington
Copy link
Copy Markdown
Contributor

gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864)

Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S.

The BTI flag must be applied in assembler sources for this class
of attacks to be mitigated on newer aarch64 processors.

See also:
https://sourceware.org/annobin/annobin.html/Test-branch-protection.html
and
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64

The 3.14 backport makes Python/jit_unwind.c changes in
Python/perf_jit_trampoline.c.

(cherry picked from commit da8477b)
(cherry picked from commit c863e96)

Co-authored-by: Victor Stinner vstinner@python.org
Co-authored-by: stratakis cstratak@redhat.com

…mpoline.S (pythonGH-130864) (pythonGH-150189)

pythongh-139808: Add branch protections for aarch64 in asm_trampoline.S (pythonGH-130864)

Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S.

The BTI flag must be applied in assembler sources for this class
of attacks to be mitigated on newer aarch64 processors.

See also:
https://sourceware.org/annobin/annobin.html/Test-branch-protection.html
and
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64

The 3.14 backport makes Python/jit_unwind.c changes in
Python/perf_jit_trampoline.c.

(cherry picked from commit da8477b)
(cherry picked from commit c863e96)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: stratakis <cstratak@redhat.com>
@vstinner
Copy link
Copy Markdown
Member

I tested this change on Fedora 43 AArch64 with commands:

./configure --enable-shared CFLAGS="-mbranch-protection=standard -fplugin=annobin -fstack-protector-strong -fstack-clash-protection -D_FORTIFY_SOURCE=3" LDFLAGS="-Wl,-z,now" --with-lto
make -j24
readelf -n ./python | grep Properties

Output:

readelf: Warning: Gap in build notes detected from 0x40087d to 0x400897
      Properties: AArch64 feature: BTI, PAC, GCS

The BTI and PAC protections are present as expected.

@vstinner
Copy link
Copy Markdown
Member

@stratakis: Here is an automated backport to 3.13 of PR gh-150189 fix.

@stratakis
Copy link
Copy Markdown
Contributor

Unfortunately this is a bit trickier here. While I found everything working, except the case with frame pointers and mbranch protection for the dwarf unwinding path. Although quite niche, other issues might be here, I think this should go on 3.13 only if @pablogsal would think that 5535482 is also cherry-pickable for 3.13.

@stratakis
Copy link
Copy Markdown
Contributor

I think cherry-picking the trampoline fixes before this would be the right move, but it's not for me to decide.

@stratakis
Copy link
Copy Markdown
Contributor

Unfortunately this is a bit trickier here. While I found everything working, except the case with frame pointers and mbranch protection for the dwarf unwinding path. Although quite niche, other issues might be here, I think this should go on 3.13 only if @pablogsal would think that 5535482 is also cherry-pickable for 3.13.

Ah wait, this commit IS on 3.13. Then I'm not sure what the issue is here.

@vstinner
Copy link
Copy Markdown
Member

While I found everything working, except the case with frame pointers and mbranch protection for the dwarf unwinding path.

Would you mind to elaborate on the issue? Like explain how to reproduce it?

@stratakis
Copy link
Copy Markdown
Contributor

While I found everything working, except the case with frame pointers and mbranch protection for the dwarf unwinding path.

Would you mind to elaborate on the issue? Like explain how to reproduce it?

Actually everything works, forgot the clear the stale perf /tmp/jitted*.so files from the previous test run so something got messy there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants