-
Notifications
You must be signed in to change notification settings - Fork 59
Should format!("{:p}", ptr)
leak provenance?
#322
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
Comments
format!("{:p}", ptr)
leak provenance?
"leaking provenance" means wildly different things in different context to different people, so I have no idea what you are even asking, or what the "it" is that might be working or not. ;) |
I mean in the exact way that If I do What I'm interested in is whether |
So far I have been considering two kinds of models:
I guess you are saying we could have a variant of (1) where two kinds of ptrtoint casts exist -- those that "broadcast" and those that do not. Sure, we could. However that solves none of the things that make (1) a mess so it doesn't really help I think. |
Although I very much like (2) and agree that it would be a better model, all other things being equal, I worry about the fact that So what I'm wondering is if we can't have (2) for new code, but (1) for old code, even if old code is necessarily pessimised by such. The model in Rust land would roughly be (modulo naming)
The remaining question in such a world is whether existing There's definitely complications I haven't considered, but I'm just ((un)reasonably?) scared of retroactively saying any lib using And of course, whatever model is chosen is predicated on what backends (i.e. LLVM) have support for; if LLVM doesn't have a way for a (Now I guess I should go rewrite ptr-union's alignment tagging to use |
I agree with these concerns, but as long as (1) exists at all, it has all the bad effects I described. The only cap-out I can imagine is to say "the formal spec doesn't cover code on old editions that still uses the deprecated casts; such code is supported on a best-effort basis". That would actually help the formal efforts. But anyway that is wildly off-topic from the original question in this thread.^^ |
I mean, it's a question of if the OP question is moot. And I think we have reasonable consensus (at least between the two of us, and that's enough for me to close the issue) that
So to answer the OP question: No, parsing and then dereferencing the address printed by |
@CAD97 I'm confused by your conclusion. Surely under (1) parsing and then dereferencing the address is not UB, since the pointer was broadcast, since |
Yes, you're correct, it would be defined under (1), I sort of (accidentally) assumed that (1) wasn't the case in the conclusion. (The question is still moot under that model, though, as there's no way for the answer to be different.) |
The case for it working:
I print the address. I then parse the formatted text, and convert the parsed integer into a pointer. I then dereference that constructed pointer. The constructed pointer is "derived from" the original pointer, so it should be valid.
The case for it not working:
Wow that's annoying. Plus, it'd be very nice to be able to implement e.g. tagged pointers in the obvious way, using future provenance-aware APIs, such as
Once we have provenance-aware APIs, it makes sense to allow manipulation of addresses without leaking provenance, as the developer has indicated that they intend to maintain the pointer provenance, not try to reconstruct it from just the address.
But what about all of the
ptr as usize
in the standard library today? How much of it can avoid the ptrtoint, how much can potentially beptr.addr()
in the future, and how much will need to be (the moral equivalent of a)ptr::leak
to maintain compatibility with today's semantics?Printing the address of a pointer is the obvious example of a ptrtoint which does not necessarily lead to a inttoptr. I don't actually know if any other obscure ways to effectively get ptrtoint without writing
ptr as usize
exist in the standard library.The text was updated successfully, but these errors were encountered: