From: Jiri Denemark Date: Thu, 6 Nov 2025 12:40:14 +0000 (+0100) Subject: cputest: Ignore missing MSRs in cpu-data.py X-Git-Tag: CVE-2025-12748~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3395fb59867458357b7b6616f58acced6751827;p=thirdparty%2Flibvirt.git cputest: Ignore missing MSRs in cpu-data.py The current code made sense when we were reading only one MSR, but since we started reading more MSRs, the host CPU would have to support all of them otherwise the function would just return an empty dict. Signed-off-by: Jiri Denemark Reviewed-by: Michal Privoznik --- diff --git a/tests/cputestdata/cpu-data.py b/tests/cputestdata/cpu-data.py index b280eed436..4d89cd6d5c 100755 --- a/tests/cputestdata/cpu-data.py +++ b/tests/cputestdata/cpu-data.py @@ -151,20 +151,28 @@ def gather_msr(): try: with open("/dev/cpu/0/msr", "rb") as f: for addr in addresses: - f.seek(addr) - buf = f.read(8) - msrs[addr] = struct.unpack("=Q", buf)[0] - return "", msrs + try: + f.seek(addr) + buf = f.read(8) + msrs[addr] = struct.unpack("=Q", buf)[0] + except IOError: + pass + if msrs: + return "", msrs except IOError as e: print("Warning: {}".format(e), file=sys.stderr) try: with open("/dev/kvm", "rb") as f: for addr in addresses: - bufIn = struct.pack("=LLLLQ", 1, 0, addr, 0, 0) - bufOut = fcntl.ioctl(f, KVM_GET_MSRS, bufIn) - msrs[addr] = struct.unpack("=LLLLQ", bufOut)[4] - return " via KVM", msrs + try: + bufIn = struct.pack("=LLLLQ", 1, 0, addr, 0, 0) + bufOut = fcntl.ioctl(f, KVM_GET_MSRS, bufIn) + msrs[addr] = struct.unpack("=LLLLQ", bufOut)[4] + except IOError: + pass + if msrs: + return " via KVM", msrs except IOError as e: print("Warning: {}".format(e), file=sys.stderr)