From patchwork Thu Aug 31 10:45:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 718973 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp395456wrn; Thu, 31 Aug 2023 03:48:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYg4vPSNo/EOyQZgRuBBlm3WE74Yiad/89JhaLrhR5tvvzzoROUq5mfJguiJqi6HlAahj9 X-Received: by 2002:a05:6214:518e:b0:641:8df1:79e2 with SMTP id kl14-20020a056214518e00b006418df179e2mr3086999qvb.30.1693478913597; Thu, 31 Aug 2023 03:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693478913; cv=none; d=google.com; s=arc-20160816; b=bz4Tl0ZLJCUXWSoZKEJUusLro0bzXCJbpW252i1FIswScwsyJtnq78zuXA4QdM0dz4 006LhDsD061UsVSPI0ly14Wh+ISs9FLj+3AZQFryRZHZOsSac8nF+wvV7kYUPVa212lQ PcEvxEdjqvxJ83T9sVTzNd+w+ll591Hjvx7L6r+MeI+j60CyTr9Ov/0yEwqtpsCqbZD/ ayygL/VTF8GsA25gl5zqdxfPojTb84zFv6DBJrp3yh4DpNu05Uv5F1N6MNdE0sMhhJMa sYqkHiOCf+akbDCmJE2+vTqvdA07Szh1Dr2odWvhxarZ8kIAtqGeAIMWhQXn0Psl/WNW cBwQ== 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:to:from :dkim-signature; bh=QhVdc3OQbrieoN9KEVVJ4cHPM40QA7TFXVC/nD97cgo=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=XQ8qYpkzNFzlhXG0Mgr6MqPJ9OLy+h1tox+YnA2FZMK5ECbYAephm//ydO4s4+L4GW 1wH9I9SyVK6nyfrkF1mXr3bLkttowwgzpd1JnP0Q/49578/Sf8sB5gctyutK3AwORs51 8wDcoIwrJ3Fzncz0loAOwza77B5e224n4kHV2TF9GJ1WvZrBs/W1mrtJbKLpNCbcH6uD AK1LYJANjaU/M0//uZsUHJSfGwLPDYv1t1/aeuZL6Jh4x+yAAhiTOS5sgkaB5i3g8x4u 7+Y9F4xV+BrFhWPbKN982rOffO1bbFTki5SuN2FijiBbcPtlzauLN5PunmIWU3DAUL8w GfFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UGtXE3VU; 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 w16-20020a0ce110000000b0064f45b8c035si653521qvk.374.2023.08.31.03.48.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Aug 2023 03:48:33 -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=UGtXE3VU; 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 1qbfBL-0003rQ-5h; Thu, 31 Aug 2023 06:45:47 -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 1qbfB7-0003ZY-HJ for qemu-devel@nongnu.org; Thu, 31 Aug 2023 06:45:34 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbfB3-00044O-GL for qemu-devel@nongnu.org; Thu, 31 Aug 2023 06:45:32 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-401d24f1f27so6410015e9.1 for ; Thu, 31 Aug 2023 03:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693478728; x=1694083528; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QhVdc3OQbrieoN9KEVVJ4cHPM40QA7TFXVC/nD97cgo=; b=UGtXE3VU5X0nm5b0Ax1H1ZU+ztX2WIbCpKlHXstWtNo8aadh+Y86dn2r/lGsbVW+Ac 2g9+8pa8koz7B6bD79+Cz5aa6718k/pI/ym02flbEZLj3sAfrnkS/XMoP/cVjxtDXdan 2yxe7qfknHKiNtKt5v4Uu4u15PgeqrkPQa1Edt+xqW+zH9/Sub3WNHscml0VbMZcYeVO cKpN7S0QthAPMBLhVYJ2WO8Ykx4fyEFx7t/TkjM4NJLt+tFnKuNG3tUBzgQaPTFi2TS5 eJMTypLTtN+x5t1GH+hrQLyHzMsrtO03Wt4ziBdXhMg1Fc8oy8G4wvUXZQiGZLRwNJJ7 VkmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693478728; x=1694083528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QhVdc3OQbrieoN9KEVVJ4cHPM40QA7TFXVC/nD97cgo=; b=ViXxsLZxYeVPvVOFyc9+VoNW/bEUHSepC0OB7xs2CE7YUuYNUOZ0W94NtcDmIpMsiu PJTj4BblD69P2XEw9XZRpZAsbU2v5W5MJw+rPzHXDy87JItqhzORQdHPHR2P/piPQ+wH hiQ2CfoVUaBg7cnwoTK/XzkLkL9UKd8J2uppjZyZ2r6eM7I9qlC+iIKztZ1XcU+f6vI3 1WmNCwXZfaKDQHgguP+dH97SGpak31e6PIrZ/bERi9AVk33E8hvrwOj0/wzp+4mOczSR d+VcYCZ4MGEiXQI4qdxcnHsx4NujmAgfPfARCl5X6m5u61MjH9PS1HL0cO3TgzsC1oWi O57A== X-Gm-Message-State: AOJu0YwcDBNbptlIKaGsXnQEyYl1UE9BONa3x1yUK9WNYfzuQcRTW1pb hn5d5DICA8+NhQkpeDb7M1sLFQziU1SZd3KD6Ag= X-Received: by 2002:a05:600c:cb:b0:3f9:b430:199b with SMTP id u11-20020a05600c00cb00b003f9b430199bmr3853750wmm.15.1693478727863; Thu, 31 Aug 2023 03:45:27 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l5-20020adfe585000000b0031c71693449sm1785524wrm.1.2023.08.31.03.45.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 03:45:27 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 17/24] target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS Date: Thu, 31 Aug 2023 11:45:12 +0100 Message-Id: <20230831104519.3520658-18-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831104519.3520658-1-peter.maydell@linaro.org> References: <20230831104519.3520658-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.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=ham 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 The architecture requires (R_TYTWB) that an attempt to return from EL3 when SCR_EL3.{NSE,NS} are {1,0} is an illegal exception return. (This enforces that the CPU can't ever be executing below EL3 with the NSE,NS bits indicating an invalid security state.) We were missing this check; add it. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20230807150618.101357-1-peter.maydell@linaro.org --- target/arm/tcg/helper-a64.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c index 1c9370f07bd..0cf56f6dc44 100644 --- a/target/arm/tcg/helper-a64.c +++ b/target/arm/tcg/helper-a64.c @@ -780,6 +780,15 @@ void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc) spsr &= ~PSTATE_SS; } + /* + * FEAT_RME forbids return from EL3 with an invalid security state. + * We don't need an explicit check for FEAT_RME here because we enforce + * in scr_write() that you can't set the NSE bit without it. + */ + if (cur_el == 3 && (env->cp15.scr_el3 & (SCR_NS | SCR_NSE)) == SCR_NSE) { + goto illegal_return; + } + new_el = el_from_spsr(spsr); if (new_el == -1) { goto illegal_return;