From nobody Mon Feb 9 19:05:39 2026 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=1639601834; cv=none; d=zohomail.com; s=zohoarc; b=G855HV6Idin1v5AyK6xRcn2C2BFRAFzTM8tbNPlGeA42SfMFp1bZCf54nOx2g1h31xhnvqC6Qw6k0wGV/pRl/zPb2V7qacpUX2+6Fk/RGSmfXfXfTTfHlt3spBLFXoVTubhMOKpaqYB9WrU5Ugs+HLvSXII56w1nZ1DC9aW19ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639601834; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=OOkRh2MZ/DBLfZ4HT9jmHJS4If0ihWIm6frAMrPlFV0=; b=NuosxGp7U05IE4LOU5EXYQZR4cz7i7rPLc/fVACSbT+AuMCTlFIjg4vsfTHitZSysAJ9rP4tqCe1PJvBNHxtksT1jL4yTWeYm1ZkbcOynGEZMBaNGS6JCjrvQ+6hz0bvNq104yWj89LYPICXwEPyim2hwxDUwbSPt5uWlmqE0BI= 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 1639601834030775.1546493297715; Wed, 15 Dec 2021 12:57:14 -0800 (PST) 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-499-Lg7RkmNlODaCfGPcGhlN5A-1; Wed, 15 Dec 2021 15:57:11 -0500 Received: by mail-wm1-f70.google.com with SMTP id b75-20020a1c804e000000b0034569bde713so162188wmd.9 for ; Wed, 15 Dec 2021 12:57:11 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id f15sm3521642wmg.30.2021.12.15.12.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 12:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639601833; 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=OOkRh2MZ/DBLfZ4HT9jmHJS4If0ihWIm6frAMrPlFV0=; b=eL83DB4m1h/zV+i9j2aTa2f3ZBZ/VHdKasYchAi305zxkIGmZVpZ7xGFbCqc6Rf9YV7gT9 4x8hI5El+HURHh9Vi/s2vKPkgDfrikH6GF47iA7dVRntWn3BQrxK8hv6D8gZPnR+z25Dlj eZKlsWzKaxOs1GFa/p3fBl3SULblenc= X-MC-Unique: Lg7RkmNlODaCfGPcGhlN5A-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=OOkRh2MZ/DBLfZ4HT9jmHJS4If0ihWIm6frAMrPlFV0=; b=cesEz77QtEhLArHpUgBXFTAzvF9eLryasUQbhHWvv0/9ZBbfBFLrZxYiMEz3vB/Z04 PzGwN++KCVRnIxsL1SUOc3TpkcG60EKViUqcOXtu+BSF9zctXkZt3Vs9HEhh3yxaRjOm mCXFYr0YGOpEmjtRCdhJnjVz3yEBMm0nn+4mx179BB/TnXBSSuvGsjrKo/QADJgtM/9B H29PlN02zooa4N61HtobX87oncHJev2lAObH4Q/fHdCe9/S6hru9Y/0aZRbP5K9yLesa SufFerV8JVLXLG1cBN6tgqixrQqR/gZnfndiRsQoKHdLyt6DUYEs+du6tNfUbDrynxDO rhag== X-Gm-Message-State: AOAM533+2LsyUcl1Roc7dEdokn4nwTtnrtYcqF639cnAHrirTkSGkF1F cEEVn9wUaVc/QqjTbZIgjjah6fPB4f64qwnrlV47YP/ZOZl/dBgJyHX6j2TWut/1u95ZOyzfpRy RNd151AkhT8eT3Q== X-Received: by 2002:adf:ec85:: with SMTP id z5mr1529829wrn.568.1639601830671; Wed, 15 Dec 2021 12:57:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgX1cpLtsgJ3wxILAQYLUhqa2o58p5r47g9Uo5MGHKubIQ/xUVRmrWJro6fBZy7QKMDdlylQ== X-Received: by 2002:adf:ec85:: with SMTP id z5mr1529806wrn.568.1639601830512; Wed, 15 Dec 2021 12:57:10 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Li Qiang , David Hildenbrand , Paolo Bonzini , qemu-block@nongnu.org, Gerd Hoffmann , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Darren Kenny , Peter Maydell , Peter Xu , Jason Wang , Qiuhao Li , Bandan Das , Laurent Vivier , "Edgar E . Iglesias" , Stefan Hajnoczi , Bin Meng , Alexander Bulekov Subject: [RFC PATCH 1/3] hw/sd/sdhci: Honor failed DMA transactions Date: Wed, 15 Dec 2021 21:56:54 +0100 Message-Id: <20211215205656.488940-2-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215205656.488940-1-philmd@redhat.com> References: <20211215205656.488940-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: 1639601834663100001 From: Philippe Mathieu-Daud=C3=A9 DMA transactions might fail. The DMA API returns a MemTxResult, indicating such failures. Do not ignore it. On failure, raise the ADMA error flag and eventually triggering an IRQ (see spec chapter 1.13.5: "ADMA2 States"). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- hw/sd/sdhci.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index e0bbc903446..fe2f21f0c37 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -742,6 +742,7 @@ static void sdhci_do_adma(SDHCIState *s) unsigned int begin, length; const uint16_t block_size =3D s->blksize & BLOCK_SIZE_MASK; ADMADescr dscr =3D {}; + MemTxResult res; int i; =20 if (s->trnmod & SDHC_TRNS_BLK_CNT_EN && !s->blkcnt) { @@ -790,10 +791,13 @@ static void sdhci_do_adma(SDHCIState *s) s->data_count =3D block_size; length -=3D block_size - begin; } - dma_memory_write(s->dma_as, dscr.addr, - &s->fifo_buffer[begin], - s->data_count - begin, - MEMTXATTRS_UNSPECIFIED); + res =3D dma_memory_write(s->dma_as, dscr.addr, + &s->fifo_buffer[begin], + s->data_count - begin, + MEMTXATTRS_UNSPECIFIED); + if (res !=3D MEMTX_OK) { + break; + } dscr.addr +=3D s->data_count - begin; if (s->data_count =3D=3D block_size) { s->data_count =3D 0; @@ -816,10 +820,13 @@ static void sdhci_do_adma(SDHCIState *s) s->data_count =3D block_size; length -=3D block_size - begin; } - dma_memory_read(s->dma_as, dscr.addr, - &s->fifo_buffer[begin], - s->data_count - begin, - MEMTXATTRS_UNSPECIFIED); + res =3D dma_memory_read(s->dma_as, dscr.addr, + &s->fifo_buffer[begin], + s->data_count - begin, + MEMTXATTRS_UNSPECIFIED); + if (res !=3D MEMTX_OK) { + break; + } dscr.addr +=3D s->data_count - begin; if (s->data_count =3D=3D block_size) { sdbus_write_data(&s->sdbus, s->fifo_buffer, block_= size); @@ -833,7 +840,16 @@ static void sdhci_do_adma(SDHCIState *s) } } } - s->admasysaddr +=3D dscr.incr; + if (res !=3D MEMTX_OK) { + if (s->errintstsen & SDHC_EISEN_ADMAERR) { + trace_sdhci_error("Set ADMA error flag"); + s->errintsts |=3D SDHC_EIS_ADMAERR; + s->norintsts |=3D SDHC_NIS_ERR; + } + sdhci_update_irq(s); + } else { + s->admasysaddr +=3D dscr.incr; + } break; case SDHC_ADMA_ATTR_ACT_LINK: /* link to next descriptor table */ s->admasysaddr =3D dscr.addr; --=20 2.33.1 From nobody Mon Feb 9 19:05:39 2026 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=1639601840; cv=none; d=zohomail.com; s=zohoarc; b=Bde8yLTizLH8mYQIh/eay012UKeJXZDmapiiHbwV4tTqEJlBgUczMH4A3qETuTjoLnogmaOCFVPd/3756JNtEp/44LNl9WIVogJHP9xRU1HAx7hmb1pzW1ovpV075aQOk0SpQzHmqjzLtowJqc6I1AgSQNil3lYAQuWvdLsdSOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639601840; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=oSQRyRj2GbkDloms+3kG1uqQcojtiwJxAy2G0BkB6EI=; b=LlSUbt+TS8/56vilD/e67jciakp/Vf78nWTFY8fTFtpLUrg64ELBJ7hNAbabtB5H4Eq/Mp+PkWvplsKAtAzdPhtAo/PYBej8b9+8FdrMuC/dqTt2QpZzYv+3j9Lz4mZ5I03/CkFBLNDJl8obrVnEFXC4KFz8vxhBuxwxFNn5NiQ= 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 1639601840945416.2332823186572; Wed, 15 Dec 2021 12:57:20 -0800 (PST) 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-319-O3azeY84O2-5Ps7q5dch0A-1; Wed, 15 Dec 2021 15:57:18 -0500 Received: by mail-wr1-f69.google.com with SMTP id k8-20020a5d5248000000b001763e7c9ce5so6210250wrc.22 for ; Wed, 15 Dec 2021 12:57:18 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id g124sm5980438wme.28.2021.12.15.12.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 12:57:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639601839; 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=oSQRyRj2GbkDloms+3kG1uqQcojtiwJxAy2G0BkB6EI=; b=GkhBeCBG75UYYR1GbKpyWBzn5GacPGpz8TfcJEJtTjiJIPdQnxvEhGy3ihW+O/zNVgMCSA tDxvF2aOVxluDix+DoHyx5lxGEWbSB5ZKMgvlpWbwlDph9g9Yk9ssnzkmkcT336CM6dZmd p4oDaHfBR4+HI8nIiuTPBGqr0iCkWpY= X-MC-Unique: O3azeY84O2-5Ps7q5dch0A-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=oSQRyRj2GbkDloms+3kG1uqQcojtiwJxAy2G0BkB6EI=; b=HXbIGBvRnh58sbrSBhS3tfNCd40XLhVVKiVfTeKm2ibSme6Yjk/moeWqalJAl9aBHn UsWH1EMxOusB6I5r9t/AvPDnj8HH62UrjvT+gKB99YdtBPWz8qzaoKtEaCAY9CSLbRCT 5uXNXy5M7wpaFE3OiWgLco58C2YxZDQQ4MOcg9z+ylbIWATEnZF9Nk7FeIn4JoODANBO e5lJXyuvv4sL36A5m9U07METjNpUqJeJeW0A6RF2W4c2/V3NuMlMzK9EoJtrlsEDSP0h VQjz+jN6Qjt/KVEnzivrX3UF7ffvLPK4XUpFIlRbhlM6IPGjGHsGTQRZFCwT4NfM2nqP zCsQ== X-Gm-Message-State: AOAM532+Qb2/tp8Xl4UcJfQUZB7ID2XQlHQkxaW1v5T9slMMzdfEwfRf MebPkHT+wKP3IuGuAopfplpD1cIOKoZB5w2ltmOUWrWUuYTsw+5LjkzK3D9+tSn6kKTqIim8MV7 deGzc4VfXs+avog== X-Received: by 2002:a05:600c:19cc:: with SMTP id u12mr1981838wmq.24.1639601835363; Wed, 15 Dec 2021 12:57:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb8G+oMVd86cvwguQJsJmKfSEz09jDT1yPJwprMX48giyS9Rnw06hdOAozhRSrnIbC+jMqDg== X-Received: by 2002:a05:600c:19cc:: with SMTP id u12mr1981830wmq.24.1639601835155; Wed, 15 Dec 2021 12:57:15 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Li Qiang , David Hildenbrand , Paolo Bonzini , qemu-block@nongnu.org, Gerd Hoffmann , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Darren Kenny , Peter Maydell , Peter Xu , Jason Wang , Qiuhao Li , Bandan Das , Laurent Vivier , "Edgar E . Iglesias" , Stefan Hajnoczi , Bin Meng , Alexander Bulekov Subject: [RFC PATCH 2/3] hw/sd/sdhci: Prohibit DMA accesses to devices Date: Wed, 15 Dec 2021 21:56:55 +0100 Message-Id: <20211215205656.488940-3-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215205656.488940-1-philmd@redhat.com> References: <20211215205656.488940-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: 1639601841720100001 From: Philippe Mathieu-Daud=C3=A9 The issue reported by OSS-Fuzz produces the following backtrace: =3D=3D447470=3D=3DERROR: AddressSanitizer: heap-buffer-overflow READ of size 1 at 0x61500002a080 thread T0 #0 0x71766d47 in sdhci_read_dataport hw/sd/sdhci.c:474:18 #1 0x7175f139 in sdhci_read hw/sd/sdhci.c:1022:19 #2 0x721b937b in memory_region_read_accessor softmmu/memory.c:440:11 #3 0x72171e51 in access_with_adjusted_size softmmu/memory.c:554:18 #4 0x7216f47c in memory_region_dispatch_read1 softmmu/memory.c:1424:16 #5 0x7216ebb9 in memory_region_dispatch_read softmmu/memory.c:1452:9 #6 0x7212db5d in flatview_read_continue softmmu/physmem.c:2879:23 #7 0x7212f958 in flatview_read softmmu/physmem.c:2921:12 #8 0x7212f418 in address_space_read_full softmmu/physmem.c:2934:18 #9 0x721305a9 in address_space_rw softmmu/physmem.c:2962:16 #10 0x7175a392 in dma_memory_rw_relaxed include/sysemu/dma.h:89:12 #11 0x7175a0ea in dma_memory_rw include/sysemu/dma.h:132:12 #12 0x71759684 in dma_memory_read include/sysemu/dma.h:152:12 #13 0x7175518c in sdhci_do_adma hw/sd/sdhci.c:823:27 #14 0x7174bf69 in sdhci_data_transfer hw/sd/sdhci.c:935:13 #15 0x7176aaa7 in sdhci_send_command hw/sd/sdhci.c:376:9 #16 0x717629ee in sdhci_write hw/sd/sdhci.c:1212:9 #17 0x72172513 in memory_region_write_accessor softmmu/memory.c:492:5 #18 0x72171e51 in access_with_adjusted_size softmmu/memory.c:554:18 #19 0x72170766 in memory_region_dispatch_write softmmu/memory.c:1504:= 16 #20 0x721419ee in flatview_write_continue softmmu/physmem.c:2812:23 #21 0x721301eb in flatview_write softmmu/physmem.c:2854:12 #22 0x7212fca8 in address_space_write softmmu/physmem.c:2950:18 #23 0x721d9a53 in qtest_process_command softmmu/qtest.c:727:9 A DMA descriptor is previously filled in RAM. An I/O access to the device (frames #22 to #16) start the DMA engine (frame #13). The engine fetch the descriptor and execute the request, which itself accesses the SDHCI I/O registers (frame #1 and #0), triggering a re-entrancy issue. Fix by prohibit transactions from the DMA to devices. The DMA engine is thus restricted to memories. Reported-by: OSS-Fuzz (Issue 36391) Resolves: https://gitlab.com/qemu-project/qemu/-/issues/451 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- hw/sd/sdhci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index fe2f21f0c37..0e5e988927e 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -741,6 +741,7 @@ static void sdhci_do_adma(SDHCIState *s) { unsigned int begin, length; const uint16_t block_size =3D s->blksize & BLOCK_SIZE_MASK; + const MemTxAttrs attrs =3D { .memory =3D true }; ADMADescr dscr =3D {}; MemTxResult res; int i; @@ -794,7 +795,7 @@ static void sdhci_do_adma(SDHCIState *s) res =3D dma_memory_write(s->dma_as, dscr.addr, &s->fifo_buffer[begin], s->data_count - begin, - MEMTXATTRS_UNSPECIFIED); + attrs); if (res !=3D MEMTX_OK) { break; } @@ -823,7 +824,7 @@ static void sdhci_do_adma(SDHCIState *s) res =3D dma_memory_read(s->dma_as, dscr.addr, &s->fifo_buffer[begin], s->data_count - begin, - MEMTXATTRS_UNSPECIFIED); + attrs); if (res !=3D MEMTX_OK) { break; } --=20 2.33.1 From nobody Mon Feb 9 19:05:39 2026 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=1639601846; cv=none; d=zohomail.com; s=zohoarc; b=HUf7SngFExZXeQDewcJ4V4K2I0Lh/oiab/oR7omdEnC6mIFDPNyLsFW9Bsv4Z2sessbNr/ygxSIohmKjQQ8WvCRBMIdux3bCsylngQKyOPTN862fsL7YBrzRxpoImtdKq0EHy2zrwtvAMm5SdzZeR6TrpIyAeNf0EoYuejT7708= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639601846; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=vh+8wU32JL1bhYQ0/2idBT2LvjJjYrC1aRBROqGEF/k=; b=Y6pfgQEaP4l/91fuVPFqZvqquBW7glx0FrkCJGGkihSHfP+fMC/9tDyBYyp518kvt4KGMI4KsFdrd/UwA9A9jEiVYArCAzReIOYLwWynv49m+FlQUApXChII4pGmZgvwMur/xlVtfa5LOgxpglSGXTxwjEOzRbh7kYUIwb23jdM= 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 1639601846916295.2462707290008; Wed, 15 Dec 2021 12:57:26 -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-385-3ruIVnzHMBCu4227IcsL9w-1; Wed, 15 Dec 2021 15:57:24 -0500 Received: by mail-wm1-f69.google.com with SMTP id i15-20020a05600c354f00b0034566ac865bso1326235wmq.6 for ; Wed, 15 Dec 2021 12:57:24 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id l8sm6536185wmc.40.2021.12.15.12.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 12:57:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639601845; 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=vh+8wU32JL1bhYQ0/2idBT2LvjJjYrC1aRBROqGEF/k=; b=BunEq8+TS56eQAaPtBjM+MOEW29uILZkK1yoBy54a6YHB1rXBoEMqI1jtWXosEwI7HE+zC hPgKCJ9bZ0SxOL+ME3dsZkbsNcO5DE/A1VGVJ5B51ACOlvTV6VKjyA7QWkk9BZSrlakSNV j+Q+JAmKo6xAMf4oDtSfB/si6NEDrME= X-MC-Unique: 3ruIVnzHMBCu4227IcsL9w-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=vh+8wU32JL1bhYQ0/2idBT2LvjJjYrC1aRBROqGEF/k=; b=7qfG9cP6NX1UHn8kAp4+q/oxkv0UdhOWDzAxEVREz+ghA1DL4RxWOvjfZzzPnPNnnM Ejkn0AAIfdgIpSckSMvXW/9ct/jm+vh8PoG0k4EiCtjt6/CmfwnXG1MHaAwm0+5qmEjb nHRPxMRG84Dejhn0f2Ppv5jcQTtCY8aGIxyzhU2j3xzPWOivnldGmX6hpUTvhdjvuZKc 8siL9PXf7AAwxNTKc3JpgHfkv6fPGrlsy/uXj2tdpXuVUrzSbmjFu61nphtH628IndSU cBnN/qZF2EXbMNeZdlCFAi1nwqGox/NH4WWaf7ZLmlcfoA1yUs/C2m0bJ+6um1uNuApm dkvQ== X-Gm-Message-State: AOAM531+YEhJIsGfG19BzyGYu8e4cPMz6V3GG2yX80GXdK+kUPZXfvTS mpNOmC6xtAjHj+ZGQFLzvsoYCe59nVy+e3VZV9uW6aw+X6EPbEBCvmxVL0WZ0UlUF0TwQ5tQqSS LqlGkLEqdsTk8Iw== X-Received: by 2002:a5d:59ae:: with SMTP id p14mr6189515wrr.365.1639601840207; Wed, 15 Dec 2021 12:57:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJw37XfrzBqGdGBXoqqYvYaWeB/rahHydYtiV9JcQeFcjTE+l927ViNq/rh1VthRoVcRj5lIFQ== X-Received: by 2002:a5d:59ae:: with SMTP id p14mr6189492wrr.365.1639601839998; Wed, 15 Dec 2021 12:57:19 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Li Qiang , David Hildenbrand , Paolo Bonzini , qemu-block@nongnu.org, Gerd Hoffmann , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Darren Kenny , Peter Maydell , Peter Xu , Jason Wang , Qiuhao Li , Bandan Das , Laurent Vivier , "Edgar E . Iglesias" , Stefan Hajnoczi , Bin Meng , Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 3/3] tests/qtest/fuzz-sdcard-test: Add reproducer for OSS-Fuzz (Issue 29225) Date: Wed, 15 Dec 2021 21:56:56 +0100 Message-Id: <20211215205656.488940-4-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215205656.488940-1-philmd@redhat.com> References: <20211215205656.488940-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: 1639601848480100001 Include the qtest reproducer provided by Alexander Bulekov in https://gitlab.com/qemu-project/qemu/-/issues/451. Without the previous commit, we get: $ make check-qtest-i386 ... Running test qtest-i386/fuzz-sdcard-test =3D=3D447470=3D=3DERROR: AddressSanitizer: heap-buffer-overflow on addres= s 0x61500002a080 at pc 0x564c71766d48 bp 0x7ffc126c62b0 sp 0x7ffc126c62a8 READ of size 1 at 0x61500002a080 thread T0 #0 0x564c71766d47 in sdhci_read_dataport hw/sd/sdhci.c:474:18 #1 0x564c7175f139 in sdhci_read hw/sd/sdhci.c:1022:19 #2 0x564c721b937b in memory_region_read_accessor softmmu/memory.c:440= :11 #3 0x564c72171e51 in access_with_adjusted_size softmmu/memory.c:554:18 #4 0x564c7216f47c in memory_region_dispatch_read1 softmmu/memory.c:14= 24:16 #5 0x564c7216ebb9 in memory_region_dispatch_read softmmu/memory.c:145= 2:9 #6 0x564c7212db5d in flatview_read_continue softmmu/physmem.c:2879:23 #7 0x564c7212f958 in flatview_read softmmu/physmem.c:2921:12 #8 0x564c7212f418 in address_space_read_full softmmu/physmem.c:2934:18 #9 0x564c721305a9 in address_space_rw softmmu/physmem.c:2962:16 #10 0x564c7175a392 in dma_memory_rw_relaxed include/sysemu/dma.h:89:12 #11 0x564c7175a0ea in dma_memory_rw include/sysemu/dma.h:132:12 #12 0x564c71759684 in dma_memory_read include/sysemu/dma.h:152:12 #13 0x564c7175518c in sdhci_do_adma hw/sd/sdhci.c:823:27 #14 0x564c7174bf69 in sdhci_data_transfer hw/sd/sdhci.c:935:13 #15 0x564c7176aaa7 in sdhci_send_command hw/sd/sdhci.c:376:9 #16 0x564c717629ee in sdhci_write hw/sd/sdhci.c:1212:9 #17 0x564c72172513 in memory_region_write_accessor softmmu/memory.c:4= 92:5 #18 0x564c72171e51 in access_with_adjusted_size softmmu/memory.c:554:= 18 #19 0x564c72170766 in memory_region_dispatch_write softmmu/memory.c:1= 504:16 #20 0x564c721419ee in flatview_write_continue softmmu/physmem.c:2812:= 23 #21 0x564c721301eb in flatview_write softmmu/physmem.c:2854:12 #22 0x564c7212fca8 in address_space_write softmmu/physmem.c:2950:18 #23 0x564c721d9a53 in qtest_process_command softmmu/qtest.c:727:9 0x61500002a080 is located 0 bytes to the right of 512-byte region [0x6150= 00029e80,0x61500002a080) allocated by thread T0 here: #0 0x564c708e1737 in __interceptor_calloc (qemu-system-i386+0x1e6a737) #1 0x7ff05567b5e0 in g_malloc0 (/lib64/libglib-2.0.so.0+0x5a5e0) #2 0x564c71774adb in sdhci_pci_realize hw/sd/sdhci-pci.c:36:5 SUMMARY: AddressSanitizer: heap-buffer-overflow hw/sd/sdhci.c:474:18 in s= dhci_read_dataport Shadow bytes around the buggy address: 0x0c2a7fffd3c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c2a7fffd3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c2a7fffd3e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c2a7fffd3f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c2a7fffd400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =3D>0x0c2a7fffd410:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c2a7fffd420: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2a7fffd430: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2a7fffd440: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2a7fffd450: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2a7fffd460: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Heap left redzone: fa Freed heap region: fd =3D=3D447470=3D=3DABORTING Broken pipe ERROR qtest-i386/fuzz-sdcard-test - too few tests run (expected 3, got 2) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Thomas Huth --- tests/qtest/fuzz-sdcard-test.c | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/qtest/fuzz-sdcard-test.c b/tests/qtest/fuzz-sdcard-test.c index ae14305344a..6dfe26e983c 100644 --- a/tests/qtest/fuzz-sdcard-test.c +++ b/tests/qtest/fuzz-sdcard-test.c @@ -87,6 +87,81 @@ static void oss_fuzz_36217(void) qtest_quit(s); } =20 +/* + * https://gitlab.com/qemu-project/qemu/-/issues/451 + * Used to trigger a heap buffer overflow. + */ +static void oss_fuzz_36391(void) +{ + QTestState *s; + + s =3D qtest_init(" -display none -m 4G -nodefaults -nographic" + " -device sdhci-pci,sd-spec-version=3D3" + " -device sd-card,drive=3Ddrv" + " -drive if=3Dnone,index=3D0,file=3Dnull-co://,format= =3Draw,id=3Ddrv"); + qtest_outl(s, 0xcf8, 0x80001010); + qtest_outl(s, 0xcfc, 0xe0000000); + qtest_outl(s, 0xcf8, 0x80001004); + qtest_outw(s, 0xcfc, 0x7); + qtest_bufwrite(s, 0xe0000005, "\x73", 0x1); + qtest_bufwrite(s, 0xe0000028, "\x55", 0x1); + qtest_bufwrite(s, 0xe000002c, "\x55", 0x1); + qtest_bufwrite(s, 0x0, "\x65", 0x1); + qtest_bufwrite(s, 0x7, "\x69", 0x1); + qtest_bufwrite(s, 0x8, "\x65", 0x1); + qtest_bufwrite(s, 0xf, "\x69", 0x1); + qtest_bufwrite(s, 0x10, "\x65", 0x1); + qtest_bufwrite(s, 0x17, "\x69", 0x1); + qtest_bufwrite(s, 0x18, "\x65", 0x1); + qtest_bufwrite(s, 0x1f, "\x69", 0x1); + qtest_bufwrite(s, 0x20, "\x65", 0x1); + qtest_bufwrite(s, 0x27, "\x69", 0x1); + qtest_bufwrite(s, 0x28, "\x65", 0x1); + qtest_bufwrite(s, 0x2f, "\x69", 0x1); + qtest_bufwrite(s, 0x30, "\x65", 0x1); + qtest_bufwrite(s, 0x37, "\x69", 0x1); + qtest_bufwrite(s, 0x38, "\x65", 0x1); + qtest_bufwrite(s, 0x3f, "\x69", 0x1); + qtest_bufwrite(s, 0x40, "\x65", 0x1); + qtest_bufwrite(s, 0x47, "\x69", 0x1); + qtest_bufwrite(s, 0x48, "\x65", 0x1); + qtest_bufwrite(s, 0xe000000c, "\x55", 0x1); + qtest_bufwrite(s, 0xe000000e, "\x2c", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x5b", 0x1); + qtest_bufwrite(s, 0xe0000010, "\x06\x46", 0x2); + qtest_bufwrite(s, 0x50, "\x65", 0x1); + qtest_bufwrite(s, 0x57, "\x69", 0x1); + qtest_bufwrite(s, 0x58, "\x65", 0x1); + qtest_bufwrite(s, 0x5f, "\x69", 0x1); + qtest_bufwrite(s, 0x60, "\x65", 0x1); + qtest_bufwrite(s, 0x67, "\x69", 0x1); + qtest_bufwrite(s, 0x68, "\x65", 0x1); + qtest_bufwrite(s, 0x6f, "\x69", 0x1); + qtest_bufwrite(s, 0x70, "\x65", 0x1); + qtest_bufwrite(s, 0x77, "\x69", 0x1); + qtest_bufwrite(s, 0x78, "\x65", 0x1); + qtest_bufwrite(s, 0x7f, "\x69", 0x1); + qtest_bufwrite(s, 0x80, "\x65", 0x1); + qtest_bufwrite(s, 0x87, "\x69", 0x1); + qtest_bufwrite(s, 0x88, "\x65", 0x1); + qtest_bufwrite(s, 0x8f, "\x69", 0x1); + qtest_bufwrite(s, 0x90, "\x65", 0x1); + qtest_bufwrite(s, 0x97, "\x69", 0x1); + qtest_bufwrite(s, 0x98, "\x65", 0x1); + qtest_bufwrite(s, 0xe0000026, "\x5a\x06", 0x2); + qtest_bufwrite(s, 0xe0000028, "\x46\xc0\xc9\xc9", 0x4); + qtest_bufwrite(s, 0xe0000028, "\x55", 0x1); + qtest_bufwrite(s, 0xe000002a, "\x5a", 0x1); + qtest_bufwrite(s, 0xa0, "\x65", 0x1); + qtest_bufwrite(s, 0xa5, "\xff", 0x1); + qtest_bufwrite(s, 0xa6, "\xff", 0x1); + qtest_bufwrite(s, 0xa7, "\xdf", 0x1); + qtest_bufwrite(s, 0xe000000c, "\x27", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x55", 0x1); + + qtest_quit(s); +} + int main(int argc, char **argv) { const char *arch =3D qtest_get_arch(); @@ -96,6 +171,7 @@ int main(int argc, char **argv) if (strcmp(arch, "i386") =3D=3D 0) { qtest_add_func("fuzz/sdcard/oss_fuzz_29225", oss_fuzz_29225); qtest_add_func("fuzz/sdcard/oss_fuzz_36217", oss_fuzz_36217); + qtest_add_func("fuzz/sdcard/oss_fuzz_36391", oss_fuzz_36391); } =20 return g_test_run(); --=20 2.33.1