From patchwork Thu Jun 13 12:13:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 166610 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp685721ilk; Thu, 13 Jun 2019 05:18:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPDJedrQbr72bLMOmn+bu6ffdTap9y3EQy8DFD5pSod6VukMZaQMSS8fLMhARw9+UgHWB0 X-Received: by 2002:a37:8fc4:: with SMTP id r187mr11978594qkd.113.1560428305022; Thu, 13 Jun 2019 05:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560428305; cv=none; d=google.com; s=arc-20160816; b=ip9H6zWq4eF4W9AT7Kt/pLeO+eB2Sdsv0z9RRWoXNsJW1TV+wwfDypI/nkntDE4dFs IE0PCA8LsJgzQ2xDz8ulNMTNm2JjnwCnyEdFuvl7B4UJ8CDXQfABXZfTyOUSWyJu2Neq 80zhS5zRUCoj9M5QtloH6cbJ7Tp6biXjqxXRHWrAuo40GHKSi2Yt2j2MMYg4idQYdMTa VhAMmg26ZrpDbip1dEjOv/NfCP3omBTMDYOXfjNBw34xReTHekSYkIcdEu7EGSn7MbQ4 Gput8hqY+uf0OZh56GRlpgRpUkWVgi/r0++L/yokQD6prU7gwdACgGQAo5Z4btLXBYe8 6Utg== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=jlXFJdoAtBcsrDt+RzPH/+cxhZKjIl45SfiQerQen7Q=; b=ZEgyecCiGZp9Oel1qCjI+Ly2shCTBDvWtruuxuJ2T3QPUAtFQ93yXRFGdDNkz5FpAg dxdfl7u+tzP3Kxjc1IbAr19KCt5HuR019zTrCN8nR2QpA0jYAJU9wEdqFKTcxQ7hc+fe wjHYc2n7P/YpuDnWbRZ8a0563smzWja2TMJJIH2yJXNBV2NQwcYuWO2d13JqFenDGZbW 0Zi0Jgdq8mlutop7/7/svvoOKY6uP4tIRzhZaUyv8uBgKMYfWoxV8c42tOlTTIiXyMCZ Tx3yYZCGw5sjd9NkgmZscwJq7FZviGMotOVOwtjxR0JDhJqzVV1zB/SrOqGIe35C/7eQ 9Uvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bz3uCyd+; 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=fail (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 f6si1526026qkm.111.2019.06.13.05.18.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2019 05:18:25 -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=fail header.i=@linaro.org header.s=google header.b=bz3uCyd+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbOgS-0007uq-Cn for patch@linaro.org; Thu, 13 Jun 2019 08:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58777) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbOcx-0007tl-I3 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbOcv-0003xm-B7 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:47 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:38642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbOcv-0003v1-39 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:45 -0400 Received: by mail-wr1-x443.google.com with SMTP id d18so20520750wrs.5 for ; Thu, 13 Jun 2019 05:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jlXFJdoAtBcsrDt+RzPH/+cxhZKjIl45SfiQerQen7Q=; b=bz3uCyd+MZGkEPqrwRWvQ7NPvDO1qqBasx/hS1DLa4Oy3XxwuNOZdEhqgq8V9SugnN W0M9psU3QZNedPZ9B3Ga8Ytar4fQnNoHawResRMyfVvpabH/j5xOjp6nQYqIG0iTJfOc nd4Gy2v2EWWwbFpa3sLOX8d7ZCq0afwfwsmpjhkquTkm5a3lKXk3QDaipz0OkfTjaoLR m7YdkmKU8CacDmd2UskiqcB0MyDj54CYrWtb5T4fzgtafPMVU6Av7fA47mbZsDeUQWU+ bZLTdwkoCytsxQiPJjeg1E61ryxozTh3hfmI9/51c3xu6l6z9JnwhmVopthku/sbEM30 gX7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jlXFJdoAtBcsrDt+RzPH/+cxhZKjIl45SfiQerQen7Q=; b=pNr93u7MXrBJVH+hJZDVtb9FbLrSptkneP6zQaDMGdMZnBLFkqbR1HXUaVumRpmmbn O3qJKPHQDUducNmM2lM52+yGqBjFDAqfSAU3KSZSn6J0u4rOUnN3XgNoZV0dwk/8aMxv 1fVPxd8NPybObEUaJoJMBzW1DCL5y+Xv/PA+zC5ILX6LacarpuHOWEzBO0kiq05IYztu 1cusYk+BR+IzbNscZlZPLKhLx0dDJ3Dz0UB/SLnTrn0Ee1PE03KOjqQvN61A5VaELLMn uz9Q+RUF0P4G6MG/lFkztQerN7TJz3RPg/WzPBkTPg5bRsA5s8s6fd5xjkBFM5tweGKw g9Ig== X-Gm-Message-State: APjAAAUdlAsQJ2RReHfPLwQy9nxnpq9HMKSZqDXqimL9qrWCAfj78HEO Cb0/M7cvEuxMKgfbjhpPuVvjWtSuKtZ8LQ== X-Received: by 2002:a5d:5089:: with SMTP id a9mr2459600wrt.290.1560428082247; Thu, 13 Jun 2019 05:14:42 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y6sm2010576wrp.12.2019.06.13.05.14.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 05:14:41 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 13 Jun 2019 13:13:51 +0100 Message-Id: <20190613121433.5246-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190613121433.5246-1-peter.maydell@linaro.org> References: <20190613121433.5246-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PULL 06/48] target/arm: Fix output of PAuth Auth X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" From: Richard Henderson The ARM pseudocode installs the error_code into the original pointer, not the encrypted pointer. The difference applies within the 7 bits of pac data; the result should be the sign extension of bit 55. Add a testcase to that effect. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- tests/tcg/aarch64/Makefile.target | 2 +- target/arm/pauth_helper.c | 4 +- tests/tcg/aarch64/pauth-2.c | 61 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 tests/tcg/aarch64/pauth-2.c -- 2.20.1 diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 2bb914975be..31ba9cfcaa1 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -15,7 +15,7 @@ run-fcvt: fcvt $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)") $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref) -AARCH64_TESTS += pauth-1 +AARCH64_TESTS += pauth-1 pauth-2 run-pauth-%: QEMU += -cpu max TESTS:=$(AARCH64_TESTS) diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index 7f30ae7395e..d3194f20437 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -344,9 +344,9 @@ static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, if (unlikely(extract64(test, bot_bit, top_bit - bot_bit))) { int error_code = (keynumber << 1) | (keynumber ^ 1); if (param.tbi) { - return deposit64(ptr, 53, 2, error_code); + return deposit64(orig_ptr, 53, 2, error_code); } else { - return deposit64(ptr, 61, 2, error_code); + return deposit64(orig_ptr, 61, 2, error_code); } } return orig_ptr; diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c new file mode 100644 index 00000000000..2fe030ba3da --- /dev/null +++ b/tests/tcg/aarch64/pauth-2.c @@ -0,0 +1,61 @@ +#include +#include + +asm(".arch armv8.4-a"); + +void do_test(uint64_t value) +{ + uint64_t salt1, salt2; + uint64_t encode, decode; + + /* + * With TBI enabled and a 48-bit VA, there are 7 bits of auth, + * and so a 1/128 chance of encode = pac(value,key,salt) producing + * an auth for which leaves value unchanged. + * Iterate until we find a salt for which encode != value. + */ + for (salt1 = 1; ; salt1++) { + asm volatile("pacda %0, %2" : "=r"(encode) : "0"(value), "r"(salt1)); + if (encode != value) { + break; + } + } + + /* A valid salt must produce a valid authorization. */ + asm volatile("autda %0, %2" : "=r"(decode) : "0"(encode), "r"(salt1)); + assert(decode == value); + + /* + * An invalid salt usually fails authorization, but again there + * is a chance of choosing another salt that works. + * Iterate until we find another salt which does fail. + */ + for (salt2 = salt1 + 1; ; salt2++) { + asm volatile("autda %0, %2" : "=r"(decode) : "0"(encode), "r"(salt2)); + if (decode != value) { + break; + } + } + + /* The VA bits, bit 55, and the TBI bits, should be unchanged. */ + assert(((decode ^ value) & 0xff80ffffffffffffull) == 0); + + /* + * Bits [54:53] are an error indicator based on the key used; + * the DA key above is keynumber 0, so error == 0b01. Otherwise + * bit 55 of the original is sign-extended into the rest of the auth. + */ + if ((value >> 55) & 1) { + assert(((decode >> 48) & 0xff) == 0b10111111); + } else { + assert(((decode >> 48) & 0xff) == 0b00100000); + } +} + +int main() +{ + do_test(0); + do_test(-1); + do_test(0xda004acedeadbeefull); + return 0; +}