[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.20] x86/hvm: Fix UB on defensive default case in handle_pio()



commit c5c4f96a2fe6a5a7271808e8b498af2a3e8a648e
Author:     Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
AuthorDate: Thu Oct 29 13:32:02 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Oct 29 13:32:02 2026 +0100

    x86/hvm: Fix UB on defensive default case in handle_pio()
    
    There's a potential 32bit left-shift (when size is 4) to a 32bit value,
    which would trigger UB and tickle UBSAN the wrong way. Shifting right an
    all-ones mask fixes the issue.
    
    Fixes: 4609fc8eb04e ("x86/hvm: Improve error information in handle_pio()")
    Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    master commit: 2b3f56ab514d46bed652527974b74d1cef76b759
    master date: 2026-10-14 09:27:28 +0200
---
 xen/arch/x86/hvm/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
index 47ce09331d..64746e64b5 100644
--- a/xen/arch/x86/hvm/io.c
+++ b/xen/arch/x86/hvm/io.c
@@ -136,7 +136,7 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
     default:
         gprintk(XENLOG_ERR, "Unexpected PIO status %d, port %#x %s 0x%0*x\n",
                 rc, port, dir == IOREQ_WRITE ? "write" : "read",
-                size * 2, data & ((1u << (size * 8)) - 1));
+                size * 2, data & (UINT32_MAX >> (32 - size * 8)));
         domain_crash(curr->domain);
         return false;
     }
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.20



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.