[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/42] scsi-disk: Don't silently truncate serial number
From: |
Paolo Bonzini |
Subject: |
[PULL 23/42] scsi-disk: Don't silently truncate serial number |
Date: |
Sat, 8 Jun 2024 10:33:56 +0200 |
From: Kevin Wolf <kwolf@redhat.com>
Before this commit, scsi-disk accepts a string of arbitrary length for
its "serial" property. However, the value visible on the guest is
actually truncated to 36 characters. This limitation doesn't come from
the SCSI specification, it is an arbitrary limit that was initially
picked as 20 and later bumped to 36 by commit 48b62063.
Similarly, device_id was introduced as a copy of the serial number,
limited to 20 characters, but commit 48b62063 forgot to actually bump
it.
As long as we silently truncate the given string, extending the limit is
actually not a harmless change, but break the guest ABI. This is the
most important reason why commit 48b62063 was really wrong (and it's
also why we can't change device_id to be in sync with the serial number
again and use 36 characters now, it would be another guest ABI
breakage).
In order to avoid future breakage, don't silently truncate the serial
number string any more, but just error out if it would be truncated.
Buglink: https://issues.redhat.com/browse/RHEL-3542
Suggested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20240604161755.63448-1-kwolf@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/scsi-disk.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 4bd7af9d0c2..5f55ae54e42 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -58,6 +58,9 @@
#define TYPE_SCSI_DISK_BASE "scsi-disk-base"
+#define MAX_SERIAL_LEN 36
+#define MAX_SERIAL_LEN_FOR_DEVID 20
+
OBJECT_DECLARE_TYPE(SCSIDiskState, SCSIDiskClass, SCSI_DISK_BASE)
struct SCSIDiskClass {
@@ -648,8 +651,8 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *req,
uint8_t *outbuf)
}
l = strlen(s->serial);
- if (l > 36) {
- l = 36;
+ if (l > MAX_SERIAL_LEN) {
+ l = MAX_SERIAL_LEN;
}
trace_scsi_disk_emulate_vpd_page_80(req->cmd.xfer);
@@ -2501,9 +2504,20 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
if (!s->vendor) {
s->vendor = g_strdup("QEMU");
}
+ if (s->serial && strlen(s->serial) > MAX_SERIAL_LEN) {
+ error_setg(errp, "The serial number can't be longer than %d
characters",
+ MAX_SERIAL_LEN);
+ return;
+ }
if (!s->device_id) {
if (s->serial) {
- s->device_id = g_strdup_printf("%.20s", s->serial);
+ if (strlen(s->serial) > MAX_SERIAL_LEN_FOR_DEVID) {
+ error_setg(errp, "The serial number can't be longer than %d "
+ "characters when it is also used as the default for
"
+ "device_id", MAX_SERIAL_LEN_FOR_DEVID);
+ return;
+ }
+ s->device_id = g_strdup(s->serial);
} else {
const char *str = blk_name(s->qdev.conf.blk);
if (str && *str) {
--
2.45.1
- [PULL 13/42] target/i386: use gen_writeback() within gen_POP(), (continued)
- [PULL 13/42] target/i386: use gen_writeback() within gen_POP(), Paolo Bonzini, 2024/06/08
- [PULL 14/42] target/i386: fix SP when taking a memory fault during POP, Paolo Bonzini, 2024/06/08
- [PULL 15/42] target/i386: fix size of EBP writeback in gen_enter(), Paolo Bonzini, 2024/06/08
- [PULL 16/42] machine: default -M mem-merge to off is QEMU_MADV_MERGEABLE is not available, Paolo Bonzini, 2024/06/08
- [PULL 17/42] meson: Don't even detect posix_madvise() on Darwin, Paolo Bonzini, 2024/06/08
- [PULL 18/42] osdep: Make qemu_madvise() to set errno in all cases, Paolo Bonzini, 2024/06/08
- [PULL 20/42] backends/hostmem: Report error when memory size is unaligned, Paolo Bonzini, 2024/06/08
- [PULL 21/42] machine, hostmem: improve error messages for unsupported features, Paolo Bonzini, 2024/06/08
- [PULL 22/42] hostmem: simplify the code for merge and dump properties, Paolo Bonzini, 2024/06/08
- [PULL 19/42] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes, Paolo Bonzini, 2024/06/08
- [PULL 23/42] scsi-disk: Don't silently truncate serial number,
Paolo Bonzini <=
- [PULL 24/42] stubs/meson: Fix qemuutil build when --disable-system, Paolo Bonzini, 2024/06/08
- [PULL 25/42] i386/hvf: Adds support for INVTSC cpuid bit, Paolo Bonzini, 2024/06/08
- [PULL 27/42] hvf: Consistent types for vCPU handles, Paolo Bonzini, 2024/06/08
- [PULL 26/42] i386/hvf: Fixes some compilation warnings, Paolo Bonzini, 2024/06/08
- [PULL 28/42] i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change, Paolo Bonzini, 2024/06/08
- [PULL 29/42] i386/hvf: In kick_vcpu use hv_vcpu_interrupt to force exit, Paolo Bonzini, 2024/06/08
- [PULL 31/42] hvf: Makes assert_hvf_ok report failed expression, Paolo Bonzini, 2024/06/08
- [PULL 30/42] i386/hvf: Updates API usage to use modern vCPU run function, Paolo Bonzini, 2024/06/08
- [PULL 33/42] target/i386: mark CR4.FRED not reserved, Paolo Bonzini, 2024/06/08
- [PULL 32/42] target/i386: add support for FRED in CPUID enumeration, Paolo Bonzini, 2024/06/08