fix(kernel): wrap watch_queue monotonic id counters to avoid overflow#126
Merged
Conversation
create_queue/create_queue_with_capacity/create_group incremented next_queue_id/next_group_id with a plain '+= 1'. The occupancy guards cap only the concurrently-live count (MAX_QUEUES=256 / MAX_GROUPS=64), not the monotonic counter, so over a long-running create/destroy cycle the u32 id reaches u32::MAX and the next increment panics under overflow-checks. Use wrapping_add, matching the next_*_id idiom already used in sysfs_attr.rs and perf_events.rs: the bounded live count makes id reuse after a 2^32 wrap a non-issue in practice. Latent: WatchQueueSubsystem is an exported pub module with no instance, syscall, or dispatch path today.
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.
Summary
create_queue/create_queue_with_capacity/create_groupincrementednext_queue_id/next_group_idwith a plain+= 1. The occupancy guards bound only the concurrently-live count (MAX_QUEUES=256/MAX_GROUPS=64), not the monotonic counter, so over a long-running create/destroy cycle the u32 id reachesu32::MAXand the next increment panics under overflow-checks.Use
wrapping_add, matching thenext_*_ididiom already insysfs_attr.rs/perf_events.rs— the bounded live count makes id reuse after a 2^32 wrap a non-issue.Latent:
WatchQueueSubsystemis an exported pub module with no instance/syscall/dispatch path today. Found by a kernel security-parser fan-out (ptrace/landlock/perf/BTF/io_uring/seccomp/keyring all came back clean).Verification
cargo clippy -p oncrix-kernel -- -D warnings✓ (0) +cargo build -p oncrix-kernel --target x86_64-unknown-none✓ (bare-metal) +cargo fmt --all -- --check✓