From patchwork Wed Jun 15 16:38:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 581972 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp618464max; Wed, 15 Jun 2022 09:41:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tJ8bh1JT5pJwjJ2P1D8npS74ZmjRWrjacmv+YtRkq4ZBRoA5SqqqkIN8KkuS7bPPsHfEFe X-Received: by 2002:ac8:5704:0:b0:305:f15:6470 with SMTP id 4-20020ac85704000000b003050f156470mr398248qtw.414.1655311306542; Wed, 15 Jun 2022 09:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655311306; cv=none; d=google.com; s=arc-20160816; b=m+FVDg0H1MwjPgyN5P3HJYk7xPw3PLu7PgOwVgN3qXlqLgmg5jntrIWt35xObkYfdB Vsy+c/LJmFvkdKPXMLCjgcmhqJBl26vzaeVajf7TU9SRN7ORPwzC0jVdmnNuWVXvfmQZ M6M0XwQscwmGDSdp5fgYt+oUhIVQJYT9pf5hDWrrtFNhQ3Aoz2q6xMro19eXoJR18iMB OQbdGcVpyYdLJRSYIsTSdn97XLAGxK0e6B6A+gWahbNS/JHIWlUX8DHmU89XyrxsSeQO 0fYcz08/l7Yjvw7rH+efC12/Nb+stvCncvjDXHEzboSGhs2I/yjUW67XUEFvL7gaGaB/ hfWw== 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:message-id:date:subject:to:from:dkim-signature; bh=/e8HPnW6cPZQVWMnlzZxW/trXJbieQRDGjs7G9PSIq4=; b=Y//6gigTwG+z1CjW6h2rvK0mN8A5F1yAfOrElIRXHZeeJYd8OLuE2TAKGvygB5B1ng CTOotOonH0tpglbmfic3r7scmOWM1CmmZU4c9cPZ/Yw58qmPFQfm5FzqFJ1n1nQ8YSW5 H69bEjBj+hytkQ1f3SYSneBwEfcWJbJSSM0ntZtTklUxCLmtktiGPyH1yReeXSOF1FyE ynuNN9dktpdwEGcWzGSvA5k9m/GOPnAQw2F9/nUIYpL8c2HHyVBfndhdKmiAV6AWwHQi nG3rYcRJP2dxJSK0MT/iSKDJDpZB3nyErdOZ1x+86MrrXoSlxFmKpXrEUqDSy6S7z9KI KZQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ym6cRxW8; 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 v131-20020a376189000000b006a6f1c2bed6si7871686qkb.291.2022.06.15.09.41.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Jun 2022 09:41:46 -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=Ym6cRxW8; 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]:35228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1W5S-0002uB-3x for patch@linaro.org; Wed, 15 Jun 2022 12:41:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1W2s-0002rN-M2 for qemu-devel@nongnu.org; Wed, 15 Jun 2022 12:39:08 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:45942) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1W2c-0006Nc-NE for qemu-devel@nongnu.org; Wed, 15 Jun 2022 12:39:05 -0400 Received: by mail-pl1-x635.google.com with SMTP id d5so8269273plo.12 for ; Wed, 15 Jun 2022 09:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/e8HPnW6cPZQVWMnlzZxW/trXJbieQRDGjs7G9PSIq4=; b=Ym6cRxW81nwSLKl6pIMtPsDIFYQrFhGlsvrMl506bX6AlrXlgo4PBUv6FUVRGqaWtH pGAtVHhXzMQet58If2uI01fTfr3ooflbzvHMyEpwKu49Uc4nFVXBfC0pgPg4mkdd+I3c zZk018rvVcRlrAnqtajZIgVcsN1yxDb5z49dcvNwVE3910flmrLQdjSfWNmi7UM5S14w ONcKy45Uy+6CaGpPgRLoA8JQf8CAFqIRhwxjFIsSYtpeg866Pm1tMo01Rs/SD+3sPfxk hFDgyr7nuBMM/v44S5wjS2Kq1T5gUJYV2TU/gK/7FeaH10BCeiIOsZ6LqozEQqi0HOfx DmPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/e8HPnW6cPZQVWMnlzZxW/trXJbieQRDGjs7G9PSIq4=; b=HvshcyGcgalEKogxU7yRcOrFMh1IhDj90y0dXAr5m+QdkLQjuW45VvNDiaNmAn8Oxn 2thE4nHIIxrdRghi1p39rU9iVaoswydYx8prUOXTZO/1U/S6z2SMMZE3TeBNo5kiHQvP 3uyVCOUPirEwQqdFWVTIyvtUSld2HkZNfYPPrq47/w0GJ2lA/jD07qorB+GVutmTITlJ 9Oxg/DfxTKZ15NTpMxEL+iyZ4aJx9JdUiXnF18RCGFfEm/ufX65iY697Nxdb0NnBv+It XLO5FmVifSXucSzzTIS3og8hC3iBPfo3CGfgIvBhXOsoPxzkNBvYlC2FbpH/i40TSnx4 AZaA== X-Gm-Message-State: AJIora+fP5T2xRy2mp6niEXjbEmKZUXp4tEV0mG2UFsuAhqAvSODGk0C gtyjtIxE0bD7iWjiUDU63+RQv0txSycpzQ== X-Received: by 2002:a17:902:d50b:b0:165:2aa0:4b22 with SMTP id b11-20020a170902d50b00b001652aa04b22mr217218plg.131.1655311128811; Wed, 15 Jun 2022 09:38:48 -0700 (PDT) Received: from stoup.. ([192.77.111.2]) by smtp.gmail.com with ESMTPSA id e11-20020a170902ed8b00b00163f8ddf160sm9579644plj.161.2022.06.15.09.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 09:38:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] softmmu: Always initialize xlat in address_space_translate_for_iotlb Date: Wed, 15 Jun 2022 09:38:46 -0700 Message-Id: <20220615163846.313229-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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 --- softmmu/physmem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 657841eed0..fb0f0709b5 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -681,6 +681,9 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr, AddressSpaceDispatch *d = qatomic_rcu_read(&cpu->cpu_ases[asidx].memory_dispatch); + /* Record the original phys page for use by the translate_fail path. */ + *xlat = addr; + for (;;) { section = address_space_translate_internal(d, addr, &addr, plen, false);