From patchwork Thu Jun 2 21:48:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 578180 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp979401max; Thu, 2 Jun 2022 15:54:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFbTn2VPLLJlG4Mox6a10CrTCTAMaMDtOSQddaYmgVQ2Yb1A4dBriB/JOwitsaSVhMBuRj X-Received: by 2002:ac8:5a08:0:b0:2fc:56c9:db09 with SMTP id n8-20020ac85a08000000b002fc56c9db09mr5445609qta.19.1654210457145; Thu, 02 Jun 2022 15:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654210457; cv=none; d=google.com; s=arc-20160816; b=wlzLg4yFYlZT3oADJ3hTj4882XELyja+k81yFnKz7l/AklGQPY+ck4U08ynZVyKFcY sjjqVfJGrqbuNVPOkeuzyAvNJ5ZjZDvUUtoXGpcfSHMtEiPFgufY5sTseIVbnWRC8dgW mjpbZbyOZlGanCt0kZ9b0I711VDg6PdqRNNtyR1vYMOaOYWh/MQu4csEAPCXI2YzScmM KktjkT/7LPtVJpG+LcdtbBcEEzTSK1NfuDkyjXm2xkKUCL2odPwWbx3Rv1J8XbjQFykR KEIsmiJYjp6PYDfLnghsP0efMlfKPSh8H6PFVNKM+dFI936s6ULxOEy4gRGZ9jtuu/HR 8bZA== 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=G9tBDIOox4Y0NhHvT3VV3KFHeeNFnyNER4ZnNO5qAIM=; b=vK3SK8gFVWftb2+adhaJy6LVBYL7P5BUNjmcUGXjBUhda5cDJhECXyyuiXUeF6Y9nZ ivvlg/ED22b0soPWtOh7MU2Y5d5umIEOxTO9sDBPWqJQ7SWJzdGzOqSbsB93NC4BDUe+ mRFDx5Oe+k9CFokBaDpuEqevYIC1fcDU+PTx9oKupjde96GJQUwfZOpxzfhFcT1o7WE4 Jk4QKK2HfibF7HL4y9LBDcHErMbpZ8MMfS1vuF7vu7kUU0df9KHf1QFgc1y55x19irD6 2VkkefFuxdS57vTUQcdCzGY4Z5h9Q9tp9c4s60sTItsT2K5wFS3BORXrhbIg3u/XGAVk oyJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="N3/1BKJ1"; 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 g4-20020ac85804000000b002f90f63b872si2611416qtg.340.2022.06.02.15.54.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 15:54:17 -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="N3/1BKJ1"; 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]:60058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwtho-0002Sy-Ou for patch@linaro.org; Thu, 02 Jun 2022 18:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwskR-0001ip-Af for qemu-devel@nongnu.org; Thu, 02 Jun 2022 17:52:59 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:34786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwskP-0000yw-JN for qemu-devel@nongnu.org; Thu, 02 Jun 2022 17:52:55 -0400 Received: by mail-pf1-x42c.google.com with SMTP id c196so5821566pfb.1 for ; Thu, 02 Jun 2022 14:52:52 -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=G9tBDIOox4Y0NhHvT3VV3KFHeeNFnyNER4ZnNO5qAIM=; b=N3/1BKJ1Ko8TBV5VQwomspi2MMYZSTWZqHyMBd8DEEgcJHJ1Ir5g3Z7D4pf3VqMD4a K9Ijgdq30ZarfSdZyT/d52nxkThBfOaFCGhLcxV6KJsEuVeKiYlT/Dm8m5kOVjJ93+W9 +TVYltkMfUc7/6uW7TxbrrqQCrbZi893QAynu/fKqpqCJA9R351Wt7uMoL5+IENzkWha VVzWqVNJFu6cnnUwq6BLAMvRcjl8sTLe7uFisSwMNtQAyQ+bfw13iATF2RD8f2Rj3pT3 sARvnKsKcdehbvbrEbTcuzf7JZlOJfXKuR1nYf5AyLQH3qzkscK2eytaBbXsaNfE4bia R76w== 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=G9tBDIOox4Y0NhHvT3VV3KFHeeNFnyNER4ZnNO5qAIM=; b=lxZxDiayOrIzCjz085nbi7Ifpa/r4Z+hrr+bPGxkv50Ilh/o/Ni2ngl9a0IBGR5bh0 qtWjamGo1l3AWDW7X9Z17IE49m3griYqzBeFrJkUq7KiXcWX8KzWGzXwmtDTGNVGKzLg MAwF5b+r1ZpGFuYLo/gdlH66bQtIxNgk9Wgnwrx9HZNXcVrQt1h0MtmL08RilAUWlp5D ajQjVBl9Qo8+mC4dEWa8V6Be5u6X1KVxMfcY/f4RmJ9FCTzv1d+ACP8hpcJb8NQNBkOH ClxRKCmzJb1II+5uosqMTJs277rc2ICsjVw1sNrqz/h5M8KJkvsiuU70AhaLE/MReS6s 7TKA== X-Gm-Message-State: AOAM530cw8dn8MCVzwEDdnA1QEkpnAHzLcz7nsq32ue1gov4Xjv8n42e dQoLV+BTZZ0FwbFmmCyKq0bfxEbQvMabpw== X-Received: by 2002:a05:6a00:882:b0:510:a043:d4bc with SMTP id q2-20020a056a00088200b00510a043d4bcmr7156291pfj.64.1654206771596; Thu, 02 Jun 2022 14:52:51 -0700 (PDT) Received: from stoup.. (174-21-71-225.tukw.qwest.net. [174.21.71.225]) by smtp.gmail.com with ESMTPSA id e14-20020a170902ed8e00b0015edfccfdb5sm4039605plj.50.2022.06.02.14.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 14:52:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 65/71] linux-user/aarch64: Move sve record checks into restore Date: Thu, 2 Jun 2022 14:48:47 -0700 Message-Id: <20220602214853.496211-66-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220602214853.496211-1-richard.henderson@linaro.org> References: <20220602214853.496211-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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=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" 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 --- 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 711fd19701..73b15038ad 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_cached(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_cached(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;