From patchwork Wed Nov 17 23:24:21 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: 12625741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32A1DC433F5 for ; Wed, 17 Nov 2021 23:28:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D0C9661BC1 for ; Wed, 17 Nov 2021 23:28:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D0C9661BC1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnULs-0008K7-2A for qemu-devel@archiver.kernel.org; Wed, 17 Nov 2021 18:28:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnUIK-0004LL-Gk for qemu-devel@nongnu.org; Wed, 17 Nov 2021 18:24:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnUI5-0002Rj-Ta for qemu-devel@nongnu.org; Wed, 17 Nov 2021 18:24:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637191473; 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=6bR7W7pApBvDZKc22ceTHQaPDWCmswmmkM55lsqJEG0=; b=gSBMCtDOJKxD5zkWca+1pbIb/Wd2Ck5/E8aYoZnP13ngmJ1AJivjLlTaZDLFhW/i1+yq/z LjfCWGusUWXQUYBTsHQqOfDSsrUN8hSV/9ARTN8eZ1LXK9iz9GpfWAvzSXBQ7CejX6ldb5 3R8knC1NuF27c7F/VhRetM1o/LBG9AU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-DUlM9fNgOjGtyg4-aMNEJg-1; Wed, 17 Nov 2021 18:24:30 -0500 X-MC-Unique: DUlM9fNgOjGtyg4-aMNEJg-1 Received: by mail-wm1-f72.google.com with SMTP id v10-20020a1cf70a000000b00318203a6bd1so2096137wmh.6 for ; Wed, 17 Nov 2021 15:24:30 -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=6bR7W7pApBvDZKc22ceTHQaPDWCmswmmkM55lsqJEG0=; b=eBkz9X1fiXeANEDZeWhqWyt6aSZXSN/63VHXYgDiCzDk7XOPvwtZ+7f6OHeh/36IeP ugkxPQP1DxNTJaE1BEanvyzWQJldw6MXyn9WDxnGNX2YyG1jjAvr3t86fhrrGV8NRxq1 A9gik/Bu1X4reW+Y5//YoVSeIiOGvRRCbUEobyEHCGQrILnhR3eLh2CPQIMzQl0AHHln vKmJs6uOuOpadGr0NorGL4KPtV2kOPzJmeesKX2b84gnRf+c4Y4cbj4MAEOt4l6DHIvA aERIjjvHL/iYnotQRvOnC6zACoHfgRK7A7VdO9PjMTWnu5LUpGaTMPIqDRv1ax5ZMEGS 4xVA== X-Gm-Message-State: AOAM532SZKSMD804ANb4ctdkJqAmerHM3yK/27DXj05gio5ydh/OFmnq Z0ATJbWlI7/VnZL7cCBCBCNgeufFNgyG1SILqjaKY/qtp4eeDZPNfux25HPiwb26eg6oJQ4Dv11 nc9d/nmchNW4ZyD616rqMvJjSJd+exe2zWgpr92mz8p0qNHr2nC0W6EDq4oo23Jtl X-Received: by 2002:adf:cd04:: with SMTP id w4mr24522506wrm.406.1637191469043; Wed, 17 Nov 2021 15:24:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGxtaX0G+egFTZet/iUx41TG3FEKtOefK0jxFu1kZ72hhvLUj/7u9sSkax6mmviUIVLb0rBg== X-Received: by 2002:adf:cd04:: with SMTP id w4mr24522464wrm.406.1637191468803; Wed, 17 Nov 2021 15:24:28 -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 k8sm1153363wrn.91.2021.11.17.15.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 15:24:28 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH-for-6.2 v2 1/2] hw/block/fdc: Kludge missing floppy drive to fix CVE-2021-20196 Date: Thu, 18 Nov 2021 00:24:21 +0100 Message-Id: <20211117232422.1026411-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211117232422.1026411-1-philmd@redhat.com> References: <20211117232422.1026411-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.701, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Kevin Wolf , Laurent Vivier , Thomas Huth , Prasad J Pandit , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster , Alexander Bulekov , Hanna Reitz , Paolo Bonzini , Gaoning Pan , John Snow Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Guest might select another drive on the bus by setting the DRIVE_SEL bit of the DIGITAL OUTPUT REGISTER (DOR). The current controller model doesn't expect a BlockBackend to be NULL. A simple way to fix CVE-2021-20196 is to create an empty BlockBackend when it is missing. All further accesses will be safely handled, and the controller state machines keep behaving correctly. Fixes: CVE-2021-20196 Reported-by: Gaoning Pan (Ant Security Light-Year Lab) BugLink: https://bugs.launchpad.net/qemu/+bug/1912780 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/338 Signed-off-by: Philippe Mathieu-Daudé --- hw/block/fdc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index fa933cd3263..eab17e946d6 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -1161,7 +1161,19 @@ static FDrive *get_drv(FDCtrl *fdctrl, int unit) static FDrive *get_cur_drv(FDCtrl *fdctrl) { - return get_drv(fdctrl, fdctrl->cur_drv); + FDrive *cur_drv = get_drv(fdctrl, fdctrl->cur_drv); + + if (!cur_drv->blk) { + /* + * Kludge: empty drive line selected. Create an anonymous + * BlockBackend to avoid NULL deref with various BlockBackend + * API calls within this model (CVE-2021-20196). + * Due to the controller QOM model limitations, we don't + * attach the created to the controller. + */ + cur_drv->blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); + } + return cur_drv; } /* Status A register : 0x00 (read-only) */ From patchwork Wed Nov 17 23:24:22 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: 12625739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EE64C433EF for ; Wed, 17 Nov 2021 23:25:57 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0FAA861B3A for ; Wed, 17 Nov 2021 23:25:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0FAA861B3A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnUJQ-0005s9-1g for qemu-devel@archiver.kernel.org; Wed, 17 Nov 2021 18:25:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnUIB-0003zV-Gi for qemu-devel@nongnu.org; Wed, 17 Nov 2021 18:24:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56515) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnUI8-0002SH-VV for qemu-devel@nongnu.org; Wed, 17 Nov 2021 18:24:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637191475; 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=47kPYn7uOgULylrkXDVpilzijynJ2WpK52xoSC0rC5M=; b=Cf1+eLPuOQIDHoIaaEEZliphZOLJ2RLO7OgQrU5uZCrk+VxL/0t1phvDc758K+PZmJhaGz N7o44X6xCD3KTmfYPYDqmHc3z3sjz3k2ub04aECEEKpH5IQEzlx0AdPUALfMOLKhM/Sqgw SqinVbgua38Y2DbabHGYOu3YQ2cDobE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-485-MxMgrz1JMM6heWY74sAb7g-1; Wed, 17 Nov 2021 18:24:35 -0500 X-MC-Unique: MxMgrz1JMM6heWY74sAb7g-1 Received: by mail-wr1-f69.google.com with SMTP id y4-20020adfd084000000b00186b16950f3so750929wrh.14 for ; Wed, 17 Nov 2021 15:24:34 -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=47kPYn7uOgULylrkXDVpilzijynJ2WpK52xoSC0rC5M=; b=uGtdEmhs2UxhHSLyEbZEZtml+rKyz7M/KUgAtYnGF8AeDoJo0TsKLLkqb2+g4X7uJd mJ40MGIgqlD3aOSs2Y0LESEnxkvNGP4aRBe7i/Xz+uRb7p5Sp5d/AjNBzhiHEhdGedF3 U1JpY/QqNgsmQdVk74rrUP5O0AC5GvsKzAOKSU6kZenAfCMPBUuG6wZpFmlxBKffwKPK FLCfsA0gxDpoxZmicgsWS/zHLNfjF2/BJGF+7JcDdmNMpik/VktU37B/b7gjIpvTYsqk I/5gd4WDd3VaRibhcNLy+FUyo/qkEgjJfWfoMRPfLQgv27VkP14d8HMbSvpuzPpQwAHw G+5Q== X-Gm-Message-State: AOAM531nap3EIy5cYpMYC6EDFcSXttLlWswJYR8M88iVrTaZbHXjUfwk S5UnrLxmQ4+X7G7gCf29F8Mrh5rtRrls+mFbPhhgRVDa1KEc3dG+mRKVZHwgqUuAe/nHXG6ONNP jQ+u+Sa7d6rReH65k5bDhe4mvgX45P83vJ7pd+vvUzqNcuRrPC/2Rnp23+F98V0GQ X-Received: by 2002:a5d:648e:: with SMTP id o14mr24732142wri.141.1637191473490; Wed, 17 Nov 2021 15:24:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNkb6vonRxmsY/4qewwcb3ru6pJQfV/zbO2rrggMyMqi3QpX31twR0PJFYIYWhwHmm3Y4ZHQ== X-Received: by 2002:a5d:648e:: with SMTP id o14mr24732106wri.141.1637191473302; Wed, 17 Nov 2021 15:24:33 -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 n32sm1115396wms.42.2021.11.17.15.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 15:24:32 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH-for-6.2 v2 2/2] tests/qtest/fdc-test: Add a regression test for CVE-2021-20196 Date: Thu, 18 Nov 2021 00:24:22 +0100 Message-Id: <20211117232422.1026411-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211117232422.1026411-1-philmd@redhat.com> References: <20211117232422.1026411-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.129.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.701, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: Kevin Wolf , Laurent Vivier , Thomas Huth , Prasad J Pandit , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster , Alexander Bulekov , Hanna Reitz , Paolo Bonzini , Gaoning Pan , John Snow Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Alexander Bulekov When running 'make check-qtest-i386' with QEMU configured with '--enable-sanitizers' we get: AddressSanitizer:DEADLYSIGNAL ================================================================= ==287878==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000344 ==287878==The signal is caused by a WRITE memory access. ==287878==Hint: address points to the zero page. #0 0x564b2e5bac27 in blk_inc_in_flight block/block-backend.c:1346:5 #1 0x564b2e5bb228 in blk_pwritev_part block/block-backend.c:1317:5 #2 0x564b2e5bcd57 in blk_pwrite block/block-backend.c:1498:11 #3 0x564b2ca1cdd3 in fdctrl_write_data hw/block/fdc.c:2221:17 #4 0x564b2ca1b2f7 in fdctrl_write hw/block/fdc.c:829:9 #5 0x564b2dc49503 in portio_write softmmu/ioport.c:201:9 Signed-off-by: Alexander Bulekov Message-Id: <20210319050906.14875-2-alxndr@bu.edu> [PMD: Rebased, use global test_image] Signed-off-by: Philippe Mathieu-Daudé --- tests/qtest/fdc-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c index 26b69f7c5cd..dfca84c7b96 100644 --- a/tests/qtest/fdc-test.c +++ b/tests/qtest/fdc-test.c @@ -546,6 +546,26 @@ static void fuzz_registers(void) } } +static void test_cve_2021_20196(void) +{ + QTestState *s; + + s = qtest_initf("-nographic -m 32M -nodefaults " + "-drive file=%s,format=raw,if=floppy", test_image); + qtest_outw(s, 0x3f2, 0x0004); + qtest_outw(s, 0x3f4, 0x0200); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f2, 0x0001); + qtest_quit(s); +} + int main(int argc, char **argv) { int fd; @@ -576,6 +596,7 @@ int main(int argc, char **argv) qtest_add_func("/fdc/read_no_dma_18", test_read_no_dma_18); qtest_add_func("/fdc/read_no_dma_19", test_read_no_dma_19); qtest_add_func("/fdc/fuzz-registers", fuzz_registers); + qtest_add_func("/fdc/fuzz/cve_2021_20196", test_cve_2021_20196); ret = g_test_run();