From nobody Sun May 12 00:08:28 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 4VcNHw5jRSz5JbSH; Sun, 12 May 2024 00:08:28 +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 4VcNHw315Xz4sxt; Sun, 12 May 2024 00:08:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715472508; 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=TtJcJG4UJhrfUd6qb38zPMLuV+B9xq27sPhlgVEmYvs=; b=IsaW5/gpeE5bXMWqkTYVlCop/7EO9YH9Tv8DK2jOeSEI9uxl9XVzSaI3xKbyPeyhksRsg2 B2bLEL8x3E0Rb24o/mSteHCkv4/ijSpIexk0mkLf0Ke7p6p7vbIsQaWhUnmx6fGp+CYn0n UjTqcDI9Yj6tGZvR1L4mgt+mTgG1lcYYNZO5MR/xKM9RqIyPRAbyUm8xRfbs8H64da1vrU 7yrhxsVMVI2CDoEYVH/pTkBzYmUIu7IKj07ipgadz+s62DswGHzTDLhStecFLJzbquXdnW vL3a5NffhBwKLauwqVKNCQhdYI8S/3Iy17KX2PR1bGTe+fNVIuH8GVYyd6KRQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715472508; a=rsa-sha256; cv=none; b=fwsLeiVzEeH9xr7T491IYBN/VJdxazF3Y9HHeGAF6edWcbo0Jzf9vjVS0gBRCjOVevQfFS /dSKw1leM5oAddQPYi4i4QGh/PSBodVGg8fbyHfnnbUiFny+2pfCX4pe9jzZjbcOYS6k5L Sxjmn9d7D5Swpsk8YWhki5ORmTFo9olutJcdhtKCwh3G9tVKJFbh8x+mqSj7DAKMnOUikU wpjHBxcYuxvcCq3jKM5WckTi3RIJNAT/DziXkwQbNm8QDzXk1D8eTj1oXzlvg3WZN6oS2i oXtFXbXXZFEZ/7PXZJYhUoLr2RU4iQ3U0hbt1e2Gp0SG6wue2Y+RIWYlxENJEA== 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=1715472508; 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=TtJcJG4UJhrfUd6qb38zPMLuV+B9xq27sPhlgVEmYvs=; b=j/jNZagLfbCds7pyqDv7NM0RGdI9Z1579PXIAO7JpZ7NLGf7TWj1iTV7RyRx3Eoi245DgC jrMvLStUMGJzKGOv1bGxJFJC3Q/DEqtyFN/iRmOo11qunUrCbkZH47tGvkVsbigaeXKbH/ nbDHi5HasocgYlcniw0vd2EJBxsv1Oblco4rxc440+D2AFo4jBLM3AwvrTYuHAGSgN6bOg r6KdG0r+WLi6ruydhQhyVD4owOBAyPgJv8MnuW+KFlp6FwimoHa3gPHxwMKlR5MNwLXqzM XyKWBceivPRCt+PtXoFVuRo3oBnW7RFYDyWQOYM4HqT4/Afxg486iDsrmrKR/g== 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 4VcNHw2VyszhTv; Sun, 12 May 2024 00:08:28 +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 44C08SwM001825; Sun, 12 May 2024 00:08:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44C08SEg001822; Sun, 12 May 2024 00:08:28 GMT (envelope-from git) Date: Sun, 12 May 2024 00:08:28 GMT Message-Id: <202405120008.44C08SEg001822@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jake Freeland Subject: git: fa92eaede40b - stable/14 - ktrace: Record syscall violations with KTR_CAPFAIL 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: fa92eaede40bce557c44e4f1b599cd6e443607b5 Auto-Submitted: auto-generated The branch stable/14 has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=fa92eaede40bce557c44e4f1b599cd6e443607b5 commit fa92eaede40bce557c44e4f1b599cd6e443607b5 Author: Jake Freeland AuthorDate: 2024-04-06 18:31:18 +0000 Commit: Jake Freeland CommitDate: 2024-05-11 23:57:44 +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 (cherry picked from commit 05296a0ff615566d25c77c5e6619b08724d2eecb) --- 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 6f8d6feaf60b..6c8b038bdb09 100644 --- a/sys/amd64/amd64/sys_machdep.c +++ b/sys/amd64/amd64/sys_machdep.c @@ -189,35 +189,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 208026db85ba..d167c757952b 100644 --- a/sys/arm/arm/sys_machdep.c +++ b/sys/arm/arm/sys_machdep.c @@ -177,22 +177,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 1634041daf2a..3a7b7c2f6c71 100644 --- a/sys/i386/i386/sys_machdep.c +++ b/sys/i386/i386/sys_machdep.c @@ -154,26 +154,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 30d82f74d725..b72ae27e2a0b 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -877,6 +877,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 2f2ec7edfb12..b1860bf23cf2 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -2690,10 +2690,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 ff13672501b2..725467e1215f 100644 --- a/sys/kern/subr_syscall.c +++ b/sys/kern/subr_syscall.c @@ -120,10 +120,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