From patchwork Tue Jun 28 04:21:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585501 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp449571mab; Mon, 27 Jun 2022 22:48:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4F8O4uiqeyIBuAuIKOVaUgj49M8z+nX5pkLTXspRh1eKWu1s9My6Tp1B+9orLO78tiPDc X-Received: by 2002:a05:622a:316:b0:31b:6818:9a5d with SMTP id q22-20020a05622a031600b0031b68189a5dmr4158169qtw.96.1656395324292; Mon, 27 Jun 2022 22:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395324; cv=none; d=google.com; s=arc-20160816; b=skSbOgarob3JcAD7udS/atY7qv8bC/m2RHdjzydTKxG35yDnjlk3FOgb5TzC/5CMXJ KSiV8YJB6ykzxhYj3bMMkV2oTeuBG6bEAsiM/TrP4qO3AjasHG5DaCv8e0Oq9lr5E7dk Td5TP+lhihfNl9AUM+V4+J9QNY3s9JoHfwFVbOS9Z3JFnKhZErNpQNWnsXNBiGreeXXj iQdFcEufz/AUkONoNHIM3jtn/YELkiOHbFa6sg0CNCQuT66xtwLnVdCEIygfCH0oBrQR FYHDz3kkqi7xo8cUPuTSRwBUfMgQbtyaclCuIW8s1ARYHnK1lqHKjvp6XEr8ZmZINMHC 7gNA== 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:cc:to :from:dkim-signature; bh=pyZCOGTvs2PmDR4WHKguGZ+NHJT+1M/Dn/XfXNcerpI=; b=0qhh6vZaKiaqGE1iGsabA2rn5FmW3JpaVfnzSWQ+ASsIWFi2ZolDnCKPMUymB++Vl4 1vn55skp+r0dzSIYpvJ05qmGhZbC+vXS5DlmfQyIsMQ1MfTQW3pSy4k8Gl7/8NfcYQ0F E6rMrfTiL3HejsY1jx+mn+tZgGaoLH7nARIG5CTInIXItRu/oxLqLr1fYIZ9yXaykmQ2 TIEZBbW213PKA4h5V+9rmoj/jbFv4lCgGDW+lTBeBPXztLzjWqUGrcxcZOoVmydgWm2Q mLZBfrVZxMg6oqigMaVDUoXNLGTv4/1wCKqV7VZM2yPPI29jiRnuMS6sRRp+qKSdDPqz H7PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vCmVON94; 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 y17-20020a05622a165100b003066da05886si7261950qtj.343.2022.06.27.22.48.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:48:44 -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=vCmVON94; 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]:56058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o645b-0006IK-Qk for patch@linaro.org; Tue, 28 Jun 2022 01:48:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o62kq-0002wY-OY for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:23:13 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:45838) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o62ko-0003y6-ES for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:23:12 -0400 Received: by mail-pf1-x42e.google.com with SMTP id 128so10862369pfv.12 for ; Mon, 27 Jun 2022 21:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pyZCOGTvs2PmDR4WHKguGZ+NHJT+1M/Dn/XfXNcerpI=; b=vCmVON94gl4G2Y+bZqxMm2Q6igB/O8sZ2JUs3RBmf801kLb5ANfdrNhXCBXTbrE6rW FWusndL4okxMTEPF4rG/gqF98GgFESQyNff6kLeV+YUKxUG0JQ3jB44UsmusDAIBDcri GyU5QzfdziOzDODjTHuV2TPgZ1fyaC3BsR+aF2KJISanHuZFu+qVYcC0a4VHyiKArgNz Yp2PcOtQwCMbv0w3bhXSXIGG1M2XfhfFFwooQn0jfaWrTn6YABzYS3KrWLcO66lKHnAE TA0l4mP5w8x1mEQrcNESjCGGIWstPNYEOQ8Ci5Ok/i1kPjvTzb9cQJXOE2S8irQZcWot 6XHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pyZCOGTvs2PmDR4WHKguGZ+NHJT+1M/Dn/XfXNcerpI=; b=1k0N6LaWqj0u0ThkIpAHAxpDLDBgdLlnaRkqc4G765IrbVCXoNppnvTEhZZBfPDjpe dvEUKC7GnK60Q0/r+Sxjlm6prWsIYJ34bOOWGYRx+D8BGG/0aDYOsQq/rFwVJcNJ7L+h /YyoK8x3F2WrZaJO1xxzVNM0nkaGoDCWdXF696Sc6RNl4VmxKZ/13y1J8eBcxU4jt9zb P2XPw5jUXL2UZaiDAI3BWPZ6nBYFZzyUl1O6JKVlIAq0hZwbVN++4wX79I1fhjk1MJlV FeIOVuvFcPVecZSU3pINDzv9B9J4ivo4sW8CL8PGh7if9nxUv7qUX3RMfH//vkqdXORn VKgw== X-Gm-Message-State: AJIora9vdGNTZmZ6n6sKcxLxcgc3NYF9JSSxePKAe/k8Zs5NF4Bk60QH QXcg5ao1IkqrZKVYF8wYvlC4xiWgbzZMlQ== X-Received: by 2002:a63:1759:0:b0:40d:5aba:4bb0 with SMTP id 25-20020a631759000000b0040d5aba4bb0mr16085440pgx.496.1656390175165; Mon, 27 Jun 2022 21:22:55 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id jg6-20020a17090326c600b0016a087cfad8sm7994929plb.264.2022.06.27.21.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:22:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 39/45] linux-user/aarch64: Move sve record checks into restore Date: Tue, 28 Jun 2022 09:51:11 +0530 Message-Id: <20220628042117.368549-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628042117.368549-1-richard.henderson@linaro.org> References: <20220628042117.368549-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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" Move the checks out of the parsing loop and into the restore function. This more closely mirrors the code structure in the kernel, and is slightly clearer. Reject rather than silently skip incorrect VL and SVE record sizes. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- linux-user/aarch64/signal.c | 51 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index 9ff79da4be..22d0b8b4ec 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -250,12 +250,36 @@ static void target_restore_fpsimd_record(CPUARMState *env, } } -static void target_restore_sve_record(CPUARMState *env, - struct target_sve_context *sve, int vq) +static bool target_restore_sve_record(CPUARMState *env, + struct target_sve_context *sve, + int size) { - int i, j; + int i, j, vl, vq; - /* Note that SVE regs are stored as a byte stream, with each byte element + if (!cpu_isar_feature(aa64_sve, env_archcpu(env))) { + return false; + } + + __get_user(vl, &sve->vl); + vq = sve_vq(env); + + /* Reject mismatched VL. */ + if (vl != vq * TARGET_SVE_VQ_BYTES) { + return false; + } + + /* Accept empty record -- used to clear PSTATE.SM. */ + if (size <= sizeof(*sve)) { + return true; + } + + /* Reject non-empty but incomplete record. */ + if (size < TARGET_SVE_SIG_CONTEXT_SIZE(vq)) { + return false; + } + + /* + * Note that SVE regs are stored as a byte stream, with each byte element * at a subsequent address. This corresponds to a little-endian load * of our 64-bit hunks. */ @@ -277,6 +301,7 @@ static void target_restore_sve_record(CPUARMState *env, } } } + return true; } static int target_restore_sigframe(CPUARMState *env, @@ -287,7 +312,7 @@ static int target_restore_sigframe(CPUARMState *env, struct target_sve_context *sve = NULL; uint64_t extra_datap = 0; bool used_extra = false; - int vq = 0, sve_size = 0; + int sve_size = 0; target_restore_general_frame(env, sf); @@ -321,15 +346,9 @@ static int target_restore_sigframe(CPUARMState *env, if (sve || size < sizeof(struct target_sve_context)) { goto err; } - if (cpu_isar_feature(aa64_sve, env_archcpu(env))) { - vq = sve_vq(env); - sve_size = QEMU_ALIGN_UP(TARGET_SVE_SIG_CONTEXT_SIZE(vq), 16); - if (size == sve_size) { - sve = (struct target_sve_context *)ctx; - break; - } - } - goto err; + sve = (struct target_sve_context *)ctx; + sve_size = size; + break; case TARGET_EXTRA_MAGIC: if (extra || size != sizeof(struct target_extra_context)) { @@ -362,8 +381,8 @@ static int target_restore_sigframe(CPUARMState *env, } /* SVE data, if present, overwrites FPSIMD data. */ - if (sve) { - target_restore_sve_record(env, sve, vq); + if (sve && !target_restore_sve_record(env, sve, sve_size)) { + goto err; } unlock_user(extra, extra_datap, 0); return 0;