Skip to contentSkip to conversation

xen/argo: make the ring copy length check overflow-safe

PATCH In review WeiqiW 2 participants 3 messages Oct 10 – Oct 12 2 messages not in the archive

lore
Share & tools
lore

WeiqiW

author
#0 lore raw

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
index 0b9a54db36..b308ee8311 100644
@@ -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)
#1 lore raw
Quoted 6 lines · WeiqiW

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 )

Quoted 7 lines

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.

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.

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]

Acked-by
#4 lore raw
Quoted 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_MAX the 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