From nobody Sun May 19 00:47:43 2024 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=1637191474; cv=none; d=zohomail.com; s=zohoarc; b=MCp8E384LCwfMfpajaCi4JOq+EWZPhISbVjBzT76BPLlXEcvj0Qvxig3wfZicBnGi5IBGeD0ZmAS3zFWSjBwsqOofFl2sJ3zXRhFHlKMZt2edt8IP0I6H/Vw+cEqjcbL7TqwUbqSDxd1ch2xoRowxlBtj2FSQzxo4PbA8gGyFEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637191474; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=6bR7W7pApBvDZKc22ceTHQaPDWCmswmmkM55lsqJEG0=; b=nE88FMiuFyIuOUICOSwIhWp1JQKAumqcpHmi/7frSaBJ5MSnSjSqd7OzgU79x9AXCusL9YHwHx94g5mJtTKlP6+9hIM5XH1798r8qcA5MxntkAHYLWsLcMw4+RKx2dqtDmedFh22fyS5BYfb7EnVMI+nUf3Pth0FimrU6ya5XxA= 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) 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 1637191474132773.5283057743906; Wed, 17 Nov 2021 15:24:34 -0800 (PST) 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-539-waCPI83gNge1OEN60y3r7w-1; Wed, 17 Nov 2021 18:24:30 -0500 Received: by mail-wm1-f72.google.com with SMTP id o18-20020a05600c511200b00332fa17a02eso2093766wms.5 for ; Wed, 17 Nov 2021 15:24:29 -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 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) 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= X-MC-Unique: waCPI83gNge1OEN60y3r7w-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=6bR7W7pApBvDZKc22ceTHQaPDWCmswmmkM55lsqJEG0=; b=2e8BJZMs1I9jYPMkNuFElE1MQQelq4n9MrfccwwEtocOFMjX1J3Wh5Lhr1WYytTx86 X92yB1XFz7H21xbECvF5H/3r2kDAyyq76egoy/c3/iLoaHmNGb4sTTGEH3AT9OIsyyIq LRB46qNZ3DuThnLPtnyQwCwT+XvwyjEYVmhILqFbskeygDsbyxo9idfKCVax2iluSWrf 9dAZjfw24LSoh3+2ypRBHcnqD+zZGqf+EXuZPDFZj2BDHGUXSSAZ2jerCE8Yaih0Dk+E y7JAr3D0KNxlcVP27S0RYdV3fkBu/GqHtW4RFoEQiV79qHYo5el8bbA/jDS+2ZjLJmnr Hn8g== X-Gm-Message-State: AOAM533ZkqiMq83jCwnFnNWJX6bU0R3iNR3lJjIsfccoQ3zfKRHGIGhp etMmVtD1rYYGAzC93Z5iTZ1WBNoTzMhnXLFrD4IjoVbytue/hVjv20RDquObcaGuHe2iqcSAD7U ysd3IHgq6Pd/8IA== X-Received: by 2002:adf:cd04:: with SMTP id w4mr24522482wrm.406.1637191468942; Wed, 17 Nov 2021 15:24:28 -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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Prasad J Pandit , Hanna Reitz , Laurent Vivier , Alexander Bulekov , qemu-block@nongnu.org, Thomas Huth , Gaoning Pan , Markus Armbruster , Paolo Bonzini , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637191475370100001 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=C3=A9 Reviewed-by: Darren Kenny --- 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) =20 static FDrive *get_cur_drv(FDCtrl *fdctrl) { - return get_drv(fdctrl, fdctrl->cur_drv); + FDrive *cur_drv =3D 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 =3D blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); + } + return cur_drv; } =20 /* Status A register : 0x00 (read-only) */ --=20 2.31.1 From nobody Sun May 19 00:47:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1637191476; cv=none; d=zohomail.com; s=zohoarc; b=BNGc86DLbARluGcIhOvTIavsGwgRwYERBQ5gMTG7YmeqP6Pon1j38j25z7Jf4fmy1ptPtWDjef789gY3EsFtRUWrkVExtNPBfo+Vn0K6zvYVP2DP/C2nwkj0S+1mSEZTjJrZFCGvU2iBsQs7LlFGmUcyFS5j69N9jm7EiXwY3tI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637191476; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=47kPYn7uOgULylrkXDVpilzijynJ2WpK52xoSC0rC5M=; b=ivy3AoAY5yA3xSvpGaG5aGCoIAlaPvi97cangEx5bPYo2BnWyzH6mylmjaDUzFN5MtzaU5YdE3Gw7+b0KVrBGO1dCoJzMbbAJV14II93xaUQObBruAkrJg6zqLRY9n4iD0GsEDQrS3GH+vZn+T09qCGjZtT9Eo1a7SkQD1k+JP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1637191476911839.4357779883184; Wed, 17 Nov 2021 15:24:36 -0800 (PST) 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-401-I08Ld6clPNCOsYHZIqnhrw-1; Wed, 17 Nov 2021 18:24:34 -0500 Received: by mail-wm1-f72.google.com with SMTP id r129-20020a1c4487000000b00333629ed22dso3470860wma.6 for ; Wed, 17 Nov 2021 15:24:34 -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 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) 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= X-MC-Unique: I08Ld6clPNCOsYHZIqnhrw-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=47kPYn7uOgULylrkXDVpilzijynJ2WpK52xoSC0rC5M=; b=jOVogrHBwUMAIqWfnw6onwP0hh3dQTsTnttvjUVnpkRwQXyZiNzK9hJsZjj39KsZiW m6vTbOn9y8iW6ODyb9/h4snUZ9YeB+26Omq8JhxozCpzQDEo4OxIDbhJBvmc5upzPsF3 YU+I4JM9hT7Aqw58JDjrIZY0Xk/LyDCz5Y+A6ICm/rvDfJD3k49RVdc1pDZ1qMc69Pc2 S4dPG9V28VKm1ODVhe4IhKA11N/zBZExOsFVaOxeK4FCTaNb+ffOUVjKfJRudTf/siZD 34Cml8ZaCK0zh7r1oeMSyFgGhhyD7jU9LW0jmnMr9kycY0AsvbZ9WQtwgp46YZPbskS1 V2+Q== X-Gm-Message-State: AOAM533xp3y//8Nd4v0rXxlzF9AF9eGovTN5wSAmmIq4Vi3QlUIcLYBd pj0nW5LlA9KsiCyhDVYlzZuSlH4rvdA3UrzudKpYon9Nh8e4CxKE0sw+mcxDvZtJGVLhrwu61Nh J4iu0t+gcI2Mi2g== X-Received: by 2002:a5d:648e:: with SMTP id o14mr24732123wri.141.1637191473431; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Prasad J Pandit , Hanna Reitz , Laurent Vivier , Alexander Bulekov , qemu-block@nongnu.org, Thomas Huth , Gaoning Pan , Markus Armbruster , Paolo Bonzini , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637191478672100001 From: Alexander Bulekov When running 'make check-qtest-i386' with QEMU configured with '--enable-sanitizers' we get: AddressSanitizer:DEADLYSIGNAL =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=3D287878=3D=3DERROR: AddressSanitizer: SEGV on unknown address 0x0000= 00000344 =3D=3D287878=3D=3DThe signal is caused by a WRITE memory access. =3D=3D287878=3D=3DHint: 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=C3=A9 Reviewed-by: Darren Kenny --- 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) } } =20 +static void test_cve_2021_20196(void) +{ + QTestState *s; + + s =3D qtest_initf("-nographic -m 32M -nodefaults " + "-drive file=3D%s,format=3Draw,if=3Dfloppy", test_imag= e); + 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); =20 ret =3D g_test_run(); =20 --=20 2.31.1