Skip to content

freebsd sync: fix _umtx_time flags check to use bitwise operation.#4911

Merged
RalfJung merged 2 commits intorust-lang:masterfrom
devnexen:freebsd_abstime_flag_fix
Mar 29, 2026
Merged

freebsd sync: fix _umtx_time flags check to use bitwise operation.#4911
RalfJung merged 2 commits intorust-lang:masterfrom
devnexen:freebsd_abstime_flag_fix

Conversation

@devnexen
Copy link
Copy Markdown
Contributor

@devnexen devnexen commented Mar 21, 2026

The _umtx_time flags check in read_umtx_time used equality (flags == abs_time) instead of bitwise AND (flags & abs_time != 0) to detect UMTX_ABSTIME. While functionally equivalent for current valid inputs (0 or UMTX_ABSTIME alone), the equality check would silently treat an absolute timeout as relative if flags had UMTX_ABSTIME set alongside other bits. Additionally, unknown flags were silently accepted, whereas the FreeBSD kernel (umtx_copyin_umtx_time() in kern_umtx.c) rejects them with EINVAL.

The fix adds validation that rejects unsupported flags and switches to the standard bitwise AND pattern used elsewhere in the codebase (e.g. O_APPEND/O_TRUNC checks in fs.rs).

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 21, 2026

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Mar 21, 2026
@RalfJung
Copy link
Copy Markdown
Member

Could you please add a PR description explaining the change? What's wrong with the old code, why is the new code more correct?

The `_umtx_time` flags check in `read_umtx_time` used equality (`flags == abs_time`) instead of bitwise AND (`flags & abs_time != 0`) to detect `UMTX_ABSTIME`. While functionally equivalent for current valid inputs (0 or `UMTX_ABSTIME` alone), the equality check would silently treat an absolute timeout as relative if `flags` had `UMTX_ABSTIME` set alongside other bits. Additionally, unknown flags were silently accepted, whereas the FreeBSD kernel (`umtx_copyin_umtx_time()` in `kern_umtx.c`) rejects them with `EINVAL`.

The fix adds validation that rejects unsupported flags and switches to the standard bitwise AND pattern used elsewhere in the codebase (e.g. `O_APPEND`/`O_TRUNC` checks in `fs.rs`).
@devnexen devnexen force-pushed the freebsd_abstime_flag_fix branch from 612b613 to 1b5a282 Compare March 21, 2026 11:30
Copy link
Copy Markdown
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks! We should really error on unsupported flags, good catch.
I have one minor comment.

@rustbot author

View changes since this review

Comment on lines +220 to +224
if flags & !abs_time != 0 {
throw_unsup_format!("unsupported `_umtx_time` flags: {:#x}", flags);
}

let abs_time_flag = flags & abs_time != 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual way we do this is by "subtracting" what we know from the flag, and then checking for 0 at the end. This avoids the hazard of having to list all supported flags twice, like this code currently does. (open uses a mirror variable instead, but that seems unnecessary complicated. Elsewhere we "subtract".)

@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Mar 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 28, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Mar 28, 2026
Instead of listing supported flags twice (once for the unsupported
check and once for extraction), subtract known flags and check for
!= 0 at the end, matching the convention used elsewhere in Miri.
@RalfJung RalfJung added this pull request to the merge queue Mar 29, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 29, 2026
@RalfJung RalfJung added this pull request to the merge queue Mar 29, 2026
Merged via the queue into rust-lang:master with commit 71bcd44 Mar 29, 2026
13 checks passed
@rustbot rustbot removed the S-waiting-on-author Status: Waiting for the PR author to address review comments label Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants