From nobody Sat May 18 22:31:10 2024 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=1637237206; cv=none; d=zohomail.com; s=zohoarc; b=k6RusmKbXAL9dOEfoUiD7U1snWtVWyExA1m3ukQsBRpyD9NhdqIHAJ6EFGKdvEe1bmoOSwljIvD5LSPHXsY2uisOTiyRlaKz0B3ThI+sdU4hAjb9YIMAvqjZ+DjvVOelIJimkLaSxVGeybPdt+KMFYpDA6TzY8uY7u0MNRPeCTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637237206; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=jQgJq8UQRrsSz2LTJWEcm7fv7ub6tAHvzmzHdQGoASg=; b=j3Xbow/G2KjyOcXggT/uEqmAXUV6cFK0UkHNyVE3MAxz5Z3FbsjAJbA57vHT44sUhJWVnA9vPBiQp61WcKa4+PjF0be89tNvx0XBPTdHRBioJr7R0ZngBHOXQjk+zIo0ku0MjOdvvmEHGIuHW9CJ0uB30y+7d86ZxE8eefeTfQM= 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 1637237206567772.5452285964406; Thu, 18 Nov 2021 04:06:46 -0800 (PST) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-546-TtW4tHPbNUaJ0Q4rx45yMA-1; Thu, 18 Nov 2021 07:06:44 -0500 Received: by mail-wr1-f72.google.com with SMTP id q17-20020adfcd91000000b0017bcb12ad4fso1019247wrj.12 for ; Thu, 18 Nov 2021 04:06:44 -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 z8sm3004513wrh.54.2021.11.18.04.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 04:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637237205; 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=jQgJq8UQRrsSz2LTJWEcm7fv7ub6tAHvzmzHdQGoASg=; b=HBpSKoYeAVv4UOhO1wV2xr44PzlnKcNpZdeYn2l6S5bUboVFWrmpyZaO+y+Fa3XnecWD0h 3MKay3xcduaE4f+DOb6HRV76UvKsniqxS1ZWBUWa/+YUV3MZW1N1+uT9i/AxwmoJDxlm9i y+lrsTXhQ9y6GxEFmhon2vfO/5BB0WA= X-MC-Unique: TtW4tHPbNUaJ0Q4rx45yMA-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=jQgJq8UQRrsSz2LTJWEcm7fv7ub6tAHvzmzHdQGoASg=; b=UvJEh7IV2tTmFFX9plnms6zQiXOyYkOeMyV6btRLfC62cC5CRww3DX8XX8TJJpgOMB 7Mg7KzzpOuUTjM2QR/iqkZ+9i/wPOvLLPRJxpGqiJmsq/ExL2OhbaNx2KHcmPbkCYxet nKCrzC5K2kMBLpBOX6sayRkwEYW3WXj0q1g/g1b1q11gD4Ca0inXswyoGB5yeQuGjHxL jn6s54tjegECKz3AQlfpimuOZvSxYA6s0rPdaojBgEkJU4I2cyX6YzRQrKYrTpSSjwkj oFo6fWCRHABglnrdVwMOgcrZc1+/YRakLut6+1CCwD5q0IZKI3+TcyvFT4fwULE55NGN MVLA== X-Gm-Message-State: AOAM5320BRWoPiUTkJlQXr/zJf6ZlSVEbkX067qlNsEQcjPiWo9dh10I wp3J8lihWHoNyWPAfHQLxswF2YUVU5OXkNbh7P1efA7WxDMvjjZzACWCEOvtknJa7qiUA9JpXCW ocrrpqiV+VcAsbg== X-Received: by 2002:a1c:1941:: with SMTP id 62mr9057958wmz.131.1637237203037; Thu, 18 Nov 2021 04:06:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFsojgTDTDS9qD2uxJc1zleNYE1KqNYZH/RRs2s/DwoXu+ACYb3IKpxcewDzjG9ew7G3vzGA== X-Received: by 2002:a1c:1941:: with SMTP id 62mr9057932wmz.131.1637237202796; Thu, 18 Nov 2021 04:06:42 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Alexander Bulekov , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Darren Kenny , Prasad J Pandit , Paolo Bonzini , Laurent Vivier , Hanna Reitz , qemu-block@nongnu.org, Gaoning Pan , Kevin Wolf , Markus Armbruster , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH-for-6.2 v3 1/2] hw/block/fdc: Kludge missing floppy drive to fix CVE-2021-20196 Date: Thu, 18 Nov 2021 13:06:34 +0100 Message-Id: <20211118120635.4043197-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118120635.4043197-1-philmd@redhat.com> References: <20211118120635.4043197-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: 1637237207359100001 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. Cc: qemu-stable@nongnu.org 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 Reviewed-by: Darren Kenny Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Hanna Reitz --- 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 d21b717b7d6..6f94b6a6daa 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 device. + */ + 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 Sat May 18 22:31:10 2024 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=1637237211; cv=none; d=zohomail.com; s=zohoarc; b=CeSTgp9b2eHA1bO37auFhjFT1cfesPG81Brem0KVggNThzz3eSo7snFqzjafA9Z4wGnLaTFze4O5rhS2mTI8JCsKHxS3qQPIVO7/A3qOtnsWhlX0Aw5/LJ4NnNaY+DUx8+QU+uu6NmezS5dTbjdglDZKV0fu4/A9zY+wmVrj46w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637237211; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=r59luPWtxRlKzSRSIEGfjHStklJXogUMIUpFeVyWk9E=; b=UdWm2O1XGs+D5ZLyj1R3t6DuIWcNbylOd9g38e2L3jJ7nX0IxX41s/DsfCaP02YwptrWcuMdu4oLEdnsUTbL+INMBv+l9XEisnkOsF4IpFHjhAVz5oBw/4N7i+5ypMmjADTaVqr3i7t9keOtbzE2FvffDbEoyN/MVH3XWxVl5z8= 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 1637237211131391.55157823742286; Thu, 18 Nov 2021 04:06:51 -0800 (PST) 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-128-Qz_Yy5CUPniOBi9AHXkK3A-1; Thu, 18 Nov 2021 07:06:48 -0500 Received: by mail-wm1-f69.google.com with SMTP id o10-20020a05600c4fca00b0033312e1ed8bso3012564wmq.2 for ; Thu, 18 Nov 2021 04:06:48 -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 a22sm2855997wme.19.2021.11.18.04.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 04:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637237210; 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=r59luPWtxRlKzSRSIEGfjHStklJXogUMIUpFeVyWk9E=; b=BDYOsgbtDKIk8qvzsvJOTYrT9rhVYx7QxsE8kx2HhkPgxNpFaAPoy8gTgkSljK7xeiy0H8 coHCfptYN1c+PDY+7p1/wVITmXCYAwF61KtVRVwR30VhXiQhFuBXdxN/A1johejy9iBxL+ cdgHaT0trA9Sy/f5/mmY8savEomnV1o= X-MC-Unique: Qz_Yy5CUPniOBi9AHXkK3A-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=r59luPWtxRlKzSRSIEGfjHStklJXogUMIUpFeVyWk9E=; b=hwFEpcuPK6doCCr1bu2eYzc1lY6G83tBrYBAKDWG2spcbhJyK5fI/99yVFzdZznNeP mum7VOmXMSf63nPVByvcqiGEkiEGqOJEHwv+WK7XTcvxAVqr6wiG5C4tJoaWxGBAHSu5 sw5lZlFVEKEQc2dWvqn+LTNK5d9vr/9zsjxcDByKWJz7QJ6ol+zTcBK2p2uWudj1f2S5 3cGRzmbZGakjd8Wxu2MYIGclDEF45MH2PS18Ri2IkjsJvoKgB+8pKt/b5JM+y+1PxO3e P7na7yRIvHxbIwfYtgG7yF5HpBMwAILp8P0qg2nFYkjbg4bqh0pBMFAt6JnXweOtBx/T 5Yfw== X-Gm-Message-State: AOAM531Jqy95uU4gGHwapefyqvwuhfWYbsNUZaclajpBMGyOp6J6vdQl QAPmjZC7BMoqfMZW8zeBsL7QZwZJ7bO4dSMBqQL6BWtC9mpb0jcfZ6zTlw7SEHTaftpnh2mG0xO k2pRDHWff79n/TQ== X-Received: by 2002:a5d:4ecd:: with SMTP id s13mr31232828wrv.400.1637237207829; Thu, 18 Nov 2021 04:06:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJz02O8jhQFKBJ2/C66qdQ5YNObQuuEFiySs1in+N4oAqJxslJlPT8ziyIXH+bxhAKN10bScRQ== X-Received: by 2002:a5d:4ecd:: with SMTP id s13mr31232792wrv.400.1637237207681; Thu, 18 Nov 2021 04:06:47 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Alexander Bulekov , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Darren Kenny , Prasad J Pandit , Paolo Bonzini , Laurent Vivier , Hanna Reitz , qemu-block@nongnu.org, Gaoning Pan , Kevin Wolf , Markus Armbruster , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2 v3 2/2] tests/qtest/fdc-test: Add a regression test for CVE-2021-20196 Date: Thu, 18 Nov 2021 13:06:35 +0100 Message-Id: <20211118120635.4043197-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118120635.4043197-1-philmd@redhat.com> References: <20211118120635.4043197-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: 1637237212583100001 From: Alexander Bulekov Without the previous commit, 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 Add the reproducer for CVE-2021-20196. Signed-off-by: Alexander Bulekov Message-Id: <20210319050906.14875-2-alxndr@bu.edu> [PMD: Rebased, use global test_image] Reviewed-by: Darren Kenny Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 f164d972d10..0f8b9b753f4 100644 --- a/tests/qtest/fdc-test.c +++ b/tests/qtest/fdc-test.c @@ -565,6 +565,26 @@ static void test_cve_2021_3507(void) qtest_quit(s); } =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; @@ -596,6 +616,7 @@ int main(int argc, char **argv) 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_3507", test_cve_2021_3507); + qtest_add_func("/fdc/fuzz/cve_2021_20196", test_cve_2021_20196); =20 ret =3D g_test_run(); =20 --=20 2.31.1