Repository navigation
rust: time: keep Instant invariant when adding/subtracting Delta - #1273
Open
Franklin-Qi wants to merge 1 commit into
Open
Franklin-Qi wants to merge 1 commit into
Franklin-Qi wants to merge 1 commit into
Conversation
Instant documents inner in 0..=KTIME_MAX, but Add/Sub<Delta> only asserted non-negativity under CONFIG_RUST_OVERFLOW_CHECKS. With checks disabled, a negative result can be returned, and an addition past KTIME_MAX silently wraps. A later Instant-Instant subtraction relies on the invariant and may no longer be overflow-safe. Keep the existing behaviour under CONFIG_RUST_OVERFLOW_CHECKS and panic if the result is out of range. Without overflow checks, saturate the arithmetic and clamp a negative result to 0, printing a warning once, so the invariant is preserved without crashing the kernel. Document the panic and clamping conditions in the operators' rustdoc. Fixes: 22b65a4 ("rust: time: Implement Add<Delta>/Sub<Delta> for Instant") Cc: stable@vger.kernel.org Reported-by: Georgios Androutsopoulos <georgeandrout13@gmail.com> Closes: Rust-for-Linux#1272 Signed-off-by: Franklin-Qi <yusq77@gmail.com>
Franklin-Qi
force-pushed
the
fix/instant-delta-invariant
branch
from
December 2, 2026 08:16
64858e0 to
60c6b49
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instant documents inner in 0..=KTIME_MAX, but Add/Sub only asserted non-negativity under CONFIG_RUST_OVERFLOW_CHECKS. With checks disabled, a negative result can be returned and later Instant-Instant subtraction may no longer be overflow-safe.
Always assert the result is non-negative, and document the panic in the operators' rustdoc.
Fixes: 22b65a4 ("rust: time: Implement Add/Sub for Instant")
Cc: stable@vger.kernel.org
Reported-by: Georgios Androutsopoulos georgeandrout13@gmail.com
Closes: #1272
URL: https://lore.kernel.org/rust-for-linux/179610727734.137620.3884652165779521586@gmail.com/