From nobody Sun Feb 8 19:48:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1637352712; cv=none; d=zohomail.com; s=zohoarc; b=i1KNG60bENft+Hou07XDjuh6EwnU0ZUDPasnKxOg0fAppLLMtTA6dqfXuh7La5djO+wkRscQXsppnKQWbA+IM5a/W8BHgR/7Kae4hv5syIyUIXMHvK+Qw67t6ue3YSnczp77WX+DvMOyhOPIjmFW4lOEUQayPZb5MWPwc8yac1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637352712; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=tyeixmmwuZJID1W+S/tZDE99JTCY1osLTIUAw+RmmGY=; b=FKC9FBfBuXhpVFA2wPmfStbObPiJchbUWBckQo4MrgtieDCnLpaOw11BfL8GRRWkoeJHGEOIy8E/pKMmeU0NHV1yjOom4ftAxZUj3NzCmg3bW0wlDdOrXnBBkZvNp7iJ0Xr5KqBCswjDokBbimPAR4tzg6ttlyaS3l8tToa2Hn0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637352712406292.7635799441068; Fri, 19 Nov 2021 12:11:52 -0800 (PST) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-376-2nuZnR5nNGq5v0NDk_Y6ww-1; Fri, 19 Nov 2021 15:11:50 -0500 Received: by mail-wm1-f70.google.com with SMTP id v62-20020a1cac41000000b0033719a1a714so4540844wme.6 for ; Fri, 19 Nov 2021 12:11:50 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id q123sm13015208wma.30.2021.11.19.12.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 12:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637352711; 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=tyeixmmwuZJID1W+S/tZDE99JTCY1osLTIUAw+RmmGY=; b=h1QADtltZ0rr91ZGnACrrVWwyBbuwqPOIpV4p1YbYa5ZCRyi7iByNZreb8av3IDXhabtGg DnTaGSRwleNsEO+7dpj4jrb77VygH/h/MyFY8j7eQWjTkcGKzpkECaYdSNkT17FRDILvLA i+cbO1WZh6CSS0vIXkacziq6mlDfLa4= X-MC-Unique: 2nuZnR5nNGq5v0NDk_Y6ww-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tyeixmmwuZJID1W+S/tZDE99JTCY1osLTIUAw+RmmGY=; b=AXtpAERvURVOzTd7Kt7dnGGUkOn4rdiJwhPnXrrN/9aW1QBMY+hI/KiDw4m83zJibS HuKFD/HPQU7IuScoHmcG3dcAz0RvSM2PH534xAx+EhX/3wVJtZ6YC3uLmygmKwv1Ig4B E09S5k1ADWuvnwJpvGLNNYMDg7nt3ZAjc625cRvOwZgD4CeDIEPjgoJK9fhcLHIur06z EIJ+S6vBSR59CFgTdWPaFo+Hu4no2yQtFTGeiOqA0vwHbkyRyc4JspzspBn8M067gtUB ArqzCyJyGaQqJwR7NYVDayRXqsuz/KWwyjMou/KIvbsNSN6AoGHo6TIP/kCx+X0jmj8G TWcw== X-Gm-Message-State: AOAM531mQUzQwXRj0eMwCcN7p+blh1eqkVAz4JQJqP7DxX58iFaFxKhf cuAR2qkdAEhsQsZLPDLxeMA06gAhpmtK89EP2X4sh+nTraOO4/iKsi/NlDRXe2i9k9wmUSnXl59 TqIACnYgp/Vd/dw== X-Received: by 2002:a5d:4b0e:: with SMTP id v14mr11064779wrq.196.1637352708762; Fri, 19 Nov 2021 12:11:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsfp2lkYJx1+otbjpU1L0/VpexWA/+XdcMu8ge67WwaaPeyZ6588vnjTZIon+MaE9MFF4cYw== X-Received: by 2002:a5d:4b0e:: with SMTP id v14mr11064745wrq.196.1637352708576; Fri, 19 Nov 2021 12:11:48 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bandan Das , Thomas Huth , Darren Kenny , Fam Zheng , Alexander Bulekov , Paolo Bonzini , Laurent Vivier , Stefan Hajnoczi , Qiuhao Li , qemu-block@nongnu.org, Hannes Reinecke , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2 1/2] hw/scsi/megasas: Fails command if SGL buffer overflows Date: Fri, 19 Nov 2021 21:11:40 +0100 Message-Id: <20211119201141.532377-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211119201141.532377-1-philmd@redhat.com> References: <20211119201141.532377-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) X-ZM-MESSAGEID: 1637352714167100001 If we detect an overflow on the SGL buffer, do not keep processing the command: discard it. TARGET_FAILURE sense code will be returned (MFI_STAT_SCSI_DONE_WITH_ERROR). Reported-by: Alexander Bulekov Resolves: https://gitlab.com/qemu-project/qemu/-/issues/521 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Darren Kenny --- No, I haven't looked at the datasheet. --- hw/scsi/megasas.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 4ff51221d4c..8f357841004 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -303,6 +303,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd = *cmd, union mfi_sgl *sgl) } if (cmd->iov_size > iov_size) { trace_megasas_iovec_overflow(cmd->index, iov_size, cmd->iov_size); + goto unmap; } else if (cmd->iov_size < iov_size) { trace_megasas_iovec_underflow(cmd->index, iov_size, cmd->iov_size); } --=20 2.31.1 From nobody Sun Feb 8 19:48:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1637352717; cv=none; d=zohomail.com; s=zohoarc; b=UpZK6s5JGRxvAoxgI2ptlLHSfHDlQgQhpijfRpBRczw3QK1HuQacbRycAHlK01TlcA1mtgZLH4V3i/CtzOpf175m2WWa79pj3D899x8YcylbxFVKErKy8iQ2JfNm/4XZORhdhGsX9efIxuQWQs+TewWMdDR+seOFStUIlF5pwZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637352717; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0Gq6HjzogQNFDfIqJXgnhwFRKV1Nym1r+WR9nIUiBJQ=; b=aUnpA4NSA54UiINNZbMCAYPed2joaJwucw2JOoCZt4mIESXlpV49+GMbDibFxAh15aIQDWm7PLu0eoetHh6tDX1P2d9+bv6Wwgr7+M0YaElCZb3i8mLcExlarceh83XtV65LioI13ImsO5WwVS35HWdS5aPjqSPKt/yPJxv7OCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 163735271738056.02238053127917; Fri, 19 Nov 2021 12:11:57 -0800 (PST) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-222-kDs0kXyXOjKlvwx97ZLtAQ-1; Fri, 19 Nov 2021 15:11:54 -0500 Received: by mail-wm1-f71.google.com with SMTP id r129-20020a1c4487000000b00333629ed22dso6423721wma.6 for ; Fri, 19 Nov 2021 12:11:54 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id e12sm937189wrq.20.2021.11.19.12.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 12:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637352716; 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=0Gq6HjzogQNFDfIqJXgnhwFRKV1Nym1r+WR9nIUiBJQ=; b=AKLtLROLWNJC8eNekTUSR+KjiuafqHf60GnD2silcG6QYoGhbDnqeMEccIihxkx+NNYbza g/J935lTH/dZyRTitotY7zsIJ6jWefTybpL/Voh/1yzcttgTw17BAR+Hy1zx8lTdd26rcb ZpI2dpFP5YUL2e04LyHdk1greeVryQw= X-MC-Unique: kDs0kXyXOjKlvwx97ZLtAQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Gq6HjzogQNFDfIqJXgnhwFRKV1Nym1r+WR9nIUiBJQ=; b=gVAoisoBEDGOHdPzQEqWkeyTq6kkcSA03wbSFVREee47/zuvGVQhZ5Wii4bSdNHcvC IbaVqvOERfC0GNjHWoAtx2zneWjR6rpw1CVtabLphMG7jN3qQtuS7p8wIdwkl/Ppt3be pNlc2Ire2p9RYSF2KUzrz3VSpTzvdSAxn5griy3m1esHHg0DHSeHx5gQRMd/Ooi5cK6Q BFyWb5fqa8ONAbzFwdydzM9QkO+cndFWKRk7MtdxqoU4dzfrIDg638+bHyUt+PIF+hOn 25+L7on0YYNVT47bqx73zUKVahEyYri7v8aJu5JJJAC5/fFR3HWE8pi3hK5CBCD+55Im DQbw== X-Gm-Message-State: AOAM530YMEH5mc9qHXWSvkE69lXbOL7Bc1cqAuYBBxoKiLzOZ6O35YNK Ngl/nG4DqkFV5E/yv1sSWNGepbkSvyJxeoaczTZuS1jsw6ASqaoB7n90oO9h39yI+pgx2ZlHycp VW+jImGtosCcjlQ== X-Received: by 2002:a05:600c:1d28:: with SMTP id l40mr2998138wms.192.1637352713652; Fri, 19 Nov 2021 12:11:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2DR61AiYTQSjxr7lCwpna4EFDXr4+2H7nfm6nlE4D0DPmRfDoyyW44n+WUc/VzfHX/4rmSg== X-Received: by 2002:a05:600c:1d28:: with SMTP id l40mr2998101wms.192.1637352713491; Fri, 19 Nov 2021 12:11:53 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bandan Das , Thomas Huth , Darren Kenny , Fam Zheng , Alexander Bulekov , Paolo Bonzini , Laurent Vivier , Stefan Hajnoczi , Qiuhao Li , qemu-block@nongnu.org, Hannes Reinecke , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2 2/2] tests/qtest/fuzz-megasas-test: Add test for GitLab issue #521 Date: Fri, 19 Nov 2021 21:11:41 +0100 Message-Id: <20211119201141.532377-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211119201141.532377-1-philmd@redhat.com> References: <20211119201141.532377-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) X-ZM-MESSAGEID: 1637352718313100001 Without the previous commit, this test triggers: $ make check-qtest-x86_64 [...] Running test qtest-x86_64/fuzz-megasas-test qemu-system-x86_64: softmmu/physmem.c:3229: address_space_unmap: Assertio= n `mr !=3D NULL' failed. Broken pipe ERROR qtest-x86_64/fuzz-megasas-test - too few tests run (expected 2, got= 1) Suggested-by: Alexander Bulekov Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Darren Kenny --- tests/qtest/fuzz-megasas-test.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/qtest/fuzz-megasas-test.c b/tests/qtest/fuzz-megasas-tes= t.c index 940a76bf25a..e1141c58a4e 100644 --- a/tests/qtest/fuzz-megasas-test.c +++ b/tests/qtest/fuzz-megasas-test.c @@ -34,6 +34,34 @@ static void test_lp1878263_megasas_zero_iov_cnt(void) qtest_quit(s); } =20 +/* + * Overflow SGL buffer. + * https://gitlab.com/qemu-project/qemu/-/issues/521 + */ +static void test_gitlab_issue521_megasas_sgl_ovf(void) +{ + QTestState *s =3D qtest_init("-display none -m 32M -machine q35 " + "-nodefaults -device megasas " + "-device scsi-cd,drive=3Dnull0 " + "-blockdev " + "driver=3Dnull-co,read-zeroes=3Don,node-nam= e=3Dnull0"); + qtest_outl(s, 0xcf8, 0x80000818); + qtest_outl(s, 0xcfc, 0xc000); + qtest_outl(s, 0xcf8, 0x80000804); + qtest_outw(s, 0xcfc, 0x05); + qtest_bufwrite(s, 0x0, "\x01", 0x1); + qtest_bufwrite(s, 0x7, "\x01", 0x1); + qtest_bufwrite(s, 0x10, "\x02", 0x1); + qtest_bufwrite(s, 0x16, "\x01", 0x1); + qtest_bufwrite(s, 0x28, "\x01", 0x1); + qtest_bufwrite(s, 0x33, "\x01", 0x1); + qtest_outb(s, 0xc040, 0x0); + qtest_outb(s, 0xc040, 0x20); + qtest_outl(s, 0xc040, 0x20000000); + qtest_outb(s, 0xc040, 0x20); + qtest_quit(s); +} + int main(int argc, char **argv) { const char *arch =3D qtest_get_arch(); @@ -43,6 +71,8 @@ int main(int argc, char **argv) if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qtest_add_func("fuzz/test_lp1878263_megasas_zero_iov_cnt", test_lp1878263_megasas_zero_iov_cnt); + qtest_add_func("fuzz/gitlab_issue521_megasas_sgl_ovf", + test_gitlab_issue521_megasas_sgl_ovf); } =20 return g_test_run(); --=20 2.31.1