Distinguish null reference production from null pointer dereference in UB checks#158796
Conversation
|
This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras
cc @bjorn3 Some changes occurred to the CTFE machinery |
|
|
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
| //@ run-crash | ||
| //@ compile-flags: -C debug-assertions | ||
| //@ error-pattern: null pointer dereference occurred | ||
| //@ error-pattern: null reference formed |
There was a problem hiding this comment.
"formed" is not a verb we use for this anywhere else I think. The reference calls it "producing" an invalid value, maybe use that?
There was a problem hiding this comment.
thanks! i'll update the message to use produced to exact match the terminology.
Introduce a dedicated panic for null reference production to distinguish producing a reference from a null pointer from an actual null pointer dereference. This emits a dedicated panic message for null reference production while preserving the existing panic for actual dereferences.
|
r? saethlin |
Rollup of 13 pull requests Successful merges: - #158478 (Use correct typing mode in mir building for the next solver) - #158796 (Distinguish null reference production from null pointer dereference in UB checks) - #158821 (add regression test for late-bound type method probe ICE) - #158245 (Update the rustc_perf submodule) - #158346 (Prevent rustdoc auto-trait ICEs with `-Znext-solver=globally`) - #158536 (Instatiate binder instead of skipping when suggesting function arg error) - #158553 (Avoid infinite recursion when trying to build valtrees for self-referential consts) - #158679 (Document blocking guarantees for `std::sync`) - #158826 (Reorganize `tests/ui/issues` [19/N]) - #158860 (Delete `impl_def_id` field from `ImplHeader`) - #158867 (rewrite `Align::max_for_target` in a more obvious way) - #158878 (borrowck: Inline `free_region_constraint_info()` to simplify the code) - #158881 (Update mdbook to 0.5.4)
Rollup merge of #158796 - raushan728:issues/154044, r=saethlin Distinguish null reference production from null pointer dereference in UB checks Closes #154044 This change distinguishes null reference production from actual null pointer dereferences in the UB checks. Producing a reference from a null pointer (for example, `&*ptr`) is undefined behavior even if no memory is dereferenced. This change introduces a dedicated `AssertKind::NullReferenceConstructed` and runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences. Summary - Add `AssertKind::NullReferenceConstructed`. - Emit it for null reference production in the MIR null check pass. - Add `panic_null_reference_constructed` and its lang item. - Keep `NullPointerDereference` for actual dereferences. - Update the affected UI tests.
Starting with Rust 1.99.0 (expected 2026-10-01), under
`CONFIG_RUST_DEBUG_ASSERTIONS=y`, `objtool` may report:
rust/kernel.o: warning: objtool: _R..._6kernel12module_param9set_paramaEB4_()
falls through to next function _R..._6kernel12module_param9set_paramhEB4_()
(and many others) due to calls to the `noreturn` symbol [1]:
core::panicking::panic_null_reference_constructed
Thus add the mangled one to the list so that `objtool` knows it is
actually `noreturn`.
See commit 56d680d ("objtool/rust: list `noreturn` Rust functions")
for more details.
Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Pavlu <petr.pavlu@suse.com>
Link: rust-lang/rust#158796 [1]
Reported-by: Alice Ryhl <aliceryhl@google.com>
Closes: https://lore.kernel.org/rust-for-linux/alEBInX9gD1M5NAr@google.com/
Link: https://patch.msgid.link/20260710173252.191781-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Starting with Rust 1.99.0 (expected 2026-10-01), under
`CONFIG_RUST_DEBUG_ASSERTIONS=y`, `objtool` may report:
rust/kernel.o: warning: objtool: _R..._6kernel12module_param9set_paramaEB4_()
falls through to next function _R..._6kernel12module_param9set_paramhEB4_()
(and many others) due to calls to the `noreturn` symbol [1]:
core::panicking::panic_null_reference_constructed
Thus add the mangled one to the list so that `objtool` knows it is
actually `noreturn`.
See commit 56d680d ("objtool/rust: list `noreturn` Rust functions")
for more details.
Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Pavlu <petr.pavlu@suse.com>
Link: rust-lang/rust#158796 [1]
Reported-by: Alice Ryhl <aliceryhl@google.com>
Closes: https://lore.kernel.org/rust-for-linux/alEBInX9gD1M5NAr@google.com/
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260710173252.191781-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Rollup of 13 pull requests Successful merges: - rust-lang/rust#158478 (Use correct typing mode in mir building for the next solver) - rust-lang/rust#158796 (Distinguish null reference production from null pointer dereference in UB checks) - rust-lang/rust#158821 (add regression test for late-bound type method probe ICE) - rust-lang/rust#158245 (Update the rustc_perf submodule) - rust-lang/rust#158346 (Prevent rustdoc auto-trait ICEs with `-Znext-solver=globally`) - rust-lang/rust#158536 (Instatiate binder instead of skipping when suggesting function arg error) - rust-lang/rust#158553 (Avoid infinite recursion when trying to build valtrees for self-referential consts) - rust-lang/rust#158679 (Document blocking guarantees for `std::sync`) - rust-lang/rust#158826 (Reorganize `tests/ui/issues` [19/N]) - rust-lang/rust#158860 (Delete `impl_def_id` field from `ImplHeader`) - rust-lang/rust#158867 (rewrite `Align::max_for_target` in a more obvious way) - rust-lang/rust#158878 (borrowck: Inline `free_region_constraint_info()` to simplify the code) - rust-lang/rust#158881 (Update mdbook to 0.5.4)
Closes #154044
This change distinguishes null reference production from actual null pointer dereferences in the UB checks.
Producing a reference from a null pointer (for example,
&*ptr) is undefined behavior even if no memory is dereferenced. This change introduces a dedicatedAssertKind::NullReferenceConstructedand runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences.Summary
AssertKind::NullReferenceConstructed.panic_null_reference_constructedand its lang item.NullPointerDereferencefor actual dereferences.