From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7CE8C41535 for ; Sun, 17 Dec 2023 02:12:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E91BB6B0078; Sat, 16 Dec 2023 21:12:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E40F66B007B; Sat, 16 Dec 2023 21:12:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE1CF6B007D; Sat, 16 Dec 2023 21:12:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B8B416B0078 for ; Sat, 16 Dec 2023 21:12:43 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8D7D81C102E for ; Sun, 17 Dec 2023 02:12:43 +0000 (UTC) X-FDA: 81574686606.20.0AA6212 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) by imf10.hostedemail.com (Postfix) with ESMTP id C20D5C0012 for ; Sun, 17 Dec 2023 02:12:41 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=DI7RHyEj; spf=pass (imf10.hostedemail.com: domain of thiago.bauermann@linaro.org designates 209.85.210.41 as permitted sender) smtp.mailfrom=thiago.bauermann@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702779161; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZU4udhAe9yRwJhQWBqF+GjdBA5/uiRNgWqIJoHsE7co=; b=vf56iUsCjZVHxzJXpzOVy0citxLP7yjdw+vizkmeyhtMARY4zI7Cs/GOPOkS1h3pIxxw/g cEtNeSSOZlFwSOjmX5y+DNAb0I2LsUMfKWG26uZ0BL0o3IW7DiUztKlgDto3ApkmuWSZPR NPKVpT88djzJRnxbQvEyC0Nb4+hXCl4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702779161; a=rsa-sha256; cv=none; b=aJVQeIzTRJKkYycDtV9pZES+uyngGN0DC/qMSIWKXMkeeg31hIuSkMvNK/hGlMD/HwsbLM dv83aVZYP1zkwvnZ3g3lqKcEt+35RNv1bRIEHW6rrLHiweia3yp2LREh9yjvhsKTTBdR05 R/aZCRAGMKiAbF4oYHsSKWJHQge69qY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=DI7RHyEj; spf=pass (imf10.hostedemail.com: domain of thiago.bauermann@linaro.org designates 209.85.210.41 as permitted sender) smtp.mailfrom=thiago.bauermann@linaro.org; dmarc=pass (policy=none) header.from=linaro.org Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6da682e0a20so50634a34.0 for ; Sat, 16 Dec 2023 18:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702779161; x=1703383961; darn=kvack.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=ZU4udhAe9yRwJhQWBqF+GjdBA5/uiRNgWqIJoHsE7co=; b=DI7RHyEjgIVs9K+MB4HHCjxuJgAsWT6XmFdWSAC7uZseH+ac6Ud5GvhpcsKYJ2RqxS oRHs+gTLbXiqnaGaOgGbFdiEzi27zZzOM0H2nAuF5bmAlUMr4YXUmruF5FFpmI+D1Plt dwq4SRnoPn299LSEe1Bghl9NcCr6mzhmcb3UPHz9PbHfgeD3C2RJ1DNPR3y5ToHrldwv 1zkPKBXAbDnAhNzpEKpVhBgMr1PQwnLqeYowEcCW3CmzE0aei8ik49aSjbCIYIMKH0W9 jHVCZHCIRLmc+y710vONBfVR5tZ+kYuLq/xA5C2eHF9Yu8iMgwfFRdzEnmuMdfUVVMXI R4DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702779161; x=1703383961; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZU4udhAe9yRwJhQWBqF+GjdBA5/uiRNgWqIJoHsE7co=; b=PpJcB8v08YGO/Bry/5mkRsaBm4U1IbWRHQ7/Zz691bj4nwmJEKGAsBuIBJHZs9+Q/Q PJgQfiFcy0l3gT0OcPgvULexxngDwt8yCF/guxFTYBv+7jTTUDUE8+79oLYvPBrl3KdY PVu8v9qrmWHip3+WVBAjYjO8z7MB2gVt7XKdvz2qK1Q3LzHhYBkUvpHxjVPtXh3inugq qcxjILWjxiZcfI7y5M1eTFwrs1hUpAklZghP3AiO2VMxAPz5QMXjKaiCwbw95VAaDAnG MhDHqTreqz7FRsLkYaSabPgkgeYYuteCAMvOrcGyl6w5xXW0aY5ZvX3dyRpp2BocvO46 x6UQ== X-Gm-Message-State: AOJu0Yy8yQ+2Zta/cCuKBfuQzPjhlK/zx9XqgrfX11UbYgH6rH20c76y +dNzYWu5hF6vUE1uxgdkOZ+qag== X-Google-Smtp-Source: AGHT+IF6d0b9WINtfrmG2vZvKrSnvlJEjZ4mHUhu7B/LaY8JjOvAXCc/5DohR5MVIJGhP2NUssRkGA== X-Received: by 2002:a05:6808:128b:b0:3b9:dd5e:86f2 with SMTP id a11-20020a056808128b00b003b9dd5e86f2mr19868232oiw.13.1702779160745; Sat, 16 Dec 2023 18:12:40 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:a30f:cc0e:7239:16c3]) by smtp.gmail.com with ESMTPSA id f10-20020a170902e98a00b001d39ac5cbf7sm1784886plb.201.2023.12.16.18.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 18:12:40 -0800 (PST) References: <20231122-arm64-gcs-v7-0-201c483bd775@kernel.org> <20231122-arm64-gcs-v7-36-201c483bd775@kernel.org> User-agent: mu4e 1.10.8; emacs 29.1 From: Thiago Jung Bauermann To: Mark Brown Cc: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v7 36/39] selftests/arm64: Add GCS signal tests In-reply-to: <20231122-arm64-gcs-v7-36-201c483bd775@kernel.org> Date: Sat, 16 Dec 2023 23:12:37 -0300 Message-ID: <875y0x7f1m.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-Stat-Signature: nnud97x1br5s184jkcyditdtxzmf4ooq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C20D5C0012 X-Rspam-User: X-HE-Tag: 1702779161-789402 X-HE-Meta: U2FsdGVkX1+FWldHT1xkkdUTj6E65NLUuUHH813q2F3SGPLKIJoZucxNBX3b1M1+eAsen9RMkgeASFRHHP5YZagzwNMcj/l+eb8XknNgnDAqCwGIQZ9inmWtKGW0o35VjtwlrUng/QdbUbwkRwu1HXxwboK6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l4OSA41oi/V1zwqZw0a32sdJAmtFX9HcfI7WYv/0rsmqhpNR+VRBwgclrebddKxdA+oUnJ5MkB1kNj2ZHqhatIw/wW4eRXls3FV7EefVAkT4u9QXIlXNcSZZ7CoVaWRgOVT+Iux0j94Gbv0XNfTua7JYWmvqFTRIBLz5LoRXkSVSRiCLd6EdtzSMcSfo0F5Oqdr66VNq+DMxhzEV/MLKrNRg9XP9aeB92Br61SVk565UZID7oKTY78D46NAK X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Mark Brown writes: > diff --git a/tools/testing/selftests/arm64/signal/testcases/gcs_exception_fault.c b/tools/testing/selftests/arm64/signal/testcases/gcs_exception_fault.c > new file mode 100644 > index 000000000000..532d533592a1 > --- /dev/null > +++ b/tools/testing/selftests/arm64/signal/testcases/gcs_exception_fault.c > @@ -0,0 +1,59 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2023 ARM Limited > + */ > + > +#include > +#include > +#include > + > +#include > +#include > + > +#include "test_signals_utils.h" > +#include "testcases.h" > + > +/* This should be includable from some standard header, but which? */ > +#ifndef SEGV_CPERR > +#define SEGV_CPERR 10 > +#endif One suggestion is include/uapi/asm-generic/siginfo.h. It already has SEGV_MTEAERR and SEGV_MTESERR, as well as si_codes specific to other arches. >From there, it should find its way to glibc's sysdeps/unix/sysv/linux/bits/siginfo-consts.h. > +static int gcs_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) > +{ > + size_t offset; > + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); > + struct gcs_context *gcs; > + unsigned long expected, gcspr; > + int ret; > + > + ret = prctl(PR_GET_SHADOW_STACK_STATUS, &expected, 0, 0, 0); > + if (ret != 0) { > + fprintf(stderr, "Unable to query GCS status\n"); > + return 1; > + } > + > + /* We expect a cap to be added to the GCS in the signal frame */ > + gcspr = get_gcspr_el0(); > + gcspr -= 8; > + fprintf(stderr, "Expecting GCSPR_EL0 %lx\n", gcspr); > + > + if (!get_current_context(td, &context.uc, sizeof(context))) { > + fprintf(stderr, "Failed getting context\n"); > + return 1; > + } At this point, before any function call is made, can the test check that *(gcspr + 8) == 0? This would detect the issue I mentioned in patch 24 of gcs_restore_signal() not zeroing the location of the cap. > + fprintf(stderr, "Got context\n"); > + > + head = get_header(head, GCS_MAGIC, GET_BUF_RESV_SIZE(context), > + &offset); > + if (!head) { > + fprintf(stderr, "No GCS context\n"); > + return 1; > + } > + > + gcs = (struct gcs_context *)head; > + > + /* Basic size validation is done in get_current_context() */ > + > + if (gcs->features_enabled != expected) { > + fprintf(stderr, "Features enabled %llx but expected %lx\n", > + gcs->features_enabled, expected); > + return 1; > + } > + > + if (gcs->gcspr != gcspr) { > + fprintf(stderr, "Got GCSPR %llx but expected %lx\n", > + gcs->gcspr, gcspr); > + return 1; > + } I suggest adding a new check here to ensure that gcs->reserved == 0. > + fprintf(stderr, "GCS context validated\n"); > + td->pass = 1; > + > + return 0; > +} > + > +struct tdescr tde = { > + .name = "GCS basics", > + .descr = "Validate a GCS signal context", > + .feats_required = FEAT_GCS, > + .timeout = 3, > + .run = gcs_regs, > +}; > diff --git a/tools/testing/selftests/arm64/signal/testcases/gcs_write_fault.c b/tools/testing/selftests/arm64/signal/testcases/gcs_write_fault.c > new file mode 100644 > index 000000000000..126b1a294a29 > --- /dev/null > +++ b/tools/testing/selftests/arm64/signal/testcases/gcs_write_fault.c > @@ -0,0 +1,67 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2023 ARM Limited > + */ > + > +#include > +#include > +#include > + > +#include > +#include > + > +#include "test_signals_utils.h" > +#include "testcases.h" > + > +static uint64_t *gcs_page; > + > +#ifndef __NR_map_shadow_stack > +#define __NR_map_shadow_stack 452 > +#endif > + > +static bool alloc_gcs(struct tdescr *td) > +{ > + long page_size = sysconf(_SC_PAGE_SIZE); > + > + gcs_page = (void *)syscall(__NR_map_shadow_stack, 0, > + page_size, 0); > + if (gcs_page == MAP_FAILED) { > + fprintf(stderr, "Failed to map %ld byte GCS: %d\n", > + page_size, errno); This call is failing with EINVAL for me: # timeout set to 45 # selftests: arm64/signal: gcs_write_fault # # GCS write fault :: Normal writes to a GCS segfault # Registered handlers for all signals. # Detected MINSTKSIGSZ:4720 # Required Features: [ GCS ] supported # Incompatible Features: [] absent # Failed to map 4096 byte GCS: 22 # FAILED Testcase initialization. # ==>> completed. FAIL(0) not ok 11 selftests: arm64/signal: gcs_write_fault # exit=1 > + return false; > + } > + > + return true; > +} -- Thiago