From patchwork Wed Nov 24 16:15:34 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: 1559160 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=TwdLWuX9; 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 4HzmQF06DWz9s5P for ; Thu, 25 Nov 2021 03:18:13 +1100 (AEDT) Received: from localhost ([::1]:49488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpuyI-0003Bw-RO for incoming@patchwork.ozlabs.org; Wed, 24 Nov 2021 11:18:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpuw4-0000zA-DA for qemu-devel@nongnu.org; Wed, 24 Nov 2021 11:15:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpuw2-0005O3-4p for qemu-devel@nongnu.org; Wed, 24 Nov 2021 11:15:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637770549; 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=pAJvjWL7+9OjZK8lvdVpeV3G6cYC7dwmwUMy7U51Sis=; b=TwdLWuX9OiMsBzZPF+Jf6Ced12Fk2mOZeqyT8+NmbjghhYDITXOsQo9zOkbQtpFuUNZ4Ah joyrqXfjp3+EvsLNjEpk2me1ygBkWj/foKTHcT54HpRaIcTc23FQht2mS6w6D8I3JocFBX z8GWmMvUVeT3MH3yW+Etg4sYgPtk088= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-520--M79cWVmPWC_izr4YqlbsA-1; Wed, 24 Nov 2021 11:15:48 -0500 X-MC-Unique: -M79cWVmPWC_izr4YqlbsA-1 Received: by mail-wr1-f70.google.com with SMTP id f3-20020a5d50c3000000b00183ce1379feso619360wrt.5 for ; Wed, 24 Nov 2021 08:15:48 -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=pAJvjWL7+9OjZK8lvdVpeV3G6cYC7dwmwUMy7U51Sis=; b=s8Wn+R4hsIqISa5RwEyJZYXQ88ZifunEK4kLjG/ViEeuafb4HtZ8Dp37ndJzw5f1PM Y8AvEXUIqqQJdkWIYaAXMRgqt82hrE6PseUtBQmwv+q3CqmHB9ewczZiAM97fV8rSiIq 1htGHk9bI+Cm1qztBzNtAByu+IWxmYq2lPruTEYF6ELHRuztGcM8ir4RQWWJnl+h0Zce ZK8RhqfuCGLusiyX6TsTE4t2oWZ1KENHs3LY/ZQpw1rV+sgVNw3quv0XapB8az6BH8oP YwC3LzcapD3DBX5xJqja9QqdXS0rNAS5XPysqFfJpkjJRn4x9LqPVhA05iKa0ix8MlKc rW2g== X-Gm-Message-State: AOAM532SLwPkob7FpzznhyaYxzNzhKEY7Wdk97PfXCFALr06Y5Dl2mBH qwQ1VdOF2dYQ4RjbSLorCzEJLsALokOrIIVrvgXZDLo2e1kek9EdOefcfcNS+GtP+pPfKt3Bqju D4uI1lIeOSV8z1sYF2L8Z3YpQfMPE9IgTRzTLU8gaPenb2UKxa8KxWd0mibDIZzY5 X-Received: by 2002:a5d:44d1:: with SMTP id z17mr21038491wrr.143.1637770545915; Wed, 24 Nov 2021 08:15:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwD9RdGN6SPWCFFH8LFC0bXsyXZDyls+tWio3VN0u65oJD/MN0d2h89E97UsuseeuRigr54iw== X-Received: by 2002:a5d:44d1:: with SMTP id z17mr21037970wrr.143.1637770542794; Wed, 24 Nov 2021 08:15:42 -0800 (PST) Received: from x1w.redhat.com (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id g18sm238429wrv.42.2021.11.24.08.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 08:15:42 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v4 1/3] hw/block/fdc: Extract blk_create_empty_drive() Date: Wed, 24 Nov 2021 17:15:34 +0100 Message-Id: <20211124161536.631563-2-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211124161536.631563-1-philmd@redhat.com> References: <20211124161536.631563-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=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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Hanna Reitz , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We are going to re-use this code in the next commit, so extract it as a new blk_create_empty_drive() function. Inspired-by: Hanna Reitz Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Hanna Reitz --- hw/block/fdc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index fa933cd3263..1dbf3f6028f 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -61,6 +61,12 @@ } while (0) +/* Anonymous BlockBackend for empty drive */ +static BlockBackend *blk_create_empty_drive(void) +{ + return blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); +} + /********************************************************/ /* qdev floppy bus */ @@ -486,8 +492,7 @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) } if (!dev->conf.blk) { - /* Anonymous BlockBackend for an empty drive */ - dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); + dev->conf.blk = blk_create_empty_drive(); ret = blk_attach_dev(dev->conf.blk, qdev); assert(ret == 0); From patchwork Wed Nov 24 16:15:35 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: 1559163 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=S2mHyBY4; 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 4HzmVd43v6z9s5P for ; Thu, 25 Nov 2021 03:22:00 +1100 (AEDT) Received: from localhost ([::1]:57410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpv1w-00009I-Lr for incoming@patchwork.ozlabs.org; Wed, 24 Nov 2021 11:21:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpuwC-000182-3u for qemu-devel@nongnu.org; Wed, 24 Nov 2021 11:16:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpuw8-0005RL-5m for qemu-devel@nongnu.org; Wed, 24 Nov 2021 11:15:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637770555; 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=UWA1IDLGCZTNS+dT5T8n4DWw9F8qpa2tToMXzGyuHog=; b=S2mHyBY4m4Q17FWeMarpzp+7YnExqGxusl9fWdfwDMlh1BSUttdKtBr2fFOMp/2oJZDI3W Uq3MJG9zT9yxurUSh+YrVPmdPAdOsIS7TUOl/IXdHFcen6mDFVW9TBNkiZLEV7NRROU0hS LwWjJ5j3CU+sttnrUSi0Ct/gk7EsM7c= 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-461-4Faw_wBAMwC4l1lCe4E9DQ-1; Wed, 24 Nov 2021 11:15:51 -0500 X-MC-Unique: 4Faw_wBAMwC4l1lCe4E9DQ-1 Received: by mail-wm1-f70.google.com with SMTP id z138-20020a1c7e90000000b003319c5f9164so3248315wmc.7 for ; Wed, 24 Nov 2021 08:15:51 -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=UWA1IDLGCZTNS+dT5T8n4DWw9F8qpa2tToMXzGyuHog=; b=1UcnOcJRS07XoZ5oJtClx5FXyeOlkhB9+3A8zD/KTAfdCrGGd1wz3GhxOlfr/ZMqDc G1qYhgpoMubfWpGn6UMz/tRgnH5a4FX+zBlGQJPxW/wy8rj9c1fVpDzPdiGXWy6ic8Yk hv3C4klapTwZz22d1+YkrdlxWGjbCe2C9519kDhbGhAXfr2PBjGLQXDkvvXzdwYeStRb Q9FjOchdd1KnC36jUEHD+a5hoojykUVTmcmX9zvO/w4IRZfi4XNkxtzdvLheqGl6gCOk dZQ0TmWqldW7/Ft088vneL3isgJj+gfBvuXbmcLXwusJKOXPicYRMk0iatcih9+8VkKF 5tZQ== X-Gm-Message-State: AOAM5327+GTkz05XEuSSwqAcH4X9sdOUiecuDpdEjxE90qUoiusX5aD+ zFQfKl9XMRSqdtCVS3yuWMPKWMzljRotALBvp5Wet6fRTr1bwBkF1OsxZ69i/oUXLntoj82BNeO oi8fI6u0vsRG+v0PbLX75AkrtEKKQa8zFrltORnE+P8S8oDXjtLrjtZosn54UEC65 X-Received: by 2002:a05:600c:1e8d:: with SMTP id be13mr16646672wmb.79.1637770549979; Wed, 24 Nov 2021 08:15:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhOxWAfEOKANUCdT5gCfgNnQm4YjIS4Kb5ct9ksNwKPCyZAxhHo+ZzOqFgRDRUWtEsNYglyg== X-Received: by 2002:a05:600c:1e8d:: with SMTP id be13mr16646606wmb.79.1637770549664; Wed, 24 Nov 2021 08:15:49 -0800 (PST) Received: from x1w.redhat.com (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id o1sm234558wrn.63.2021.11.24.08.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 08:15:49 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v4 2/3] hw/block/fdc: Kludge missing floppy drive to fix CVE-2021-20196 Date: Wed, 24 Nov 2021 17:15:35 +0100 Message-Id: <20211124161536.631563-3-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211124161536.631563-1-philmd@redhat.com> References: <20211124161536.631563-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.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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , qemu-stable@nongnu.org, Darren Kenny , Hanna Reitz , Paolo Bonzini , Gaoning Pan , John Snow Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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. 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 Reviewed-by: Hanna Reitz 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 1dbf3f6028f..21d18ac2e36 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -1166,7 +1166,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 device. + */ + cur_drv->blk = blk_create_empty_drive(); + } + return cur_drv; } /* Status A register : 0x00 (read-only) */ From patchwork Wed Nov 24 16:15:36 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: 1559162 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=Kp7dozvl; 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 4HzmSQ2kQ3z9s5P for ; Thu, 25 Nov 2021 03:20:06 +1100 (AEDT) Received: from localhost ([::1]:54488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpv08-0006Vp-7R for incoming@patchwork.ozlabs.org; Wed, 24 Nov 2021 11:20:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpuwC-000184-5K for qemu-devel@nongnu.org; Wed, 24 Nov 2021 11:16:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32059) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpuw9-0005Sf-OY for qemu-devel@nongnu.org; Wed, 24 Nov 2021 11:15:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637770557; 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=zOmniXP9kECuj+4xZCjgmlfWEZPERWHw8eGdEQjANt4=; b=Kp7dozvlU1tkbI/rWTgK+Yb/GYX/9vbQ75Y5l6OC9KmuCxU4riUAR9eG4jfiqWyuXmfbHC 7yMYdR470W3Xp8/haXImepCVqCw6VV6z09OyhHocWHcrigquVIR6OeV2cATUEUV4rAkPBr 4OT2FQpvji+36I2JxiG/zWpmi+kldCE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-zG9yyS7pOrOfrZFYP9kMWw-1; Wed, 24 Nov 2021 11:15:56 -0500 X-MC-Unique: zG9yyS7pOrOfrZFYP9kMWw-1 Received: by mail-wr1-f69.google.com with SMTP id v17-20020adfedd1000000b0017c5e737b02so617383wro.18 for ; Wed, 24 Nov 2021 08:15:56 -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=zOmniXP9kECuj+4xZCjgmlfWEZPERWHw8eGdEQjANt4=; b=1HcAyb2IMIijm2ytoil/73bKUiLn90YdxVLtR5vrEq/LXMTz92AuhRtUmWVar2gPPo SqtziQQQ3Os4ppc5G/Nawoa+GNflMF5kpcImu/Bs4J4BlamDDJPkF0riE/O+d5ENu+F/ pYyz/gwYDidh8MzLzTa74uayYcIxNlr7f5tC+GjazBMua3PtP77wRWvRVQHyFHKmwYGB 9V9iVnhWTVUg18Y2tLu2DZpRPwS5lDSoiFHCRexoRrUWWcXFbnbBedPGiuC4f2WIZnzj aKY8F0sXI7T1red/4JTVMFzLj6C9lHZ/7qC1tTYuUEIPSfc01vwj+Xp8sJ6CBF3apYou WFkw== X-Gm-Message-State: AOAM531y1ajf9LyK8rXZ7Ef9WPm3Vtqzlk+P1iKeMQsUq4f1JgEwIrk/ 0VrXZTchSLqOqim8V1h/VBdyPuT6UXsI6eghqB5rKLk394zkoSt/LNhxNFttO7s2Pk5l/5qfi2k IgWYiR4afqXGAuE/vx/kyFAyCDkrH3jzMJxfl/CG5W8Z018w3y3stcDTMjfFEpJBZ X-Received: by 2002:a05:600c:4f87:: with SMTP id n7mr16705909wmq.63.1637770554672; Wed, 24 Nov 2021 08:15:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxT+NPiV38nxAR+CDUuMQ+dNp39joX1ZHPVoTiVVZ+s5jJuW5fc0L+g+XlYDRuHZYrR7mSKaA== X-Received: by 2002:a05:600c:4f87:: with SMTP id n7mr16705842wmq.63.1637770554343; Wed, 24 Nov 2021 08:15:54 -0800 (PST) Received: from x1w.redhat.com (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id x21sm4812146wmc.14.2021.11.24.08.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 08:15:53 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v4 3/3] tests/qtest/fdc-test: Add a regression test for CVE-2021-20196 Date: Wed, 24 Nov 2021 17:15:36 +0100 Message-Id: <20211124161536.631563-4-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211124161536.631563-1-philmd@redhat.com> References: <20211124161536.631563-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.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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Darren Kenny , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Alexander Bulekov , Hanna Reitz , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Without the previous commit, 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 Add the reproducer for CVE-2021-20196. Suggested-by: Alexander Bulekov Reviewed-by: Darren Kenny Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Hanna Reitz --- tests/qtest/fdc-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c index 26b69f7c5cd..8f6eee84a47 100644 --- a/tests/qtest/fdc-test.c +++ b/tests/qtest/fdc-test.c @@ -32,6 +32,9 @@ /* TODO actually test the results and get rid of this */ #define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) +#define DRIVE_FLOPPY_BLANK \ + "-drive if=floppy,file=null-co://,file.read-zeroes=on,format=raw,size=1440k" + #define TEST_IMAGE_SIZE 1440 * 1024 #define FLOPPY_BASE 0x3f0 @@ -546,6 +549,40 @@ static void fuzz_registers(void) } } +static bool qtest_check_clang_sanitizer(void) +{ +#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) + return true; +#else + g_test_skip("QEMU not configured using --enable-sanitizers"); + return false; +#endif +} +static void test_cve_2021_20196(void) +{ + QTestState *s; + + if (!qtest_check_clang_sanitizer()) { + return; + } + + s = qtest_initf("-nographic -m 32M -nodefaults " DRIVE_FLOPPY_BLANK); + + qtest_outw(s, 0x3f4, 0x0500); + qtest_outb(s, 0x3f5, 0x00); + qtest_outb(s, 0x3f5, 0x00); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outb(s, 0x3f5, 0x00); + qtest_outw(s, 0x3f1, 0x0400); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outw(s, 0x3f4, 0x0000); + qtest_outb(s, 0x3f5, 0x00); + qtest_outb(s, 0x3f5, 0x01); + qtest_outw(s, 0x3f1, 0x0500); + qtest_outb(s, 0x3f5, 0x00); + qtest_quit(s); +} + int main(int argc, char **argv) { int fd; @@ -576,6 +613,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();