Skip to content

Commit 04e224f

Browse files
jgross1opsiff
authored andcommitted
Buffer overflow in drivers/xen/sys-hypervisor.c
commit 27fdbab4221b375de54bf91919798d88520c6e28 upstream. The build id returned by HYPERVISOR_xen_version(XENVER_build_id) is neither NUL terminated nor a string. The first causes a buffer overflow as sprintf in buildid_show will read and copy till it finds a NUL. 00000000 f4 91 51 f4 dd 38 9e 9d 65 47 52 eb 10 71 db 50 |..Q..8..eGR..q.P| 00000010 b9 a8 01 42 6f 2e 32 |...Bo.2| 00000017 So use a memcpy instead of sprintf to have the correct value: 00000000 f4 91 51 f4 dd 00 9e 9d 65 47 52 eb 10 71 db 50 |..Q.....eGR..q.P| 00000010 b9 a8 01 42 |...B| 00000014 (the above have a hack to embed a zero inside and check it's returned correctly). This is XSA-485 / CVE-2026-31786 Fixes: 84b7625 ("xen: add sysfs node for hypervisor build id") Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 5c5ff7c7bd15bb536f44b10b3fb5b8408f344d0a) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 105663b commit 04e224f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/xen/sys-hypervisor.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,19 @@ static ssize_t buildid_show(struct hyp_sysfs_attr *attr, char *buffer)
366366
ret = sprintf(buffer, "<denied>");
367367
return ret;
368368
}
369+
if (ret > PAGE_SIZE)
370+
return -ENOSPC;
369371

370372
buildid = kmalloc(sizeof(*buildid) + ret, GFP_KERNEL);
371373
if (!buildid)
372374
return -ENOMEM;
373375

374376
buildid->len = ret;
375377
ret = HYPERVISOR_xen_version(XENVER_build_id, buildid);
376-
if (ret > 0)
377-
ret = sprintf(buffer, "%s", buildid->buf);
378+
if (ret > 0) {
379+
/* Build id is binary, not a string. */
380+
memcpy(buffer, buildid->buf, ret);
381+
}
378382
kfree(buildid);
379383

380384
return ret;

0 commit comments

Comments
 (0)