From patchwork Fri May 31 12:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 800534 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp711252wrw; Fri, 31 May 2024 05:47:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU/VVzaK2BUV/j1fwxw5e16w471xifOlKnuCASU0IQmRW3S/aoSB1w7a9bECYOFe2TQ1OefivcFYUquzRlswysV X-Google-Smtp-Source: AGHT+IGcdm930aT8BtfNlctMklG+mzAcKn7t68IfUQQpqlm7YSDFzCqEAIFYDQfYd7oDuDBsI124 X-Received: by 2002:ac8:7f4f:0:b0:43f:ee14:c1a5 with SMTP id d75a77b69052e-43ff52320a7mr17255841cf.10.1717159632407; Fri, 31 May 2024 05:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717159632; cv=none; d=google.com; s=arc-20160816; b=smvfBRf8+vUhxD5gC+BskJksjpOq3AtB1zjrub5jh+rPksnq4BX9dtgNisaGm2Fxcu d2xS08aVXHwZt2v8oZgbzGbAgmCXcPLUhw4Tat41Fjf4xsiaVrdZKfuC79odv6Mrf2Vu dRZgktwhHGRXOoS23b73FJUAIZ3N0difLnZIQ20/lC+tKmZug2n/VoRg0b2KuDKEH1ej VYdRpuMsCAtUc+Bkxvnrfn6Li6R1huLTvxZ7u71XsnN0N9yYKChqPlHN/bRk3R94TJL3 B1K7jNkWYb8jtFpMeyli4e+4aHNls7EbIwbfeQjoXndQcKETk99bueVpHSQTY97AZQWq ES4A== 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:cc:to:from:dkim-signature; bh=KNkb3HO1mvzGdO6PMr4OlLUGGePFzcV+YKoXtQ1aEQw=; fh=lq2K7GCmUYN6fWSt5B0CJHA0vBuKN99VA6CJwBcG/B0=; b=LlgdAI1HBdbHevE+x9xFD6lz5DTAvr+kz3sh2ccPMyZ2OCvHENmTKuj4AEOOwfU7/k 2rm0lXShZyVPAWAaX2uhCP1Xty4leahRG/4MDA4VB9no/WZfkey/UrreUudy+lyy7LAK uthPi2AXxpGddgmZOeeJk1r0rFcwpWNpsqR2DWdVFyu5qOONZj2PQIqTfihJd5EMVZVk kGWdkE5fQtN4GeaFzbyGTqfK51ISyuZLvtDSTOVfkVYJ0Q0Sf8T+NtR7CwqX9CVzuiBo 0i4xalphipAJurE5Ql6yyPcZtVF1Nd9WRCo644oVxx/Mi3l3P4ZWDB1Os8Qy9tWgpy5O KBug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jJ2Dxt+e; 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 d75a77b69052e-43ff258293csi17751731cf.501.2024.05.31.05.47.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 May 2024 05:47:12 -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=jJ2Dxt+e; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sD1eV-0008HY-C0; Fri, 31 May 2024 08:46:35 -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 1sD1eT-0008H7-OS for qemu-devel@nongnu.org; Fri, 31 May 2024 08:46:33 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sD1eS-0002vQ-3Q for qemu-devel@nongnu.org; Fri, 31 May 2024 08:46:33 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so11238185e9.1 for ; Fri, 31 May 2024 05:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717159590; x=1717764390; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KNkb3HO1mvzGdO6PMr4OlLUGGePFzcV+YKoXtQ1aEQw=; b=jJ2Dxt+elG1xV10f1wiisVgRyrKsAh2rMAhHlxr6AbD8HnHoKDexktJmrIlFXf/qs6 9q1pGZXCd3P5oJ0npy1eBvlHiIUQcmYnx+MWI0o/q1vtcXaAWXj4zd57rnzD5ddWHJyp CT68oRyYZg4zLSyoQ8fwaWtrqONEoD8BbWU0fjmjLgKiZoq4zruvftlC6ds6gnVVK5pQ Bpza0G4j8OD4RYrgbqKtaSov4M4GIaUPcCIN42fPj7b+IOGV3av9sAXsflws9UnEcDWh tfiZbXCP+po7U1qccRDXb7N44DBNHqndRR99BBkJ6s97JKAvNaaadoeMiWhizqrJzymm vjsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717159590; x=1717764390; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KNkb3HO1mvzGdO6PMr4OlLUGGePFzcV+YKoXtQ1aEQw=; b=pzq3+MwVpq9uKbOtvtM5sPYePbetmqCG2sQZhJxLlBZsc+1hzNoJwaNh/UKw4PkXYh m63HwEs73XVL/kigtiMP/h14oP+owHOOMp3WO7bCUIp06jL7HultUzjzi+smwVB7Sqw2 eM66AucphZaJHB9PwnxP7OGltg5YOudHhrQf2aET7P1R9v5Sx2R6ZvJb2ZKQbYFvnbEj cI53XauXMvjS/l6bZrGNryTMAjrXVmFRtsxKBU0XLpN4z8Yh2nrU/HK/pMCkaYF9KLsk 4FjgXc1zOqRwwaoyoORV3eDtsvs/pVT5hnZ+poKJzc4+bweZfMZa4YVY+JrySRE1CgN7 k3Ew== X-Forwarded-Encrypted: i=1; AJvYcCVaD8pOcFh/CAYsOqcCf/rkhjZDrRIm8QTkK7qPzuIrkytp1HYw9TcFPEGG1HIQB9Jdp5H+lUymu3IwS3po1HocMdNhZVQ= X-Gm-Message-State: AOJu0YzC7DpgLYwGCEPjkyJu7W7j4fsbz4e6O5Js+G/jk1GWT7qmg60D CqGuQdPMNGnrjg2OVdsn7uVhdj//FqOB7tFBYausYpMkc9XVJrtTz6b98F1BWArO252oF4zLOXY A X-Received: by 2002:a05:600c:444e:b0:421:29c0:b6c9 with SMTP id 5b1f17b1804b1-42129c0b9bbmr35328005e9.12.1717159590354; Fri, 31 May 2024 05:46:30 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42132471e01sm10905625e9.13.2024.05.31.05.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 05:46:29 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Alistair Francis , "Edgar E. Iglesias" , Alexandra Diupina Subject: [PATCH] hw/dma/xlnx_dpdma: Read descriptor into buffer, not into pointer-to-buffer Date: Fri, 31 May 2024 13:46:28 +0100 Message-Id: <20240531124628.476938-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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=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 In fdf029762f501 we factored out the handling of reading and writing DMA descriptors from guest memory. Unfortunately we accidentally made the descriptor-read read the descriptor into the address of the buffer rather than into the buffer, because we didn't notice we needed to update the arguments to the dma_memory_read() call. Before the refactoring, "&desc" is the address of a local struct DPDMADescriptor variable in xlnx_dpdma_start_operation(), which is the correct target for the guest-memory-read. But after the refactoring 'desc' is the "DPDMADescriptor *desc" argument to the new function, and so it is already an address. This bug is an overrun of a stack variable, since a pointer is at most 8 bytes long and we try to read 64 bytes, as well as being incorrect behaviour. Pass 'desc' rather than '&desc' as the dma_memory_read() argument to fix this. (The same bug is not present in xlnx_dpdma_write_descriptor(), because there we are writing the descriptor from a local struct variable "DPDMADescriptor tmp_desc" and so passing &tmp_desc to dma_memory_write() is correct.) Spotted by Coverity: CID 1546649 Fixes: fdf029762f50101 ("xlnx_dpdma: fix descriptor endianness bug") Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Edgar E. Iglesias --- hw/dma/xlnx_dpdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/dma/xlnx_dpdma.c b/hw/dma/xlnx_dpdma.c index dde4aeca401..a685bd28bb8 100644 --- a/hw/dma/xlnx_dpdma.c +++ b/hw/dma/xlnx_dpdma.c @@ -619,7 +619,7 @@ static MemTxResult xlnx_dpdma_read_descriptor(XlnxDPDMAState *s, DPDMADescriptor *desc) { MemTxResult res = dma_memory_read(&address_space_memory, desc_addr, - &desc, sizeof(DPDMADescriptor), + desc, sizeof(DPDMADescriptor), MEMTXATTRS_UNSPECIFIED); if (res) { return res;