Received: by 2002:a19:c345:0:0:0:0:0 with SMTP id t66csp753897lff; Wed, 11 Dec 2019 07:08:12 -0800 (PST) X-Google-Smtp-Source: APXvYqzX9GepmQgif3dedVSw+XyOZpsqK6f56ZQ2q5fAO4sRl/4mbv1vLSPKpMdW9om9JP+QOHoY X-Received: by 2002:aca:5f87:: with SMTP id t129mr3270059oib.36.1576076892414; Wed, 11 Dec 2019 07:08:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576076892; cv=none; d=google.com; s=arc-20160816; b=JTQDVlAO5j/0bFf+OMubl4qQL5PLN5sMGPbibRTrvOEiPgqi+VkbRipvlkcv8gDjyB EILv/tbKNUwvzzB0baUywllmn+fHJVxFgNdWt5CX6J34flxppHIrM2PzFij02xbxgPal GTTeqp2+CTCJ+p78BH1GtabKYcqHuMtyGiQorXo32B6B0FFdedJxyM1irSx1IxSP2UQq AFwnXo2vDFVb97GPigJJm6eddWodKhV5uO//3t+eu9ttuOlXfuDJuWCl3nL4vFggX3Bh /xcIRrxpJf64kGDoa1q7g3079rgH6ywY3RJgiHB3rOuP3jmep1mQLk8Oj64LSVhNmc+d Z3cw== 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:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=PCOnbhJypslF5hM47QeKN1c0yopkDWzpKcTM5nMU8Xo=; b=UW9vh2/TA9LMUTGutMtbRI6Sn3R9cMdbUiqGCvBA2mxrTjXRaBdDD3Xrx5df0dAs1H hviN15yEghJut7S+BMuTL7mzxoZiQ72hQbK2+TmJFgNh8pIUWOxEVYsD3w9qMUMhNPLl TInXDq8KlDLUz3KIBSMZDaja+Db/yDbiWNXBb9LGOzRS4U2ALcyIiUEItyX8XmBRs7A9 itUFeyQGS+0mqnfTEUH6THPo8gdH42EMdr8oUBFezJVn9j0751KAn3MCqMgbt+mnmD5i jCYMb3NSxmtBjFAILEYXwsSvFkzTfmw+zjTl7qI8NPCevWAHn9Mhz5bOBRxVbEGeuEoP NGWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=CDj6Mvi7; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d187si1337262oif.33.2019.12.11.07.08.12 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Dec 2019 07:08:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=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=@amazon.de header.s=amazon201209 header.b=CDj6Mvi7; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: from localhost ([::1]:43884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if3b1-0002Qk-E2 for alex.bennee@linaro.org; Wed, 11 Dec 2019 10:08:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56421) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if3ap-0002Me-7c for qemu-arm@nongnu.org; Wed, 11 Dec 2019 10:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1if3ao-0003jR-3J for qemu-arm@nongnu.org; Wed, 11 Dec 2019 10:07:59 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:24828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1if3an-0003ib-U2; Wed, 11 Dec 2019 10:07:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1576076878; x=1607612878; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=PCOnbhJypslF5hM47QeKN1c0yopkDWzpKcTM5nMU8Xo=; b=CDj6Mvi7P+4CADYQe8O5TkJhkIB8rXEMrpGN4WoS1K30AUdk6i2jNV/B MmomEoFKZaxDq1GGgoVc/Zkp+HgklLUy4tXXtWxmwCLzw4hg7CTwVz6tm xdD0sVt5WrHdahXmJKVFUxo9uJWz2+JmrjLB6RDEbkLeVdL98JZgDzwhF k=; IronPort-SDR: RWEUtVZsJacMYHqOeRxJKTi797ERWhrNiSGCdx/M2KVQwTbSZ9t73TaIVRHZabWOqmst+kEHDB 3nLBTIXiDaEw== X-IronPort-AV: E=Sophos;i="5.69,301,1571702400"; d="scan'208";a="7181881" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-baacba05.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 11 Dec 2019 15:07:55 +0000 Received: from sveith-desktop.aka.corp.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id B6585A1BEC; Wed, 11 Dec 2019 15:07:54 +0000 (UTC) Received: from sveith-desktop.aka.corp.amazon.com (localhost [127.0.0.1]) by sveith-desktop.aka.corp.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id xBBF7p0s024939; Wed, 11 Dec 2019 16:07:51 +0100 Received: (from sveith@localhost) by sveith-desktop.aka.corp.amazon.com (8.15.2/8.15.2/Submit) id xBBF7olP024913; Wed, 11 Dec 2019 16:07:50 +0100 From: Simon Veith To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: Simon Veith , Eric Auger Subject: [PATCH v2 3/6] hw/arm/smmuv3: Check stream IDs against actual table LOG2SIZE Date: Wed, 11 Dec 2019 16:07:37 +0100 Message-Id: <1576076860-24820-1-git-send-email-sveith@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576076260-18659-1-git-send-email-sveith@amazon.de> References: <1576076260-18659-1-git-send-email-sveith@amazon.de> Precedence: Bulk X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 52.95.49.90 X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: WL5yO4XysuaU When checking whether a stream ID is in range of the stream table, we have so far been only checking it against our implementation limit (SMMU_IDR1_SIDSIZE). However, the guest can program the STRTAB_BASE_CFG.LOG2SIZE field to a size that is smaller than this limit. Check the stream ID against this limit as well to match the hardware behavior of raising C_BAD_STREAMID events in case the limit is exceeded. Also, ensure that we do not go one entry beyond the end of the table by checking that its index is strictly smaller than the table size. ref. ARM IHI 0070C, section 6.3.24. Signed-off-by: Simon Veith Cc: Eric Auger Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org --- Changed in v2: * Also check that stream ID is strictly lower than the table size hw/arm/smmuv3.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index eef9a18..727558b 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -377,11 +377,15 @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *event) { dma_addr_t addr; + uint32_t log2size; int ret; trace_smmuv3_find_ste(sid, s->features, s->sid_split); - /* Check SID range */ - if (sid > (1 << SMMU_IDR1_SIDSIZE)) { + log2size = FIELD_EX32(s->strtab_base_cfg, STRTAB_BASE_CFG, LOG2SIZE); + /* + * Check SID range against both guest-configured and implementation limits + */ + if (sid >= (1 << MIN(log2size, SMMU_IDR1_SIDSIZE))) { event->type = SMMU_EVT_C_BAD_STREAMID; return -EINVAL; } -- 2.7.4