-
Notifications
You must be signed in to change notification settings - Fork 120
sysctl-register fixes #46
Conversation
`pointer::add` and `pointer::offset` turn into a `getelementptr inbounds`, which is UB if it does not point to a valid object or one past a valid object (i.e., it enables compiler optimizations that make that assumption). Raw pointers to userspace are not pointers to valid objects. `pointer::wrapping_add` and `pointer::wrapping_offset` turn into a `getelementptr`, which is always defined (and so they're both safe).
|
So, my perspective was that |
|
That's not the only thing that makes it unsafe. From https://llvm.org/docs/GetElementPtr.html#what-happens-if-an-array-index-is-out-of-bounds :
(The names are misleading and perhaps the docs are misleading too?) |
|
Would this ever construct a ptr not within the bounds? |
|
What the hell do bounds even mean when we're talking about a ptr to userspace memory? |
|
I believe userspace pointers always count as out of bounds from the perspective of our kernel code. It isn't an object that's been created by our code, we can't dereference it normally, aliasing rules don't apply to it, etc. (Honestly I'd prefer if we just kept it a To be fair, I don't really know what a compiler might want to do with this information, and I'm not sure how this is different from, say, getting a pointer out of |
|
I had the same question over at nix-rust/nix#568 (comment) when implementing safe wrappers for |
One UB fix, one pile of comments, one cleanup