-
Notifications
You must be signed in to change notification settings - Fork 13.3k
KCFI: Add KCFI arity indicator support #138368
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
Conversation
9df55b1
to
3cf7741
Compare
Thanks Ramon for the very quick PR! I think the matching LLVM PR is llvm/llvm-project#121070, not the other one, right? Also, would it make sense to add a quick check for the instructions generated, so that we are sure LLVM is actually doing something? e.g. one of the ones from https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/X86/kcfi-arity.ll |
This comment has been minimized.
This comment has been minimized.
e84b08f
to
60df964
Compare
Thanks for pointing that out! Sorry, I confused them. Fixed.
For module flags, we usually add tests up to to verifying that flags are added only because the side effects of adding them are not implemented in the Rust compiler (so we don't need to keep track of changes and update tests when changes are made in LLVM). Would that be okay for you? |
Do we want to add a check when this flag is set that the LLVM is new enough? I think LLVM will silently ignore unknown module tags, so as is, this could result in someone setting |
This comment has been minimized.
This comment has been minimized.
Up to the Rust compiler team, of course -- I am not sure what their policy is. In any case, to be clear, I only meant it as a smoke test, rather than testing everything that LLVM does. In other words, just to be sure that LLVM actually did something with the module flag, rather than replicating every test in LLVM. From a quick test, it seems LLVM (well, at least So what I thought is to check e.g. that we get, say, a |
r? @davidtwco |
60df964
to
8747e2b
Compare
Yes, I think it's a good idea. Done. It seems it's the first time such a check is added for an LLVM-related option so I hope I did it right. P.S. the implementation chosen for the KCFI arity indicator was to use different registers in the mov instruction as the arity indicator instead of augmenting the KCFI tag with this information. This is entirely implemented in LLVM and visible only in the target architecture assembly (and that is why it's tricky and probably not the right place to test it in the Rust compiler tests). |
For non module flags, we test option's side effects (which are actually implemented in the Rust compiler, such as CFI/KCFI checks) in the LLVM assembly, not the target architecture assembly, and since the implementation for the KCFI arity indicator uses different registers in a mov operation in the target architecture assembly as the arity indicator, we'd have to go even further out from what we usually do module flags (which is just test that the module flag was emitted and emitted correctly, see #129373 as an example), and test the target architecture assembly after the KCFI pass is applied and the target architecture assembly is emitted. I'll see if there is a good way to do a smoke test for this, but I still think this a contract and that it's LLVM's responsibility to test the actual side effects of the module flag-- we'd still caught with out test if we didn't pass or if there was a typo in the module flag. |
8747e2b
to
48f34d6
Compare
This comment has been minimized.
This comment has been minimized.
Hmm... I am not sure what you mean. Perhaps there is a different policy for LLVM module flags vs. other things like LLVM attributes, but the Rust compiler has assembly tests in For instance, when I added Not doing anything is not the end of the world, but it means it is fairly easy for LLVM to e.g. rename the module flags and we wouldn't notice until someone builds the kernel with that compiler and KCFI etc. enabled, as far as I understand, and then it is a mess on the kernel side to add Kconfigs to workaround it. If adding the test is complex, then sure, we can avoid it. But I don't understand what the issue is adding it. I may be missing a policy thing here, but if it is just the technical side, what is the issue? In fact, for similar reasons, I would suggest adding one to the feature the PR you linked adds. |
48f34d6
to
6b367e7
Compare
This comment has been minimized.
This comment has been minimized.
At least that is my understanding (i.e., to not duplicate LLVM tests and perform tests in LLVM assembly as much as possible). (Notice there are no sanitizer tests in there.)
Adding it is not the end the world either--I'll just add it :) (But if LLVM starts to arbitrarily changing module flags and like this, I'd argue we'd have much more serious problems.)
Since I'll create the |
6b367e7
to
2989ece
Compare
// KCFI arity requires LLVM 20.1.0 or later. | ||
if llvm_version < (20, 1, 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the case -- there is no tag yet in upstream LLVM that contains the feature, sadly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with the LLVM version check fixed as per #138368 (comment)
2135678
to
bb57c4b
Compare
This comment has been minimized.
This comment has been minimized.
bb57c4b
to
398bcd3
Compare
This comment has been minimized.
This comment has been minimized.
398bcd3
to
9cfb3f1
Compare
This comment has been minimized.
This comment has been minimized.
9cfb3f1
to
80c73a9
Compare
This comment has been minimized.
This comment has been minimized.
80c73a9
to
b2dccb8
Compare
This comment has been minimized.
This comment has been minimized.
1acda5b
to
e440a5b
Compare
This comment has been minimized.
This comment has been minimized.
Adds KCFI arity indicator support to the Rust compiler (see rust-lang#138311, llvm/llvm-project#121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
@bors r=davidtwco |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#138368 (KCFI: Add KCFI arity indicator support) - rust-lang#138381 (Implement `SliceIndex` for `ByteStr`) - rust-lang#139092 (Move `fd` into `std::sys`) - rust-lang#139398 (Change notifications for Exploit Mitigations PG) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#138368 - rcvalle:rust-kcfi-arity, r=davidtwco KCFI: Add KCFI arity indicator support Adds KCFI arity indicator support to the Rust compiler (see rust-lang#138311, llvm/llvm-project#121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
Adds KCFI arity indicator support to the Rust compiler (see #138311, llvm/llvm-project#121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).