From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B49E606A322 for ; Thu, 3 Dec 2026 21:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=d1YUxGeb Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZE2q-0000fN-Go; Thu, 03 Dec 2026 16:08:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZE2n-0000e4-2a for qemu-arm@nongnu.org; Thu, 03 Dec 2026 16:08:45 -0500 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 1xZE2l-0005jV-3j for qemu-arm@nongnu.org; Thu, 03 Dec 2026 16:08:44 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4a018493d57so21445e9.0 for ; Thu, 03 Dec 2026 13:08:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796332121; x=1796936921; darn=nongnu.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=xr7ApeTnLl4mRkhYr8hImhn5TLzXQS9HQ3cONu0SAG8=; b=d1YUxGeb8sliatPxbBR9frFvKPHf0zfUvHxldKiAHUPFoT4tRr5QiTwMXWNGqz6Nir A6wVT/EETtm4xSbr/I6N8N8iQAxk/oVShzn7lBRCEvV87LJTVszMYFsuC1VGokgaVjA1 NyxSwDx8GVRX6EDzIJoAH8S/yH8vOGS7OO9K4PL7TSSaSBSwpCSijVdggaeQ45zdVH1w GleOPP5SSP1O1SdEzf/2ti0+weIKhL36U7atT2OLqMyCI6ejYJtDfYEvqhESRa9s5UjC 24J0f+giuejvTKyYmbZxOQySiHt+zYIVUd1RzofbC7kAliMlTY8h5u8aTae2foH4TXSb 8EYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796332121; x=1796936921; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xr7ApeTnLl4mRkhYr8hImhn5TLzXQS9HQ3cONu0SAG8=; b=BlTKmyOJd88ZvhVUJLmjQl/FDWhCg1hc///dfoa+UHYQbrn7kB1Tra9rkCHxriuv+F F3FQ3R29ifTaxsEeG/AhmhLnsU5WYZIbGYJT18EsazvTI6iU8OtA7DL0iVdlXFYaoYYu tLPwo4Q2pZSEKph4lpMJ0WM1byXZkzvlj6iEXoeWUFVy8AK5J/+CtMl9e2nu+ilhyqiK Jd49/1/AsRqnBtKoHzWpF5ZOnCFDT8r4u7jw0IpBidJpWq+RIbTE1rEeQhB8/V4b96go vnE2MuExuMMDtInMUdCw+0yae7lnvxHKhmiJ08aMDLAc9LYzxi/KJB8GlY51NcAvKB7y 5qsA== X-Forwarded-Encrypted: i=1; AL+hErF0m/b2i4Wi7NXiUPPTXeOxfdV33czuB9AvS4HoH1pGYAz/Z5ymGRfMb0dTnsL13FxaWkobeDSksQ==@nongnu.org X-Gm-Message-State: APuU4Z+3aRVwd4gVmlhl9H8sdlGyTB0ZhjUu13CTYX+mJDkLTebmewDo 8ZASeIBg6SVCqvwjdr4ghiD+yXLWcFuMYzf1vud0VaaTDMNjNCy4XeyasUPEAQ+0kA== X-Gm-Gg: AZFdTZeu7xSygP+ux8NICwJkGQFyDjl+3mPdhYBOufEUz3xIjnmwE7+PCGbN2QAnLRw 5Tt+HNsnaW8FclE75AeAxyzP40EZ2jqS0Q76gZMqRAbV+UcOJYr1WFcN3jj86wfYl9j5tQICtkP CXa3n9Ji1lQo4CThLOORhtuiu/AJCGJP1Z9wAP8ZXXrX87pvvVaXfiQBpXjp0Os6NyGtpODTKqj lUV0J+gZsmMjqSp/hP21OdHpVkm0PgG8ebx1rferGFckMnr+P62g6LlebpNpYyF69nxtUbi/1DZ m32zFWXeZjTdwUg479+BbhIu/iJpE4OuAkwph+xkY4AoAeGLDzK7cuPzUvN4yizuaSJF8ATdn+K zQ+Y2084HsOzFsNat0ddtpxeSF0x78a2HphgCX+9xv861daN5FxB1mjsWrZdLSYmwGJBmCvITvQ FRR7PJhdOLYIwnwJp/sVUDBJ9FpQ3bWLbI0KWRaHxIIv9+oOgeEpSl6D+UWtsxAOvsNGdCmh1UX yp3vKlxSrO+cKs3IPCqG/rEoHxmb/mNv3MWYXwITf9MibKp9uOc0Y9Km2PSdDrHnhzq/OynWYT0 CaW9bOQStb4ehoeqI7MaknT1xNaGV+R6d48szQFsEsAgqEln0xqOnEfjw1/UKe1OwTiSAg== X-Received: by 2002:a05:600c:6d10:b0:4a1:e7d5:5132 with SMTP id 5b1f17b1804b1-4bbeacb08e9mr94055e9.3.1796332121122; Thu, 03 Dec 2026 13:08:41 -0800 (PST) Received: from google.com (160.193.189.35.bc.googleusercontent.com. [35.189.193.160]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d174452809sm1391975f8f.53.2026.12.03.13.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 13:08:40 -0800 (PST) Date: Thu, 3 Dec 2026 21:08:36 +0000 From: Mostafa Saleh To: Tao Tang Cc: Peter Maydell , Eric Auger , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Chao Liu , Chen Baozi , Jim MacArthur Subject: Re: [PATCH v6 29/35] hw/arm/smmuv3: Harden security checks in MMIO handlers Message-ID: References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> <20261114161949.3648535-1-tangtao1634@phytium.com.cn> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261114161949.3648535-1-tangtao1634@phytium.com.cn> Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=smostafa@google.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -144 X-Spam_score: -14.5 X-Spam_bar: -------------- X-Spam_report: (-14.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, FSL_HELO_FAKE=3.099, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sun, Nov 15, 2026 at 12:19:49AM +0800, Tao Tang wrote: > This patch hardens the security validation within the main MMIO > dispatcher functions (smmu_read_mmio and smmu_write_mmio). > > First, accesses to the Secure register space are gated by whether > SECURE_IMPL is enabled. When it is disabled, all SMMU_S_* registers are > read-as-zero and write-ignored. > > Second, the check for the input stream's security is made more robust. > It now validates not only the legacy MemTxAttrs.secure bit, but also > the .space field. This improves compatibility with Arm security space > handling. > I feel like this should be squashed with patch 26, but no strong opinion. > Signed-off-by: Tao Tang > Reviewed-by: Pierrick Bouvier > Reviewed-by: Jim MacArthur > --- > hw/arm/smmuv3.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 48 insertions(+) > > diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c > index 5c3d8b4bd98..0c367dc5221 100644 > --- a/hw/arm/smmuv3.c > +++ b/hw/arm/smmuv3.c > @@ -1455,6 +1455,12 @@ static bool smmu_strtab_base_writable(SMMUv3State *s, SMMUSecSID sec_sid) > return !smmu_enabled(s, sec_sid); > } > > +/* Check if the SMMU hardware itself implements Secure state features */ > +static inline bool smmu_hw_secure_implemented(SMMUv3State *s) > +{ > + return FIELD_EX32(s->bank[SMMU_SEC_SID_S].idr[1], S_IDR1, SECURE_IMPL); > +} > + > static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > { > SMMUState *bs = ARM_SMMU(s); > @@ -1771,6 +1777,37 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > return 0; > } > > +/* > + * Helper function for Secure register access validation. > + * > + * Follow S_IDR1.SECURE_IMPL accessibility rules for SMMU_S_*: > + * - SECURE_IMPL == 0: Secure state is not implemented; SMMU_S_* are RAZ/WI to > + * all accesses. > + * - SECURE_IMPL == 1: Non-secure accesses to SMMU_S_* are RAZ/WI. > + */ > +static bool smmu_check_secure_access(SMMUv3State *s, MemTxAttrs attrs, > + hwaddr offset, bool is_read) > +{ > + /* Check if the access is Secure */ > + if (!(attrs.space == ARMSS_Secure || ARMSS_Secure is 0 and MEMTXATTRS_UNSPECIFIED has all fields zero except "unspecified", can we check for "unspecified" also or drop the ARMSS_Secure check? Thanks, Mostafa > + attrs.secure == 1)) { > + qemu_log_mask(LOG_GUEST_ERROR, > + "%s: Non-secure %s at offset 0x%" PRIx64 "\n", > + __func__, is_read ? "read" : "write", offset); > + return false; > + } > + > + /* Check if the Secure state is implemented. */ > + if (!smmu_hw_secure_implemented(s)) { > + qemu_log_mask(LOG_GUEST_ERROR, > + "%s: Secure %s at offset 0x%" PRIx64 > + ": Secure state is not implemented\n", > + __func__, is_read ? "read" : "write", offset); > + return false; > + } > + return true; > +} > + > static bool smmuv3_reg_is_raz_wi(hwaddr offset, SMMUSecSID reg_sec_sid) > { > switch (offset) { > @@ -2065,6 +2102,11 @@ static MemTxResult smmu_write_mmio(void *opaque, hwaddr offset, uint64_t data, > * translate the Secure window to its bank-local register offsets. > */ > if (offset >= SMMU_SECURE_REG_START) { > + if (!smmu_check_secure_access(s, attrs, offset, false)) { > + trace_smmuv3_write_mmio(offset, data, size, MEMTX_OK); > + /* WI */ > + return MEMTX_OK; > + } > reg_sec_sid = SMMU_SEC_SID_S; > offset -= SMMU_SECURE_REG_START; > } > @@ -2244,6 +2286,12 @@ static MemTxResult smmu_read_mmio(void *opaque, hwaddr offset, uint64_t *data, > /* CONSTRAINED UNPREDICTABLE choice to have page0/1 be exact aliases */ > offset &= ~0x10000; > if (offset >= SMMU_SECURE_REG_START) { > + if (!smmu_check_secure_access(s, attrs, offset, true)) { > + /* RAZ */ > + *data = 0; > + trace_smmuv3_read_mmio(offset, *data, size, MEMTX_OK); > + return MEMTX_OK; > + } > reg_sec_sid = SMMU_SEC_SID_S; > offset -= SMMU_SECURE_REG_START; > } > -- > 2.34.1 >