From patchwork Fri Nov 19 20:11:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1557390 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h1QADtlt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hwnvn4Z7Pz9sRN for ; Sat, 20 Nov 2021 07:15:01 +1100 (AEDT) Received: from localhost ([::1]:57126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moAHi-00021z-Q3 for incoming@patchwork.ozlabs.org; Fri, 19 Nov 2021 15:14:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moAEk-0007ME-LU for qemu-devel@nongnu.org; Fri, 19 Nov 2021 15:11:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moAEh-0007mq-Qq for qemu-devel@nongnu.org; Fri, 19 Nov 2021 15:11:53 -0500 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= 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-438-f1bEgcCfMwCWcwTB2xSRXQ-1; Fri, 19 Nov 2021 15:11:50 -0500 X-MC-Unique: f1bEgcCfMwCWcwTB2xSRXQ-1 Received: by mail-wm1-f71.google.com with SMTP id n16-20020a05600c3b9000b003331973fdbbso5262741wms.0 for ; Fri, 19 Nov 2021 12:11:50 -0800 (PST) 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=zEoZ2AYr2GunAnYScEJjyngBD4IWCRoNAxCju2T0/RrhLips1xa2+raa4d4p7W5urA BQkCSqpxdPXQvZdrIM7JpusbROcQcUHqQq0f/1PZNR49PpL+vKUPE7XKgUMChu+WILF6 6ZCvKhFB7bYi2uIQdac6jLgCw9ycSTO0ZWcivoqF32nRbqzTURHZjTYqSopmZkxBLRs1 GBE3YpcAKrQFm9fCaDa3pw0bPU+6cwyV6G9bLQa3SK15WE91nlMd4MFwtve9+mrZoW8E 51/cTE+ctCCxLh+AWlg1kd14Ow85FI0QHT0PJpgRxCdM/IvLOERFthjkM35SjUARr6/k LLig== X-Gm-Message-State: AOAM531CLc0222wcyZd/S3nvrVwOwQ/lRWbiwBm7A+Nszdnchvn1Brat DCxqv9tRX/TeHrqKRCYQG5NqG5yavx+CDqDDX4OWQecgxNeAK0HrhbzC+Y9Lc6/FYvlRlExaZNi AzkaUl7Gq+aU1niA1Gm2obrKKIy7zagcD1hcMgOUvGagj+gfPLf+v6UCMoJlrAiwq X-Received: by 2002:a5d:4b0e:: with SMTP id v14mr11064793wrq.196.1637352708803; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, Alexander Bulekov , Qiuhao Li , Darren Kenny , Bandan Das , Stefan Hajnoczi , Hannes Reinecke , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é --- 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); } From patchwork Fri Nov 19 20:11:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1557389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AKLtLROL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hwnsk58s4z9sRN for ; Sat, 20 Nov 2021 07:13:14 +1100 (AEDT) Received: from localhost ([::1]:53138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moAG0-0007hl-IB for incoming@patchwork.ozlabs.org; Fri, 19 Nov 2021 15:13:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moAEq-0007Xh-2f for qemu-devel@nongnu.org; Fri, 19 Nov 2021 15:12:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moAEn-0007qp-17 for qemu-devel@nongnu.org; Fri, 19 Nov 2021 15:11:58 -0500 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= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-242-t-17hVdqPe6A-e1rJS6z8w-1; Fri, 19 Nov 2021 15:11:55 -0500 X-MC-Unique: t-17hVdqPe6A-e1rJS6z8w-1 Received: by mail-wm1-f69.google.com with SMTP id z138-20020a1c7e90000000b003319c5f9164so6420472wmc.7 for ; Fri, 19 Nov 2021 12:11:55 -0800 (PST) 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=HeR3z4BGjQass8SP/Ea6NCsl7rHVaAy+lSFDiJ541JSWBdemOl9J8K6uoKO1EP77uW SA3SVZ0qwMwiNKeylkjI6peobfjCX+xVTjRis6lDvyZUQhSVK/JD6UUweu00KLWm1nSr FGRcrB7D4M/Vb6W7g6mGoUdcfaVn+PVu9to4GqVub+TDIT35OYNLqcqdfGPUtwOy+tg6 ZUZjjjqmohvTOfNtopBYYN6uujRCespnyhD0OJMehCW7tH+ezO9dJRHQ6sxsGzxrfPt0 IGMq1papQijSzr85u0Fj3SNnfwk6A629Y3jT6haJcJ7razjInWiR9CwpTd++phOQdp76 DcQQ== X-Gm-Message-State: AOAM531fDIIuv9olhIoriBrjvzJQ5ykZMvqH0/J4/4699H9vqVWGUG7l 1Er0M1yTaHmbWn3lGDYHnoFGP3mG87+GGuIVBU64BR2Aj/lTjag7RAeXJxA5oIxVL2IXgTEdb96 9zI0tzApF58BFsaHQAdEw/0xaE5A9qoPaj1e1+JI0Rkk8+L19bbigtlWCL5IK5uhW X-Received: by 2002:a05:600c:1d28:: with SMTP id l40mr2998148wms.192.1637352713679; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Laurent Vivier , Thomas Huth , qemu-block@nongnu.org, Alexander Bulekov , Qiuhao Li , Darren Kenny , Bandan Das , Stefan Hajnoczi , Hannes Reinecke , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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: Assertion `mr != 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é --- 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-test.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); } +/* + * Overflow SGL buffer. + * https://gitlab.com/qemu-project/qemu/-/issues/521 + */ +static void test_gitlab_issue521_megasas_sgl_ovf(void) +{ + QTestState *s = qtest_init("-display none -m 32M -machine q35 " + "-nodefaults -device megasas " + "-device scsi-cd,drive=null0 " + "-blockdev " + "driver=null-co,read-zeroes=on,node-name=null0"); + 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 = qtest_get_arch(); @@ -43,6 +71,8 @@ int main(int argc, char **argv) if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 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); } return g_test_run();