From nobody Tue Nov 18 01:22:21 2025 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=1606849856; cv=none; d=zohomail.com; s=zohoarc; b=lxQB1aQ8eGpuxTKEfl18Ram58GseWsHmxVxNh1NzUStTU5ALzZ5hOFTzbkrYIVRb7ZCiNPdYfSSwoNSsoWpD73OxNBbBO1NXCT5RQooJlGz2OSTrkpOghHXr12BqSDzMZ4sX6JWWXc77LmGOI/tuxnZCBauSHB8GsxKVZqTw33k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606849856; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=VGbOkVtccZuNiaIjB/Ue2VFK3Wp2YM6HNCOG5vhEWr0=; b=ceyu+gbZ+4sAzV5xLVyCihheQl2eNndVzP1LFIbmPAcXbiTddSyDJ8vXbYv63P+xHMCowN8sAo5bHwnox7cGmwCpWRt4oFNdRwrXPdiextV5XbWYlRjJBrzKOCd3nQyT1t1TG2N2PGbOgHYemlic6oP7v7BPclDE+tBSGBg/iWQ= 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 1606849856757434.54327226826035; Tue, 1 Dec 2020 11:10:56 -0800 (PST) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-6Y7Die2WPuOVe8oPF7iZUg-1; Tue, 01 Dec 2020 14:10:50 -0500 Received: by mail-wr1-f72.google.com with SMTP id x10so1451085wrs.2 for ; Tue, 01 Dec 2020 11:10:50 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (111.red-88-21-205.staticip.rima-tde.net. [88.21.205.111]) by smtp.gmail.com with ESMTPSA id d13sm885463wrb.39.2020.12.01.11.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 11:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606849854; 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: in-reply-to:in-reply-to:references:references; bh=VGbOkVtccZuNiaIjB/Ue2VFK3Wp2YM6HNCOG5vhEWr0=; b=SNW/ydiH0zdOhjbEpzQfoQOiXARyryFoNBA6yfB+yjMsudCxJ3KKOM/42MFRoVNfp+jEmA zBIX1yvIjuDnwIlfhFXrkhhN8JDMIzQqln24N4uIhv7ToL1o7w89on3IUpoPepVlAH+EiA v+u68+F2ADsnnyCNgRHxiG5/Q4pXkAg= X-MC-Unique: 6Y7Die2WPuOVe8oPF7iZUg-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:in-reply-to :references:mime-version:content-transfer-encoding; bh=VGbOkVtccZuNiaIjB/Ue2VFK3Wp2YM6HNCOG5vhEWr0=; b=Bpjgu1nknWhydiIJtgXPC68yLVACUwA0wgc7OuP6xd15HMwP6tsQoWMVzgiwxbpnHw iW8V4XfOe/+CQ9/ghe8Pa11TnvuhvJzpFjPcgB58DapUeRpPgwRGvrS8/RjmzGhYDayI 5+BwI6vdqNbzIADGy6AmoTMUPHDgLPQp3OHUmn3D+GFofe94UcCDN1MVODCZuQwTaTWE Ofu635+i/XDi8YsciCuJEcSEHmYdFwSEWWMQd3QUJPaHIqCzHOxZ1Tf2bkQIdXhpE4bg Q4Dx5AF86k+f5KL1Jj1kqyJ65STRpoP+pW14l43cenNAc8gprMng7eSqfbDGLVhiUxlb pkeA== X-Gm-Message-State: AOAM530FgSG2bJ+kH5Y5Gyr7NzafgtekLQToPFTPclImoW9/4mbebfKh WzD8G5v0t5MW3RSG0LCCv8nGetqGsPWya9iXyA5IaZs71wN7DkMB/WrNgBK1gHdzrw7ENHEr6dg K+mGZfMZ4l6ECQA== X-Received: by 2002:adf:ec0d:: with SMTP id x13mr5837934wrn.207.1606849849650; Tue, 01 Dec 2020 11:10:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJydC7yDNoLyIxmWwbBbZ6x6HSLyJYzSndkm+uJT6QjVjkW7JltyycHoMoEcWIPvHZPhKK6UVg== X-Received: by 2002:adf:ec0d:: with SMTP id x13mr5837911wrn.207.1606849849526; Tue, 01 Dec 2020 11:10:49 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Thomas Huth , Hannes Reinecke , Fam Zheng , Li Qiang , Alexander Bulekov , qemu-block@nongnu.org, Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v2 4/4] hw/scsi/megasas: Have incorrect cdb return MFI_STAT_ABORT_NOT_POSSIBLE Date: Tue, 1 Dec 2020 20:10:26 +0100 Message-Id: <20201201191026.4149955-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201201191026.4149955-1-philmd@redhat.com> References: <20201201191026.4149955-1-philmd@redhat.com> 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) Avoid out-of-bound array access with invalid CDB is provided. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- RFC because no clue how hardware works --- hw/scsi/megasas.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index f5ad4425b5b..7e7cbb8854b 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -1680,7 +1680,15 @@ static int megasas_handle_scsi(MegasasState *s, Mega= sasCmd *cmd, if (cdb_len > 0) { len =3D scsi_cdb_length(cdb); } - assert(len > 0 && cdb_len >=3D len); + if (len < 0 || len < cdb_len) { + trace_megasas_scsi_invalid_cdb_len(mfi_frame_desc(frame_cmd), + is_logical, target_id, + lun_id, cdb_len); + megasas_write_sense(cmd, SENSE_CODE(INVALID_FIELD)); + cmd->frame->header.scsi_status =3D TASK_ABORTED; + s->event_count++; + return MFI_STAT_ABORT_NOT_POSSIBLE; + } if (is_logical) { if (target_id >=3D MFI_MAX_LD || lun_id !=3D 0) { trace_megasas_scsi_target_not_present( --=20 2.26.2