From nobody Sun Apr 07 23:57:08 2024 X-Original-To: dev-commits-src-main@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 4VCTfX59rmz5FbZT; Sun, 7 Apr 2024 23:57:08 +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 4VCTfX3w40z4CRJ; Sun, 7 Apr 2024 23:57:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712534228; 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=bTnVLFr5w6+kzsCtMetmfcsjsW877+yxbmsgZcgZukU=; b=QWAzMEFyKATMMCV75AcXKT7aQPPnWOrZk3vAft7C7xTHyBfVozKXkhIqpD30PFTp7XUdtZ 4sv8mo/gZHtbBG5E0pyTs2jIiXhvINsxXDayLD57u5NZ4STaTYLd9ccO+7NFnKp/bpSHm0 96dhSg2gTWlhayWUU9Kk+l6AVg889eGy0ueXxeCNK5CIS1OYWt5pxBxdGOio46voB0kUY1 ji2GvcI28NsMcHYhacmBbT7rz/ThxL7nWa10JsD+AA/y5BbB9mpYXuMsgufkvG86nsA8Vj 20t2AyEfgmorueTXGu7hmyJ35a9yBwEnQKsvkrAGK5qY+yJbn9d5p6k6n+ER2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712534228; a=rsa-sha256; cv=none; b=wEghMyECyIsS3O5aQGx7J/j3g4Nb1oJgSM/wppohysrt8hNL8LH9QmCETPdPJScTE4fxhN F7aD14EYH53b0la3aSrG4ltbJyzZLXvP994xeJXSMVhxe40vvDHvFzS14UreL5sp+TkhB7 Hdrrw37cXza7uVt+Cqv9Zi3ZLSff64HaTPlcWz8qX7iAQo2yAnX3a/xL5pUhVYIbA2VzK6 dgQ04SCF5RWQJvgnYhavwpS005DWTFgdMT56ZvpG6QyV0EcIusWRCiYuF79plpdZezWJYi 4pqH03D5v8A9QcEqwZDSO3Ke2rR3k6R1NqFxqwt8UKBE2mU7copSvmqqE5v1tg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712534228; 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=bTnVLFr5w6+kzsCtMetmfcsjsW877+yxbmsgZcgZukU=; b=L3a5KxAERDQwsGLlI4nHSo38wHubgIG99a9LAQpml04TvcND7HCJfJ7SpumAnUFg293QXv yKjBEd+oUBw0kEwCkSOARmbl6+iB59gJ4s35KcojSVqV2ZKHSuqCjdIr67y5Hd6Bg7vA3J vnM8VSnSr/D0o+AmH8u4LxsKWNsRQE/UTKYwN36o1vzpctSPqgYio7KAv3AtLeFDAsPMcm JyASmeRfqXyWr68iS3Dz7ZcI4Cy5hUiMSm7WIHlMWc82BZ5/DY6PCkR2wpg0XwLeISAZej /+DAkpmVZr3Mgxr/URjN+j+Izir4O8CAGFHcYYSLoL9NSkxB4MBD8vOLrZCeMw== 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 4VCTfX3XC7zpPx; Sun, 7 Apr 2024 23:57:08 +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 437Nv8og037429; Sun, 7 Apr 2024 23:57:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 437Nv8Ge037426; Sun, 7 Apr 2024 23:57:08 GMT (envelope-from git) Date: Sun, 7 Apr 2024 23:57:08 GMT Message-Id: <202404072357.437Nv8Ge037426@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jake Freeland Subject: git: 05296a0ff615 - main - ktrace: Record syscall violations with KTR_CAPFAIL List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jfree X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 05296a0ff615566d25c77c5e6619b08724d2eecb Auto-Submitted: auto-generated The branch main has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=05296a0ff615566d25c77c5e6619b08724d2eecb commit 05296a0ff615566d25c77c5e6619b08724d2eecb Author: Jake Freeland AuthorDate: 2024-04-06 18:31:18 +0000 Commit: Jake Freeland CommitDate: 2024-04-07 23:52:51 +0000 ktrace: Record syscall violations with KTR_CAPFAIL Report syscalls that are not allowed in capability mode with CAPFAIL_SYSCALL. Reviewed by: markj Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D40678 --- sys/amd64/amd64/sys_machdep.c | 52 +++++++++++++++++++++---------------------- sys/arm/arm/sys_machdep.c | 27 ++++++++++------------ sys/i386/i386/sys_machdep.c | 34 +++++++++++++--------------- sys/kern/kern_descrip.c | 2 ++ sys/kern/kern_sig.c | 12 +++++++--- sys/kern/subr_syscall.c | 11 +++++---- 6 files changed, 71 insertions(+), 67 deletions(-) diff --git a/sys/amd64/amd64/sys_machdep.c b/sys/amd64/amd64/sys_machdep.c index dd4eef610147..b626925e1ea1 100644 --- a/sys/amd64/amd64/sys_machdep.c +++ b/sys/amd64/amd64/sys_machdep.c @@ -187,35 +187,33 @@ sysarch(struct thread *td, struct sysarch_args *uap) * explicitly indicate whether or not the operation is safe to * perform in capability mode. */ - if (IN_CAPABILITY_MODE(td)) { - switch (uap->op) { - case I386_GET_LDT: - case I386_SET_LDT: - case I386_GET_IOPERM: - case I386_GET_FSBASE: - case I386_SET_FSBASE: - case I386_GET_GSBASE: - case I386_SET_GSBASE: - case I386_GET_XFPUSTATE: - case I386_SET_PKRU: - case I386_CLEAR_PKRU: - case AMD64_GET_FSBASE: - case AMD64_SET_FSBASE: - case AMD64_GET_GSBASE: - case AMD64_SET_GSBASE: - case AMD64_GET_XFPUSTATE: - case AMD64_SET_PKRU: - case AMD64_CLEAR_PKRU: - break; + switch (uap->op) { + case I386_GET_LDT: + case I386_SET_LDT: + case I386_GET_IOPERM: + case I386_GET_FSBASE: + case I386_SET_FSBASE: + case I386_GET_GSBASE: + case I386_SET_GSBASE: + case I386_GET_XFPUSTATE: + case I386_SET_PKRU: + case I386_CLEAR_PKRU: + case AMD64_GET_FSBASE: + case AMD64_SET_FSBASE: + case AMD64_GET_GSBASE: + case AMD64_SET_GSBASE: + case AMD64_GET_XFPUSTATE: + case AMD64_SET_PKRU: + case AMD64_CLEAR_PKRU: + break; - case I386_SET_IOPERM: - default: -#ifdef KTRACE - if (KTRPOINT(td, KTR_CAPFAIL)) - ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL); -#endif + case I386_SET_IOPERM: + default: + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SYSCALL, &uap->op); + if (IN_CAPABILITY_MODE(td)) return (ECAPMODE); - } + break; } #endif diff --git a/sys/arm/arm/sys_machdep.c b/sys/arm/arm/sys_machdep.c index bf738ed77a67..50cdc4158517 100644 --- a/sys/arm/arm/sys_machdep.c +++ b/sys/arm/arm/sys_machdep.c @@ -175,22 +175,19 @@ sysarch(struct thread *td, struct sysarch_args *uap) * explicitly indicate whether or not the operation is safe to * perform in capability mode. */ - if (IN_CAPABILITY_MODE(td)) { - switch (uap->op) { - case ARM_SYNC_ICACHE: - case ARM_DRAIN_WRITEBUF: - case ARM_SET_TP: - case ARM_GET_TP: - case ARM_GET_VFPSTATE: - break; - - default: -#ifdef KTRACE - if (KTRPOINT(td, KTR_CAPFAIL)) - ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL); -#endif + switch (uap->op) { + case ARM_SYNC_ICACHE: + case ARM_DRAIN_WRITEBUF: + case ARM_SET_TP: + case ARM_GET_TP: + case ARM_GET_VFPSTATE: + break; + + default: + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SYSCALL, &uap->op); + if (IN_CAPABILITY_MODE(td)) return (ECAPMODE); - } } #endif diff --git a/sys/i386/i386/sys_machdep.c b/sys/i386/i386/sys_machdep.c index 2da60bd438d1..e29d98a61cb9 100644 --- a/sys/i386/i386/sys_machdep.c +++ b/sys/i386/i386/sys_machdep.c @@ -152,26 +152,24 @@ sysarch(struct thread *td, struct sysarch_args *uap) * explicitly indicate whether or not the operation is safe to * perform in capability mode. */ - if (IN_CAPABILITY_MODE(td)) { - switch (uap->op) { - case I386_GET_LDT: - case I386_SET_LDT: - case I386_GET_IOPERM: - case I386_GET_FSBASE: - case I386_SET_FSBASE: - case I386_GET_GSBASE: - case I386_SET_GSBASE: - case I386_GET_XFPUSTATE: - break; + switch (uap->op) { + case I386_GET_LDT: + case I386_SET_LDT: + case I386_GET_IOPERM: + case I386_GET_FSBASE: + case I386_SET_FSBASE: + case I386_GET_GSBASE: + case I386_SET_GSBASE: + case I386_GET_XFPUSTATE: + break; - case I386_SET_IOPERM: - default: -#ifdef KTRACE - if (KTRPOINT(td, KTR_CAPFAIL)) - ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL); -#endif + case I386_SET_IOPERM: + default: + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SYSCALL, &uap->op); + if (IN_CAPABILITY_MODE(td)) return (ECAPMODE); - } + break; } #endif diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 7f9318a7ceda..f626f5a38ca8 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -875,6 +875,8 @@ revert_f_setfl: case F_KINFO: #ifdef CAPABILITY_MODE + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SYSCALL, &cmd); if (IN_CAPABILITY_MODE(td)) { error = ECAPMODE; break; diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index a2ca74ac9183..8fa0942a5496 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -2677,10 +2677,16 @@ ptrace_syscallreq(struct thread *td, struct proc *p, &td->td_proc->p_cowgen))) thread_cow_update(td); + td->td_sa = tsr->ts_sa; + #ifdef CAPABILITY_MODE - if (IN_CAPABILITY_MODE(td) && (se->sy_flags & SYF_CAPENABLED) == 0) { - tsr->ts_ret.sr_error = ECAPMODE; - return; + if ((se->sy_flags & SYF_CAPENABLED) == 0) { + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SYSCALL, NULL); + if (IN_CAPABILITY_MODE(td)) { + tsr->ts_ret.sr_error = ECAPMODE; + return; + } } #endif diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c index 8948cc0517a5..22bc35774e70 100644 --- a/sys/kern/subr_syscall.c +++ b/sys/kern/subr_syscall.c @@ -118,10 +118,13 @@ syscallenter(struct thread *td) * In capability mode, we only allow access to system calls * flagged with SYF_CAPENABLED. */ - if (__predict_false(IN_CAPABILITY_MODE(td) && - (se->sy_flags & SYF_CAPENABLED) == 0)) { - td->td_errno = error = ECAPMODE; - goto retval; + if ((se->sy_flags & SYF_CAPENABLED) == 0) { + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SYSCALL, NULL); + if (IN_CAPABILITY_MODE(td)) { + td->td_errno = error = ECAPMODE; + goto retval; + } } #endif