xen/argo: make the ring copy length check overflow-safe
PATCH 1/1 xen/argo: make the ring copy length check overflow-safe
From: Weiqi Wang <[email protected]>
memcpy_to_guest_ring() bounds the copy against the ring size with
if ( len + offset > XEN_ARGO_MAX_RING_SIZE )
where len and offset are unsigned int. offset is masked below PAGE_SIZE just above, but a len close to UINT_MAX makes len + offset wrap below XEN_ARGO_MAX_RING_SIZE and pass the check. The head_len computation in the loop wraps the same way, so the copy length is no longer bounded.
All current callers bound len via iov_count(), so this is not reachable in practice. Do not rely on that: bound len first, then compare offset against the room that is left.
No functional change for in-range inputs.
--- xen/common/argo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/argo.c +2 -1
@@ -568,7 +568,8 @@ memcpy_to_guest_ring(const struct domain *d, struct argo_ring_info *ring_info, offset &= ~PAGE_MASK ; -if ( len + offset >XEN_ARGO_MAX_RING_SIZE ) +if ( len >XEN_ARGO_MAX_RING_SIZE || + offset >XEN_ARGO_MAX_RING_SIZE - len )return -EFAULT ;while ( len )
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 6 lines · WeiqiW
From: Weiqi Wang <[email protected]>
memcpy_to_guest_ring()bounds the copy against the ring size withif ( len + offset >
XEN_ARGO_MAX_RING_SIZE)
Quoted 7 lines
where len and offset are unsigned int. offset is masked below
PAGE_SIZEjust above, but a len close toUINT_MAXmakes len + offset wrap belowXEN_ARGO_MAX_RING_SIZEand pass the check. Thehead_lencomputation in the loop wraps the same way, so the copy length is no longer bounded.All current callers bound len via
iov_count(), so this is not reachable in practice.
Which makes it questionable whether the change is actually needed. But as it doesn't look to introduce (e.g.) dead code, the change is likely fine to make.
However, there's a formal aspect which may need sorting:
Quoted 6 lines
Do not rely on that: bound len first, then compare offset
against the room that is left.No functional change for in-range inputs.
Signed-off-by WeiqiW <[email protected]>
There are two different real names and three different email addresses involved in your submission. Generally we'd expect at least the From:
that's going to be transformed to commit author to match the S-o-b. The mail coming from yet another email address is maybe okay-ish, but not helpful. The main problem being - how would anyone (reliably) determine that all three belong to one an the same person, not several merely happening to have identical / similar names.
Hence no ack just yet.
Jan
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jan Beulich
Acked-byQuoted 9 lines · Weiqi Wang
2026年10月12日 11:00,Weiqi Wang <[email protected]> 写道:
Apologies for the confusion. The two names and three addresses are all me: "Weiqi Wang" and "WeiqiW" are the same person, and [email protected], [email protected] and [email protected] are all my addresses. From now on I will use one identity for everything.
I will resend the patch so the From header, the commit author and the Signed-off-by line all read:
Weiqi Wang <[email protected]>
Please disregard the earlier Signed-off-by under the outlook address. Nothing else in the change is affected. Thank you for catching it.
Thanks for clarifying.
Quoted 1 line
Resent patch attached (bound len first, then compare offset against the room that is left, as you suggested). I checked it against the original guard over a grid of in-range (len, offset) pairs and found no behavioural difference, and separately confirmed the overflow case you flagged: with len close to
UINT_MAXthe old guard wrongly lets the request through, the new one correctly rejects it.
Unlike in the original submission there suddenly is a comment. If it was a brief one, I probably wouldn't mind, but for the situation at hand it's imo too verbose. Preferably with it dropped again (which I can easily do while committing)
Jan