-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Abort instead of unwinding past FFI functions #52652
Comments
This comment has been minimized.
This comment has been minimized.
cc @diwic I think @SimonSapin your description is accurate. The backport to stable and backport to beta were both minor patches, and the main one to nightly (at the time) was #48380 as you mentioned. AFAIK we should be good to go again to do this. |
I think I would prefer that instead of immediately landing a change to the default unwind behavior we just stabilize the |
Why is this attribute useful? If the issue that affected rlua is fixed, what can make the answer to "do you want to protect against some potential UB" be anything other than "yes, obviously"? |
There are cases where unwinding is fine, for example if you are using a extern "C" function to talk between different Rust crates or extern "Rust" functions to do the same. There are cases where you legitimately are fine with unwinding (and IMO it shouldn't be UB). I don't think the decision whether unwinding should abort or continue should be based on the extern-ness of the function. |
Good to see some movement here. For me it's bikeshedding whether we go with |
Alright, stabilizing some attribute (perhaps with |
The primary point we reverted back then was because of breakage due to changing the default. I'm not convinced that the breakage would not happen again; there's currently no way to explicitly document your requirements on stable. I see this as the same situation as we normally have for library features, where the unstable/deprecated solution isn't removed until the stable alternative lands in stable. I also am unclear why we would/should rush this. People have waited, people can continue to wait. Stabilizing |
I'm not sure what this means, but if -Cpanic=abort is specified I don't think you should be able to override that with a
Well, why should fixing I-unsound bugs have high priority in general? I think they should have high priority, but not everyone shares that sentiment.
Are there some unresolved questions here w r t:
|
I mean the reverse; if you've specified
This isn't an unsoundness bug though. It is currently UB to unwind through stack frames not generated by the same Rust compiler (and will always be, at least in the short term) but I don't see how that is unsound. I've removed that tag.
I'd be happy stabilizing |
It is indeed not rustc or std that is unsound, but the current situation is that it is very difficult to write sound FFI code. You need to carefully audit every callback either to convince yourself that it cannot ever panic, or use So I’d say this is a soundness-related issue. |
I don't disagree; writing sound FFI code is hard. I'm just trying to say that changing the default without providing a way to use the old behavior seems wrong and I'm against doing it. Furthermore, I'd prefer at least one cycle that users can explicitly opt-in to |
Oh yes it is. Please don't remove
|
Okay. I don't think there is much need. Maybe it would make the crate take_mut use a fewer less characters.
I see unwinding as part of the ABI, but it's possible (I'm not sure) that for all practical purposes one can see it as an orthogonal feature.
Indeed. I even found such a mistake in std once. And just to clarify, this is the practical reason why were doing the "abort" solution rather than just stop marking C ABI functions as |
@diwic I would classify a "soundness bug" as a case where "safe Rust" can generate UB. Are you saying that this is the case here? (I'm legitimately unsure) |
But in any case I think that @Mark-Simulacrum's suggestion of "do not deprecate without at least offering some way to get back the old default" makes sense to me. I think I share these sentiments pretty much exactly:
|
Yes, this is UB as of current Rust:
Here's the LLVM IR (notice the
|
Until rust-lang/rust#52652 is fixed, unwinding on panic is potentially unsound in a mixed C/Rust codebase. The codebase is supposed to be panic-free already, but just to be safe. This started mattering at commit d1820c1. Fixes #27199; bugfix on tor-0.3.3.1-alpha.
Until rust-lang/rust#52652 is fixed, unwinding on panic is potentially unsound in a mixed C/Rust codebase. The codebase is supposed to be panic-free already, but just to be safe. This started mattering at commit d1820c1. Fixes #27199; bugfix on tor-0.3.3.1-alpha.
I've opened a PR for this at #55982 which does the "easy thing" of basically flipping the defaults. I personally disagree that we need to take any further action at this time. We've got a long history of a "stable default" in Rust where the opt-out is unstable (allocators are the first that come to mind). Eventually the opt-out is stabilized in its own right, but for now we have an unstable control (the Additionally I don't think this can really bake without actually testing, this will remain virtually undetected unless everyone opts-in to testing it, so the only real way to get testing is to actually flip the defaults and see what happens. That's what we did last time and it's easy to always flip the defaults back if something comes up! |
Ok, so that's also implemented as part of that PR? Then I don't think anything else is needed here. Right now in stable it's still UB to unwind across I didn't notice anything in the PR description or the commit messages that suggested that it adds something to ensure that it always aborts, that's why I was asking. |
Yes. This is controlled by this function. |
Thanks for the confirmation, that's great news. I'm waiting for that to come back for years now :) |
Me too. :) |
Is it possible to now write somewhere "official" that unwinding across |
The abort behavior is currently only enabled with |
(I'm assigning @BatmanAoD as owner of this issue, in accordance with T-compiler's shift towards a policy where all P-high/P-critical issues are either tagged with a WG-* label or have an explicit owner who can be contacted for status updates.) @rustbot assign @BatmanAoD |
This attribute is gone now, as far as I can see. |
OTOH, the behavior without any feature gates is still unsound AFAIK, so there should be some I-unsound issue open to track that. |
I think it makes sense to leave this open until `c-unwind` and its
associated changes are stabilized.
…On Sun, Jul 3, 2022, 2:26 PM Ralf Jung ***@***.***> wrote:
OTOH, the behavior without any feature gates is still unsound AFAIK, so
there should be *some* I-unsound issue open to track that.
—
Reply to this email directly, view it on GitHub
<#52652 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARU4TYKDSNTIXDCV3GRONDVSHZNZANCNFSM4FLO2JOQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Since #116088 has merged, can this issue be closed? |
Yes indeed :) |
The description of #116088 is not super clear: does it also change Taking a step back: what is the guidance now for writing correct FFI code with callbacks? Where is that / should that be documented? |
Yes.
If you write So if Rust code passes callbacks to a C library,
Not sure, probably somewhere in the reference? |
Reference PR: rust-lang/reference#1226 |
More updated description (2021-03-11)
With #76570 having landed, Rust now aborts when a panic leaves an
extern "C"
function, so the original soundness issue is fixed. However, there is an attribute to opt-out of this behavior,#[unwind(allowed)]
. Using this attribute is currently unsound, so it should be fixed, removed, or require some form ofunsafe
.Updated Description
This is a tracking issue for switching the compiler to abort the program whenever a Rust program panics across an FFI boundary, notably causing any non-Rust-ABI function to panic/unwind.
This is being implemented in #55982 and some regressions were found in the wild so this is also being repurposed as a tracking issue for any breakage that comes up and a place to discuss the breakage. If you're a crate author and you find your way here, don't hesitate to ask questions!
Original Description
Doing Rust unwinding into non-Rust stack frames is undefined behavior. This was fixed in 1.24.0, and then reverted (I think by #48380 ?) in 1.24.1 because of a regression that affected rlua.
The latter blog post said:
The link PR has landed, but my understanding is that it does not change FFI functions back to aborting on unwind (though it looks like it does fix the issue that affected rlua).
This UB is not mentioned in any later release notes.
This issue has been assigned to @BatmanAoD via this comment.
The text was updated successfully, but these errors were encountered: