From nobody Mon Feb 9 19:47:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693487760; cv=none; d=zohomail.com; s=zohoarc; b=DLJyc/GxGeC//H30pP5qvt35FwNxgRJi+xn/ZkjHPGdT+zyfscMes+GCM1/1dLdEebcwr78zMbbuoB70todDAVyrQdqnvSoRlu04WTYXXjOGo2YCDySRoSJgS+LomAldYi46b1G/HiFEEBuVQ1i3yWfGCFeAOyp40gAY25u+URo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693487760; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A8EundCVxScMr4tt/7YFkt/7+4fhMJQyHAWZWT88veQ=; b=aQeZUa8tDxewM9NSt3Hp2jqe8+vmkx9ZQXiQEyShkos+TlVH20wgxDJ5crsbln/qi0J3iTP77Qg7ib0FSoZoOdFbbheindTEzkoxH98Td+0LYn6/JkPeDFawQcXtjKyUmyDbclN9GI9h0kSgF/jLplE3M8mIh0BjUiDIB/0Z+L0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693487760904926.0546733134194; Thu, 31 Aug 2023 06:16:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbhLL-000895-5C; Thu, 31 Aug 2023 09:04:15 -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 1qbhHP-0005an-RZ for qemu-devel@nongnu.org; Thu, 31 Aug 2023 09:00:14 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbhHL-0006Gz-Ew for qemu-devel@nongnu.org; Thu, 31 Aug 2023 09:00:11 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31c6cd238e0so1311057f8f.0 for ; Thu, 31 Aug 2023 06:00:02 -0700 (PDT) Received: from m1x-phil.lan ([176.187.199.245]) by smtp.gmail.com with ESMTPSA id b11-20020adfee8b000000b0031aeca90e1fsm2162331wro.70.2023.08.31.06.00.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 31 Aug 2023 06:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693486801; x=1694091601; 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=A8EundCVxScMr4tt/7YFkt/7+4fhMJQyHAWZWT88veQ=; b=egQjO4qICOsafCqxEjgccVxk7EjRDY8muzWAaojzCgMDoJ4l0+gyYcxQIVffhJM1G+ TxEwGJ4AHMmLSqZf86FCglZO/IbL5vypGVaWM3iSAkpyYcTpn7j9qOEiZJelY74dN+Nr ehaBWXOHgHohegynh3rhOvrB5fh62grEzBGhFsSuATbpKJCcoQS/iTINU8kQb/uyc4fp eMCKbSKmojcq7XKkZR7VBtwPgwq7GpXCzdZRjT2oxnwmF85ZYSCam2zWrw9qguJlG0YU upeks5kYZawH7xdnm5RKEMgFVZ8nKkhqwUN7whvRwGzFr4IMpf2NV2mJXuBxCAJ3GcfP F7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693486801; x=1694091601; 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=A8EundCVxScMr4tt/7YFkt/7+4fhMJQyHAWZWT88veQ=; b=W/8PTWM/tZTtfULKivEjUEIGcHz4vw4p9lkJi0dF+YMHtL/10MB63s+vCn0/x7xQho xTXRO4IPYwEaYuwlix8dfrTSu7yff2+fegnQYQCNZCwOJtMhWNgytRnEgBijpTwMDjac x9oMUzG+dQyCqtpAnuJBf6KRkKbEy4wnkMc21iy0afACm01J0IxQXNxLV4DgyaHf3zx8 l/z94vAuHn9l62jT3LDfik/yNFsjivo5Ial9wgdBmI6zbC58Rjk3+RKKdJfqHqvaYoHb 396eMPR/hPJbmKMbdtwpZkJZ56ECae+O4RfIJFeh0FGP15gZvoEajDd7/nsS49tVW1nT zesQ== X-Gm-Message-State: AOJu0YycCUlFuwGPmyVGH6WLGYXKZ/kZpCbsDHaGNkKxin6c9JmkPr7A jMbNm98oyD3Q710wDq5yL53usomO2OKxlmIYslU= X-Google-Smtp-Source: AGHT+IFgSAu7Yr1XlZV8tyfY4LMZJaXQxlIrz2p714/LOnR17cYws3TVIMXVnJ20fntcAAVtdIkUkg== X-Received: by 2002:a5d:44d2:0:b0:317:f3fd:21b0 with SMTP id z18-20020a5d44d2000000b00317f3fd21b0mr1976615wrr.7.1693486801382; Thu, 31 Aug 2023 06:00:01 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-block@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Subject: [PULL 32/41] hw/usb/hcd-xhci: Avoid variable-length array in xhci_get_port_bandwidth() Date: Thu, 31 Aug 2023 14:56:34 +0200 Message-ID: <20230831125646.67855-33-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230831125646.67855-1-philmd@linaro.org> References: <20230831125646.67855-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philmd@linaro.org; helo=mail-wr1-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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693487762944100001 From: Peter Maydell In xhci_get_port_bandwidth(), we use a variable-length array to construct the buffer to send back to the guest. Avoid the VLA by using dma_memory_set() to directly request the memory system to fill the guest memory with a string of '80's. The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527). Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <20230824164818.2652452-1-peter.maydell@linaro.org> --- hw/usb/hcd-xhci.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index b89b618ec2..324177ad5d 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2434,7 +2434,6 @@ static void xhci_detach_slot(XHCIState *xhci, USBPort= *uport) static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx) { dma_addr_t ctx; - uint8_t bw_ctx[xhci->numports+1]; =20 DPRINTF("xhci_get_port_bandwidth()\n"); =20 @@ -2442,11 +2441,10 @@ static TRBCCode xhci_get_port_bandwidth(XHCIState *= xhci, uint64_t pctx) =20 DPRINTF("xhci: bandwidth context at "DMA_ADDR_FMT"\n", ctx); =20 - /* TODO: actually implement real values here */ - bw_ctx[0] =3D 0; - memset(&bw_ctx[1], 80, xhci->numports); /* 80% */ - if (dma_memory_write(xhci->as, ctx, bw_ctx, sizeof(bw_ctx), - MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + /* TODO: actually implement real values here. This is 80% for all port= s. */ + if (stb_dma(xhci->as, ctx, 0, MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK || + dma_memory_set(xhci->as, ctx + 1, 80, xhci->numports, + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "%s: DMA memory write failed!\n", __func__); return CC_TRB_ERROR; --=20 2.41.0