From patchwork Tue Jun 21 20:46:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 583617 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2041926mab; Tue, 21 Jun 2022 13:50:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1slFtJjJCRWEPizgLpPp+LtGIiFaE0y/jl7NWhY6UxIoyzSyUdcRhnTyTbYnbhjnLU2RmBK X-Received: by 2002:ad4:5f4c:0:b0:470:4fd3:b091 with SMTP id p12-20020ad45f4c000000b004704fd3b091mr6448981qvg.14.1655844617847; Tue, 21 Jun 2022 13:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655844617; cv=none; d=google.com; s=arc-20160816; b=Q4qgMuPwQAe6DAoW0ECRlat7GLe9Hx0OmjthoCmm759mQJ814+Qck7riDS58gWmsWO gCF3XKNOirQ3jXiHBc339C7WSy8O5Rf87ctS5oxvmNF+uPkTRD69QX9eL+gQzbFppt2r yc/vySwguloyAtNg0+ycyEnTA04ZGGQCdem6hfv2SGoltIrQZF6091D2wL0eEVaSQl4b On6Lq7XjggS8XcL6pzy1ICCik0apWXxncVjNrzRFQRtOSWONurJneG0hV6wvyOIp5xI8 dNuAiKHl4jETAXlcMlTAAk5FN8jKADY7N0ArisdH4xW0+MoUUDIhqBUutxN6KFu5Bcif YZvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=umEK6S/Se+TnFpwCSFqpCewoOtCuj0w1ZzK12Mla/z8=; b=mD5T7OnlGXNcMQblw/H+jcx7+gNpSkVB3RjzzI5Ym5yzXI9k1kDb5w9A2+ufcRCc+z FLVsWg9M/iaRkc8au0+YDMlMSQijM9GOEIuXpP0i2u7PVMKa5pjsx1Pss4bylqjHp/TT IoDPLhGAMqKw3iefi9+V4OcuI3LhjhDbcqo6NRiUyy3T4xv+pHYWd5r/mJAvIHc6QXje sJ5CjwF/OcThLOBdYOzPm3a9DqRHKFcK4h8QMjN5Pdg8pz+czv9tzqdT2RbOgRCrwRfS CqAS25CSASMQfOCRKTB7jkESCdoBSLgC9x0SZJje7XgnNEYUjbRBKYlpyfP97WeR5HIV eVIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WKaVfkrd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6-20020a0562140d6600b0046a4b888b03si3928557qvs.544.2022.06.21.13.50.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Jun 2022 13:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WKaVfkrd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3kpF-0008Qf-BH for patch@linaro.org; Tue, 21 Jun 2022 16:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3km1-0006c5-Ed for qemu-devel@nongnu.org; Tue, 21 Jun 2022 16:46:57 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:33551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o3klv-00015s-OM for qemu-devel@nongnu.org; Tue, 21 Jun 2022 16:46:56 -0400 Received: by mail-pf1-x42f.google.com with SMTP id n12so7226648pfq.0 for ; Tue, 21 Jun 2022 13:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=umEK6S/Se+TnFpwCSFqpCewoOtCuj0w1ZzK12Mla/z8=; b=WKaVfkrdsqSPcent4ni6RsPHnU7+UaCMu7aov3WU8yhsIFhdpx4RHxb9vvMhq7Sltv GbyGkzLk+dY0OiDrGypLGksL8PXyMq5ZQuk9DWs2UQyztdl1pcmVFJcvWii1U6yuIQRQ 7FlQpC1b312vbq5B4tAOymxPeGPkMJGZVzoa7ZJ9iKYv2NyhMRZVKyHAzc2nvsxkxGsz KWO/6ZDEoNB7apJnt9pQLKuNHGbJ3ciaXaPZ11vHgqfXNBZnMLt5YPDxSIiLImJbLEX4 rtX12rWZZPKcmmK4klS70PkNLE5tOg8ER4XWAEcZb+GP0RZOyNq+/oOm+0acyny+8tuv KVMg== 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=umEK6S/Se+TnFpwCSFqpCewoOtCuj0w1ZzK12Mla/z8=; b=RYJGrYs2NhgMlDiGTjKfvf8Ja0T0iwDlybN8hA++cXQ3ODF838SayaQrGct4hdHOyn w0gdyfFkNSoZtfWH3yUYCOzR2zlfn95VQNvpAomj8TV6DQXNQfPV/PR4/88+iWTitTZD DItjYy7cPXzV2GJIb6maqVkQfNGs0VE9u761ZDiH7ccK1UEpZb3qvSgn6cwysOcPoY3F TR5U4ekB5LHJPLbMRWHIb6EqTllFLyRM1XC/eQpJMV3S5jG2ICP1ZY9fEiAlBNyo3PpK Jp38kwKWY8uMimwwpwrWDchI8fyeJsEoXoBk4cJt+YRtGJMkzitVfzRQMU7DxKHvnrKH 193Q== X-Gm-Message-State: AJIora+UjKvsmKQtmF/9IT52rd6tI05tDf9Slh6RDVMu/F8wkiWRR2g7 1VjSki/kmcyy5nYbI7VgdvwzCr3w4rkoTw== X-Received: by 2002:a63:6943:0:b0:40c:3020:d0b with SMTP id e64-20020a636943000000b0040c30200d0bmr24956919pgc.34.1655844410193; Tue, 21 Jun 2022 13:46:50 -0700 (PDT) Received: from stoup.. ([2602:47:d49e:3c01:8adc:a144:6ec2:4d71]) by smtp.gmail.com with ESMTPSA id p66-20020a625b45000000b005252defb016sm3649674pfb.122.2022.06.21.13.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 13:46:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 6/9] softmmu: Always initialize xlat in address_space_translate_for_iotlb Date: Tue, 21 Jun 2022 13:46:40 -0700 Message-Id: <20220621204643.371397-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220621204643.371397-1-richard.henderson@linaro.org> References: <20220621204643.371397-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The bug is an uninitialized memory read, along the translate_fail path, which results in garbage being read from iotlb_to_section, which can lead to a crash in io_readx/io_writex. The bug may be fixed by writing any value with zero in ~TARGET_PAGE_MASK, so that the call to iotlb_to_section using the xlat'ed address returns io_mem_unassigned, as desired by the translate_fail path. It is most useful to record the original physical page address, which will eventually be logged by memory_region_access_valid when the access is rejected by unassigned_mem_accepts. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1065 Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-Id: <20220621153829.366423-1-richard.henderson@linaro.org> --- softmmu/physmem.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index fb16be57a6..dc3c3e5f2e 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -669,7 +669,7 @@ void tcg_iommu_init_notifier_list(CPUState *cpu) /* Called from RCU critical section */ MemoryRegionSection * -address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr, +address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr, hwaddr *xlat, hwaddr *plen, MemTxAttrs attrs, int *prot) { @@ -678,6 +678,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr, IOMMUMemoryRegionClass *imrc; IOMMUTLBEntry iotlb; int iommu_idx; + hwaddr addr = orig_addr; AddressSpaceDispatch *d = qatomic_rcu_read(&cpu->cpu_ases[asidx].memory_dispatch); @@ -722,6 +723,16 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr, return section; translate_fail: + /* + * We should be given a page-aligned address -- certainly + * tlb_set_page_with_attrs() does so. The page offset of xlat + * is used to index sections[], and PHYS_SECTION_UNASSIGNED = 0. + * The page portion of xlat will be logged by memory_region_access_valid() + * when this memory access is rejected, so use the original untranslated + * physical address. + */ + assert((orig_addr & ~TARGET_PAGE_MASK) == 0); + *xlat = orig_addr; return &d->map.sections[PHYS_SECTION_UNASSIGNED]; }