From nobody Sun Feb 8 22:24:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612478895; cv=none; d=zohomail.com; s=zohoarc; b=E3UYfiO92F3/ZoYC6WXH374Y5x15wW64dtGHX1AjkWJF6uunhMma45H3rTZ+WxkWdhXEgBvrjcppxxj8t7YLO7N+DlPMxhfQSFyGNh36Dhrx1ANrApsXj8i/h54RzvdAwlFRoV1nVqZDrXUIyq2UwYpPE6Cw7FTYrk48TSzfFLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612478895; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=/81/LvVCMTVOSvqLCbLQh+qCxtuSEoIMFzFNM1miJj4=; b=XIBxSTGZrzQlzi6JkE1RCY+S/WX1AjcW0DxKquVU6xOLPI/YTdexuXab2vk3cZXFfoiosA2kKJmkqucTOfkcswgsgNvk/G0j0t7zRP15lL+IzWwi6j3KKdtXMGt/jJEUA05mz4WUWk1HO5//hnOxnd7pZg0CpOrDnVBNkb9SbW0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612478895718934.2329163127378; Thu, 4 Feb 2021 14:48:15 -0800 (PST) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-gxxGP-6NM8Ofspyv1xv1yQ-1; Thu, 04 Feb 2021 17:48:11 -0500 Received: by mail-ej1-f69.google.com with SMTP id aq28so4164592ejc.20 for ; Thu, 04 Feb 2021 14:48:11 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (107.red-83-59-163.dynamicip.rima-tde.net. [83.59.163.107]) by smtp.gmail.com with ESMTPSA id g9sm3056329ejp.55.2021.02.04.14.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 14:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612478894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/81/LvVCMTVOSvqLCbLQh+qCxtuSEoIMFzFNM1miJj4=; b=i32cZXvo9PtrmQn1A5ZI3xwNfHyOvlmSZVyswhqoLUjwt1SAwjbwv+z3DMdiPPZfj+zO8b GXC0L+VT2Uz/64s6p5ryw0oOPKlzSxf0oCJf0dZsp58k920RLzUNDorNUA1t6IbaHNoxle mVOJCrku+lQz94qvnU6oHF1BdUsPzzw= X-MC-Unique: gxxGP-6NM8Ofspyv1xv1yQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/81/LvVCMTVOSvqLCbLQh+qCxtuSEoIMFzFNM1miJj4=; b=aZP3TECTPu19BS7vRqVuEGpM86Pbpd85aij8I2YRJBwUVQixKGIf2QmEHhqBuizuHR oyW1D0axH1Frrjht/4e1e3AAu4X7TRUGnAShC7TFBsikl7Czra1dAxCsroVTEDLwgMpl S5nT1FfnwmMsGi1f+0z1qmMIj/dkoecCEAWE5rL80sEmCC7QFWFfz4P/NLNZne7ZF70I 9GD9hnMErjLYDcwAuInWkgQ76G/8ZSmizSWcL38WUU1+jAWJjbs4p8gGYjZH0sghTXfb s02GBtOf/OmF5sf+pxU60obr6meNZE7W6oVGThbKf/aqlwC0lHD+/rZdpIRxl0+NLkDY xu8Q== X-Gm-Message-State: AOAM532iB97aT/k1ZAK3NauqAOCYDHu1UQ65KSpLf6mBob05eRnfGZ8v 0PKCDXWVV420q3eKmp7m0Au78Yc4PvCxDSz1uf4Nuku2hAa9/925jgGXzDrORvN7eChS+GR8TSo G0VaCp0M1HTUWGw== X-Received: by 2002:aa7:c3c4:: with SMTP id l4mr758198edr.255.1612478890387; Thu, 04 Feb 2021 14:48:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/uGCF+5by7dhK4ScjdsZMiWpdsaGQ49aHjlMcHCP0/FraxGz+1tqFeNyPXjgqw3f2JYAsDA== X-Received: by 2002:aa7:c3c4:: with SMTP id l4mr758186edr.255.1612478890246; Thu, 04 Feb 2021 14:48:10 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Darren Kenny , Li Qiang , Fam Zheng , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org, Alexander Bulekov Subject: [PATCH] hw/scsi/scsi-disk: Fix out of bounds access in mode_sense_page() Date: Thu, 4 Feb 2021 23:48:07 +0100 Message-Id: <20210204224808.1821734-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Per the "SCSI Commands Reference Manual" (Rev. J) chapter 5.3 "Mode parameters" and table 359 "Mode page codes and subpage codes", the last page code is 0x3f. When using it as array index, the array must have 0x40 elements. Replace the magic 0x3f value by its definition and increase the size of the mode_sense_valid[] to avoid an out of bound access: hw/scsi/scsi-disk.c:1104:10: runtime error: index 63 out of bounds for ty= pe 'const int [63]' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior hw/scsi/scsi-disk= .c:1104:10 in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D1813911=3D=3DERROR: AddressSanitizer: global-buffer-overflow READ of size 4 at 0x5624b84aff1c thread T0 #0 0x5624b63004b3 in mode_sense_page hw/scsi/scsi-disk.c:1104:10 #1 0x5624b630f798 in scsi_disk_check_mode_select hw/scsi/scsi-disk.c:= 1447:11 #2 0x5624b630efb8 in mode_select_pages hw/scsi/scsi-disk.c:1515:17 #3 0x5624b630988e in scsi_disk_emulate_mode_select hw/scsi/scsi-disk.= c:1570:13 #4 0x5624b62f08e7 in scsi_disk_emulate_write_data hw/scsi/scsi-disk.c= :1861:9 #5 0x5624b62b171b in scsi_req_continue hw/scsi/scsi-bus.c:1391:9 #6 0x5624b62b2d4c in scsi_req_data hw/scsi/scsi-bus.c:1427:5 #7 0x5624b62f05f6 in scsi_disk_emulate_write_data hw/scsi/scsi-disk.c= :1853:9 #8 0x5624b62b171b in scsi_req_continue hw/scsi/scsi-bus.c:1391:9 #9 0x5624b63e47ed in megasas_enqueue_req hw/scsi/megasas.c:1660:9 #10 0x5624b63b9cfa in megasas_handle_scsi hw/scsi/megasas.c:1735:5 #11 0x5624b63acf91 in megasas_handle_frame hw/scsi/megasas.c:1974:24 #12 0x5624b63aa200 in megasas_mmio_write hw/scsi/megasas.c:2131:9 #13 0x5624b63ebed3 in megasas_port_write hw/scsi/megasas.c:2182:5 #14 0x5624b6f43568 in memory_region_write_accessor softmmu/memory.c:4= 91:5 Cc: qemu-stable@nongnu.org Reported-by: OSS-Fuzz Reported-by: Alexander Bulekov Buglink: https://bugs.launchpad.net/qemu/+bug/1914638 Fixes: a8f4bbe2900 ("scsi-disk: store valid mode pages in a table") Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/scsi/scsi-disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index ed52fcd49ff..93aec483e88 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1089,7 +1089,7 @@ static int scsi_emulate_mechanism_status(SCSIDiskStat= e *s, uint8_t *outbuf) static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, int page_control) { - static const int mode_sense_valid[0x3f] =3D { + static const int mode_sense_valid[MODE_PAGE_ALLS + 1] =3D { [MODE_PAGE_HD_GEOMETRY] =3D (1 << TYPE_DISK), [MODE_PAGE_FLEXIBLE_DISK_GEOMETRY] =3D (1 << TYPE_DISK), [MODE_PAGE_CACHING] =3D (1 << TYPE_DISK) | (1 << TY= PE_ROM), --=20 2.26.2