From nobody Thu Feb 22 16:28:04 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tgdq92n2Vz59wGH; Thu, 22 Feb 2024 16:28:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tgdq9153Lz4K3j; Thu, 22 Feb 2024 16:28:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708619285; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6uYSW5/MuKNuTgNhkDC4M4uthACp0GYN8IGvo7oPLh0=; b=WJ4bp/+WxHuu2nWfE45YEZrhX3TMvYz1T+p7DFDyMTxUD8/M2XmSSB1Y5odCucg4gtNmRf jTY8oKX5WqSUMZI+21HNam/15S4bEmY0Jc7vS4QeETHaBaDyJUJ/YjtIV7qlXJRoxlWMBq XoNWy7l0xH2G603HIC306HoVmelhCAqb90Z9Cj3b/8d+IGsZTEwMvqp8jgtwbB2tmGdgWi fa5mx1tvZMITIZud9xJ3gdGoHpHlZ+sj+KbgNcT6J5tPhlZJWypwjgBPA9JXhxv5WGsTFr S9NV9dMbpFuLz6smVt1BMD1YpM8JsII2yUhpdkgqdPJ8u5wbB9Ggo+UnekVsFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708619285; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6uYSW5/MuKNuTgNhkDC4M4uthACp0GYN8IGvo7oPLh0=; b=JxrXF1npXN0mQRdHgJmRWhr0boE29ydst1Ql+I7bgsnRe9TKUZ1O9F1DLhTox2kQo5wp+e dtfGvkvscGiCiwXvQvVEZrDw4lT9huY8VhTYOhd9M/3UrU19RugV6+2WC+pVKHfft66KP/ A45J3DBCXzHZm9BVtl/AVPtg9AcOZQkGKqGA2JydHVB7hCxhkSCVbj7qqWrSUJ59iW3zC4 cOfCT8W3KTvI2DM0fCI01AHmCYVWAT/Vh0mz/nvxdjk0qUHUorCwBZmxvbqa8sP/h7ztz/ 1KUpmOjH5MNiv5tt0IS91R44d4xaUXZJnABIp11gNgpYXoL92CLMdyrG+1svaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708619285; a=rsa-sha256; cv=none; b=Cersl54WwLAO1lGbNJdisPKLf1B1COq13yqqYRI5mPZqwleLt8X3pJZoSMWuEWNyyT3dG2 c8bqRS15d6HPWPf9+Hu7Kq/cpDPTDa8XBJ+8nQksxNED0M6URZmZXvDA0+HZZ/YMxGsicF g+FXJU1bsnNnhez224UHUk3NBtNiDOmf8zojFYgX8hzYY8FERsRqh+r1LzqBmjXI5+Z4Rn 4ugeCj7PPueMxFwqZ6SHuLlyuJ/Q3ZRGmgsyUPeqFj+OnoFIQDS/4yXzowTKFWDJI0/Y/N PP9gGa9Iggs8qV1vIAc6bg8pYoBO5+VHVd06j/IqLSO2WxVhg/TyTnZQ4Q/8cw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tgdq909W4zfVN; Thu, 22 Feb 2024 16:28:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41MGS4Gg015371; Thu, 22 Feb 2024 16:28:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41MGS4Wp015368; Thu, 22 Feb 2024 16:28:04 GMT (envelope-from git) Date: Thu, 22 Feb 2024 16:28:04 GMT Message-Id: <202402221628.41MGS4Wp015368@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: c4e4a7596beb - main - Add a BTI sysarch List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c4e4a7596beb488b4878e9fa2a67cf49e330f78b Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=c4e4a7596beb488b4878e9fa2a67cf49e330f78b commit c4e4a7596beb488b4878e9fa2a67cf49e330f78b Author: Andrew Turner AuthorDate: 2023-04-05 12:45:19 +0000 Commit: Andrew Turner CommitDate: 2024-02-22 16:27:47 +0000 Add a BTI sysarch This is used to enable the guard page when an elf binary is built with BTI instructions. Reviewed by: markj Sponsored by: Arm Ltd Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39453 --- sys/arm64/arm64/sys_machdep.c | 43 ++++++++++++++++++++++++++++++++++++++++++- sys/arm64/include/sysarch.h | 7 +++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/sys/arm64/arm64/sys_machdep.c b/sys/arm64/arm64/sys_machdep.c index 79546d29e251..eedc57f7c572 100644 --- a/sys/arm64/arm64/sys_machdep.c +++ b/sys/arm64/arm64/sys_machdep.c @@ -29,13 +29,54 @@ #include #include +#include #include +#include +#include +#include + #include +#include int sysarch(struct thread *td, struct sysarch_args *uap) { + struct arm64_guard_page_args gp_args; + vm_offset_t eva; + int error; + + switch (uap->op) { + case ARM64_GUARD_PAGE: + error = copyin(uap->parms, &gp_args, sizeof(gp_args)); + if (error != 0) + return (error); + + /* Only accept canonical addresses, no PAC or TBI */ + if (!ADDR_IS_CANONICAL(gp_args.addr)) + return (EINVAL); + + eva = gp_args.addr + gp_args.len; + + /* Check for a length overflow */ + if (gp_args.addr > eva) + return (EINVAL); + + /* Check in the correct address space */ + if (eva >= VM_MAX_USER_ADDRESS) + return (EINVAL); + + /* Nothing to do */ + if (gp_args.len == 0) + return (0); + + error = pmap_bti_set(vmspace_pmap(td->td_proc->p_vmspace), + trunc_page(gp_args.addr), round_page(eva)); + break; + default: + error = EINVAL; + break; + } - return (ENOTSUP); + return (error); } diff --git a/sys/arm64/include/sysarch.h b/sys/arm64/include/sysarch.h index 2bd45d384743..83094943423a 100644 --- a/sys/arm64/include/sysarch.h +++ b/sys/arm64/include/sysarch.h @@ -39,6 +39,13 @@ #ifndef _MACHINE_SYSARCH_H_ #define _MACHINE_SYSARCH_H_ +#define ARM64_GUARD_PAGE 0x100 + +struct arm64_guard_page_args { + __uintptr_t addr; + __size_t len; +}; + #ifndef _KERNEL __BEGIN_DECLS