kmq_timedsend built its queued message straight from the guest pointer
and both timed calls read abstime through it, so an unreadable pointer
faulted the host. Copy both through GuestCopyIn and fail with EFAULT,
reading the deadline right after the descriptor check as FreeBSD's
sys_kmq_timedsend and sys_kmq_timedreceive do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kmq_timedreceive_nid_postfix copied the message into the caller's buffer
with memcpy and stored the priority with *priority = ..., both guest
pointers, after only a null check, so a non-null but unmapped buffer or
priority faulted the process. Both writes now go through
GuestCopyOut_nid_no_patch: on an inaccessible output it restores the
caller's errno and returns EFAULT. Host callers pass stack buffers, which
GuestCopyOut writes like any mapped address.
Declare kmq_open/setattr/timedsend/timedreceive/unlink once in Api.hpp with their
real signatures and the GuestMqAttr/GuestTimespec types, and include Api.hpp (plus
GuestErrno.hpp and Equeue.hpp for __error and the descriptor-close observer) from
Mqueue.cpp and the test instead of local extern "C" blocks and duplicate types.
Deadline summed seconds and nanoseconds in nanoseconds, so on a microsecond
system_clock a tv_sec between about 9.2e9 and 9.2e12 passed the clock-range guard
and still overflowed; each part is now cast to the clock's duration before adding.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kmq_setattr wrote open->nonblocking outside queue.lock while WaitFor reads it
under the lock, racing concurrent mq_setattr with send and receive; the write
and the old-attribute snapshot now share the readers' lock.
kmq_timedreceive copied into buffer after dequeuing the message, so a null
buffer crashed the host and lost the message; it is now rejected with EFAULT
before the queue is touched, matching kmq_timedsend.
Deadline converted tv_sec to int64 nanoseconds, overflowing for a tv_sec near
INT64_MAX ("forever") and wrapping to an immediate timeout; it now saturates
to the clock's representable range.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>