5

CFI: Support function pointers for trait methods by maurer · Pull Request #12305...

 2 weeks ago
source link: https://github.com/rust-lang/rust/pull/123052
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

CFI: Support function pointers for trait methods #123052

Conversation

Contributor

Adds support for both CFI and KCFI for function pointers to trait methods by attaching both concrete and abstract types to functions.

KCFI does this through generation of a ReifyShim on any function pointer for a method that could go into a vtable, and keeping this separate from ReifyShims that are intended for vtable us by setting a ReifyReason on them.

CFI does this by setting both the concrete and abstract type on every instance.

This should land after #123024 or a similar PR, as it diverges the implementation of CFI vs KCFI.

r? @compiler-errors

rustbot

added A-testsuite Area: The testsuite used to check the correctness of rustc PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Mar 25, 2024

Collaborator

These commits modify compiler targets.
(See the Target Tier Policy.)

Some changes occurred in compiler/rustc_symbol_mangling/src/typeid

cc @rust-lang/project-exploit-mitigations, @rcvalle

Some changes occurred in tests/ui/sanitizer

cc @rust-lang/project-exploit-mitigations, @rcvalle

Some changes occurred in src/tools/compiletest

cc @jieyouxu

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

since this touches regular codegen by adding a ReifyReason,

@bors try @rust-timer queue

This comment has been minimized.

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

Mar 25, 2024

Contributor

⌛ Trying commit f64da91 with merge b04e6b6...

Collaborator

Some changes occurred in tests/codegen/sanitizer

cc @rust-lang/project-exploit-mitigations, @rcvalle

Contributor

☔ The latest upstream changes (presumably #123065) made this pull request unmergeable. Please resolve the merge conflicts.

Contributor

☔ The latest upstream changes (presumably #123071) made this pull request unmergeable. Please resolve the merge conflicts.

I really don't expect perf to come back with anything other than neutral here, but --

@bors try @rust-timer queue

This comment has been minimized.

Contributor

⌛ Trying commit 4775daf with merge 0f5b741...

Contributor

☀️ Try build successful - checks-actions
Build commit: 0f5b741 (0f5b7417e5e3759e1863051a83d15a28103a0e3f)

This comment has been minimized.

Collaborator

Finished benchmarking commit (0f5b741): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

Cycles

Results

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 667.526s -> 668.303s (0.12%)
Artifact size: 315.67 MiB -> 315.68 MiB (0.00%)

@@ -147,7 +147,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {

for options in [

TypeIdOptions::GENERALIZE_POINTERS,

TypeIdOptions::NORMALIZE_INTEGERS,

TypeIdOptions::NO_SELF_TYPE_ERASURE,

TypeIdOptions::ERASE_SELF_TYPE,

I don't know, I kinda disagree with the change to the NO_SELF_TYPE_ERASURE. I think the default should be what is going to be done most of the time or more commonly, and it's performing type erasure. The exception for the secondary type id should be opted in when needed.

Contributor

Author

I don't have a strong preference - I like this version a little better due to the "positive" nature of it.

With regards to defaults vs secondary, only KCFI has a meaningful notion of a "default" type ID - CFI attaches all of them to the same attachment site, so none of them are really primary or secondary. KCFI still sets ERASE_SELF_TYPE as its default with this changeset.

That said, if this change is contentious and not required by compiler-errors to land this PR, I don't really care to fight over this.

It's secondary because these are not always included. They're only included when they're unique and for methods, and also are only tested for when methods are used as function pointers so the concept of secondary does apply generally.

// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEEE"}

// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type1EE"}

// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type1EE"}

// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEEE"}

As a result of what I mentioned above, it seems the type id order also changed here.

Contributor

Author

Yes. I'm not sure why the type order changing is an issue if we only have one test that checks it.

The tests aren't an issue now. My disagreement is with the less common case (i.e., not performing self type erasure/the secondary type id) being the default behavior and also the first type id.

Contributor

Author

@rustbot ready

rustbot

added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Apr 2, 2024

Contributor

📌 Commit 473a70d has been approved by compiler-errors

It is now in the queue for this repository.

bors

added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

labels

Apr 3, 2024

Contributor

⌛ Testing commit 473a70d with merge 0194081...

Contributor

💔 Test failed - checks-actions

bors

added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

labels

Apr 3, 2024

Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

bors

added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

labels

Apr 4, 2024

Contributor

⌛ Testing commit 473a70d with merge 29fe618...

Contributor

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 29fe618 to master...

bors

added the merged-by-bors This PR was explicitly merged by bors. label

Apr 4, 2024

bors

merged commit 29fe618 into

rust-lang:master

Apr 4, 2024

12 checks passed

rustbot

added this to the 1.79.0 milestone

Apr 4, 2024

Collaborator

Finished benchmarking commit (29fe618): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 667.94s -> 669.353s (0.21%)
Artifact size: 318.08 MiB -> 318.07 MiB (-0.00%)

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

Reviewers

rcvalle

rcvalle left review comments

compiler-errors

compiler-errors approved these changes
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects

None yet

Milestone

1.79.0

Development

Successfully merging this pull request may close these issues.

None yet

7 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK