From patchwork Wed Jul 31 21:25:01 2024 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: 815672 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp922977wrs; Wed, 31 Jul 2024 14:25:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXRbHxcJKeFpE/u9pkEKkozfh8Or6mN1p5BqrLWNzYO9lcPN8heyXoaenL2+48zV4Jm38XjmkPNH1bpY8XcUnoo X-Google-Smtp-Source: AGHT+IGgauGpX3lz67u2YUtNFubYYQUnFjrLb+swIWs093Q4ZuOBd8gU0zNp2vCJXL6bq8YIgcul X-Received: by 2002:a05:622a:14a:b0:450:190:4fcb with SMTP id d75a77b69052e-4515eacfff9mr7393871cf.54.1722461157313; Wed, 31 Jul 2024 14:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722461157; cv=none; d=google.com; s=arc-20160816; b=M90H/D+GT+ksCrzq8+5iprKGsSLTvvp+AOt3L6hPQS7Oo+ytTOUfNZdpPkucdwssH6 fTDy+n10hidf1uHbuePB2Wy63OkWi5stMxmZilS8tXBkMqgchFI2MsCM+eR5l2t+fHK6 zOsgUCY26ywyqtfNFnbdxD9F4KN+O6pxKjY2A7FD91BIBuEJLz5yDmv5ZN1o46ibh+iY 99FPtIVFge+Y3A6IfCMooxg75dJFAGvD9aynvDU6e9rka5eQ8pigok6g2O7OCkY/CnS5 3YGHTSVNGAKm1/fFxTb1+UKoEsuEwSEuOBjSWlCh862XRJG34lfsPZt3UP+1kbt8TJHA FXMw== 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=DSCKNCS385Z7tdy/qq25A1b3soTdqIksx3r0Ajnm5Pk=; fh=yOu5dapRURptSyjkN+g0g4yQ8oVoqKjFkqaXuI7wjXc=; b=XX6dwuUC4lZb04gh55h7hAcL99ehgZ0wfaO+oxKDguyBFBwFhNGRpM98y0i3bpOdMI gvODzaIdrYfT6CInzvVQe1g3dfB7/5iCOZm/+VABPiLUbqBLvHJrlISWAWFtyrcg5ugz sR/6OfaRE8VSfKifG9Wi/g/Vkv/ZPTZRw1TlDjZqHuYLw21aH/bNaVbCLe6wvKekM2k1 dCGC9qW+QoBWoVDL6ExUtrdNP83avRst9jwVvSN2AqdtNHW7XjENQKi2bxj+AYpJhK5F hc4tG9ijkolVjufxzV9GMTvKOYrGkEdDqSC01Rze1GgPazv6AU6MYLyv87cimMUpYP7n dbiQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sz8jzUAL; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-44fe852c37asi167794571cf.710.2024.07.31.14.25.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2024 14:25:57 -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=sz8jzUAL; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZGpF-0000D8-PC; Wed, 31 Jul 2024 17:25:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sZGpD-00008b-GP for qemu-devel@nongnu.org; Wed, 31 Jul 2024 17:25:35 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZGpB-0002Ha-3X for qemu-devel@nongnu.org; Wed, 31 Jul 2024 17:25:35 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3685a5e7d3cso3542580f8f.1 for ; Wed, 31 Jul 2024 14:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722461131; x=1723065931; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DSCKNCS385Z7tdy/qq25A1b3soTdqIksx3r0Ajnm5Pk=; b=sz8jzUALidOE1rs3PV9L2UlPNZKnPs8R3QqJU+M5g6um9MLDJUo7DYq9pbzd9ztBJY IGB1Q+neZOO6YDdDHN27cO77jnmpiB2xWlyyS9jkRD+MrPP1OuOVyk28elTkIcvqIop6 7W/VDtryzqxM3Bmber7JlqpNmaO7E+ajRKWwdT8T9B6F5uImeJN918/a3Fea/ZyOlE1M oESrz9NMgNHENh9pGh/PFx0RHCRVHGYUFtgcFYqixl339+5bmKY97J01k7iC00vHhfJW 6ETNWtym/3KHlYBxu9vXK7EBI8yVUPYubNiu+IABCQ7iKtTVnvSYxPA3retzqA6kLAkX vylA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722461131; x=1723065931; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DSCKNCS385Z7tdy/qq25A1b3soTdqIksx3r0Ajnm5Pk=; b=SdSYwlfVyeEh8dIOMRkYLDVApvcJqeytz58Qj5eAWKwvcY1v3A60MT0TlMqvwvtop/ E6EJ5lu1HTFwJ2d7uiOh2jgqCHJz78NNZ2KPUs4LCA+EuuM1hELm+HVYSir56tdpTXaM L6cCGaeTAbVBKbd6bWSKV+LVU+7l4c08GYNmx4F/mJbsDQ3TxXjTH4zmlHYRq0bwsw2K 6+qoFSwkRWNl2VLhb8XZ2RCIiVTxHkIwGcbAUnyk3ucSmdFZsQ0ftiOFydlzFUfFgEZ5 /bxmIq7j8lUy87hADbJdAULXCDba8OMgBil2taWd2vDy5xmeVyVraR2iP3fKTU7BDrrL iF1g== X-Gm-Message-State: AOJu0Yw4vd0Acmf0kJkwfEdD7iGun3lrQsWXla4OwfACDQfbnooMDFnM mKNbV33lx0Ps8UaXByNmpOILUnZnPb+TfsgtAdzKPVaZpN48lSPcC4KoELo49LTRE13bougT0mM d X-Received: by 2002:adf:f6c4:0:b0:367:8e53:7fd7 with SMTP id ffacd0b85a97d-36baace2a4cmr402984f8f.28.1722461130582; Wed, 31 Jul 2024 14:25:30 -0700 (PDT) Received: from m1x-phil.lan ([176.176.130.148]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367d95c7sm17825028f8f.37.2024.07.31.14.25.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 31 Jul 2024 14:25:30 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , qemu-stable@nongnu.org Subject: [PATCH-for-9.1? v2 4/4] hw/sd/sdhci: Check ADMA descriptors can be accessed Date: Wed, 31 Jul 2024 23:25:01 +0200 Message-ID: <20240731212501.44385-5-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731212501.44385-1-philmd@linaro.org> References: <20240731212501.44385-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.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 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Since malicious guest can write invalid addresses to the ADMASYSADDR register, we need to check whether the descriptor could be correctly filled or not. Cc: qemu-stable@nongnu.org Fixes: d7dfca0807 ("hw/sdhci: introduce standard SD host controller") Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sdhci.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 2d8fa3151a..6794ee2267 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -701,13 +701,18 @@ static void trace_adma_description(const char *type, const ADMADescr *dscr) static void get_adma_description(SDHCIState *s, ADMADescr *dscr) { hwaddr entry_addr = (hwaddr)s->admasysaddr; + MemTxResult res; + switch (SDHC_DMA_TYPE(s->hostctl1)) { case SDHC_CTRL_ADMA2_32: { uint64_t adma2 = 0; - dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2), - MEMTXATTRS_UNSPECIFIED); + res = dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2), + MEMTXATTRS_UNSPECIFIED); + if (res != MEMTX_OK) { + break; + } adma2 = le64_to_cpu(adma2); /* * The spec does not specify endianness of descriptor table. @@ -724,8 +729,11 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr) { uint32_t adma1 = 0; - dma_memory_read(s->dma_as, entry_addr, &adma1, sizeof(adma1), - MEMTXATTRS_UNSPECIFIED); + res = dma_memory_read(s->dma_as, entry_addr, &adma1, sizeof(adma1), + MEMTXATTRS_UNSPECIFIED); + if (res != MEMTX_OK) { + break; + } adma1 = le32_to_cpu(adma1); dscr->addr = (hwaddr)(adma1 & ~0xfff); dscr->attr = (uint8_t)extract32(adma1, 0, 7); @@ -748,8 +756,11 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr) } QEMU_PACKED adma2; QEMU_BUILD_BUG_ON(sizeof(adma2) != 12); - dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2), - MEMTXATTRS_UNSPECIFIED); + res = dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2), + MEMTXATTRS_UNSPECIFIED); + if (res != MEMTX_OK) { + break; + } dscr->length = le16_to_cpu(adma2.length); dscr->addr = le64_to_cpu(adma2.addr); dscr->attr = adma2.attr & (uint8_t) ~0xc0;