From nobody Sun May 12 00:08:27 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 4VcNHv4RBfz5JbZg; Sun, 12 May 2024 00:08:27 +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 4VcNHv3ffsz4svT; Sun, 12 May 2024 00:08:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715472507; 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=UXB8THGzkCnWn5TQxvSi6Qbu0eDitE+MICo5Atv2gHM=; b=tiqVguLv6cBaAah2qBiy5w5FGw83PZ5ptbBI47WqB8X5XzvJrvmo9su0ii0Vq3Gx4nZGVQ xcPjYcu+5Pig70v/RLcVRQnUjGP7Ol9fVJHm9yO90jAigMbSWKiu/Uj4syj7gEXyK/9DOE hD/QLe+KguO1LbDl9ZvUir3tTUcNVY1egr1IN8X0XtQwbL1JtZurCeT+JSNHN+JNqYdOdF duJiNdWEi6Knravbl6bLn9TseA3Z7eNYCOFlcsIHjNEaVLEeilbCdI87q30vZesiG0kkc4 QsdBvEelDQYLZR9TrNrXFLdjyHKFuk2g5HKWNDB6foKiwwmlcSJlxn2lWKutAw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715472507; a=rsa-sha256; cv=none; b=bipgkECxlA6hO2gzcdL5vl0F313loIZ/dK/dz60rakLVodAxDLF/NN7rJyECM2f0uT2f3l a/aflxunjqse9cm4iULyvM3mLTa40+THhoyiolunLbMcd4yFTUnT8bK2iuDmpwOY/qAtdx l6ch4sqrZANwzFPilboqP7D/CMkuvTW33wSsUFlvxMLQrW1lLFIGZ/agysFNKqKM2p1gMQ EcXg76u+CfJo/gfmNAhXFNyNq/EBCID3UNRV4UXEi8joYkqKzG/j31vk0+k+gGCvHgqzUD ekesNwpxilDmTtnJs+oTSnfpkLpwVXHWfxYQ4sDcFEiJm1LPgNH7Fmc04ThL4Q== 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=1715472507; 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=UXB8THGzkCnWn5TQxvSi6Qbu0eDitE+MICo5Atv2gHM=; b=EPchNLvyUwvPK/ZqkLIk57iUoGCq1UHV5OqJrn3NPClcBmqLLD34jwjvi68fyQyNeNTEoe r2FXTzKUToFoSxq/QWWa3aKT4lCBZpycaKbZHL9z7IaIFndtiJclzuK1938wJ+iSaGDa5T ycAPDPZm6mXbbYt5pKy9rqEbeMh459E/+FDaFVmFgoLM4knVteyO0Goy8FRJp/FlB4Dwhn O5MpZMWgY0b8c/09tQXPRI4FqemBrWPaXh1tOZITpwrR9ASNLK7CI/X4g6XRYTAIcRwp6J 82l2BpvSZDM0jzOX+PCCCp6la6MNmD0M97CegAan+Hg1ukeymHRVhGecuF+nTQ== 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 4VcNHv1fv3zhTt; Sun, 12 May 2024 00:08:27 +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 44C08RRi001773; Sun, 12 May 2024 00:08:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44C08Rmr001770; Sun, 12 May 2024 00:08:27 GMT (envelope-from git) Date: Sun, 12 May 2024 00:08:27 GMT Message-Id: <202405120008.44C08Rmr001770@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: 85a4df5f2a6b - stable/14 - ktrace: Record cpuset 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: 85a4df5f2a6bae3e2ecdf311150f17f6063600d2 Auto-Submitted: auto-generated The branch stable/14 has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=85a4df5f2a6bae3e2ecdf311150f17f6063600d2 commit 85a4df5f2a6bae3e2ecdf311150f17f6063600d2 Author: Jake Freeland AuthorDate: 2024-04-06 18:31:14 +0000 Commit: Jake Freeland CommitDate: 2024-05-11 23:57:44 +0000 ktrace: Record cpuset violations with KTR_CAPFAIL Report Capsicum violations in the cpuset namespace with CAPFAIL_CPUSET. Reviewed by: markj Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D40677 (cherry picked from commit 96c8b3e509882e5a51a5ae58d366b812be4d2773) --- sys/kern/kern_cpuset.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c index 17176afa6ad3..5d9e2f2f326b 100644 --- a/sys/kern/kern_cpuset.c +++ b/sys/kern/kern_cpuset.c @@ -1762,22 +1762,38 @@ cpuset_setproc_update_set(struct proc *p, struct cpuset *set) * In Capability mode, the only accesses that are permitted are to the current * thread and process' CPU and domain sets. */ +static bool +cpuset_capmode_allowed(struct thread *td, cpulevel_t level, cpuwhich_t which, + id_t id) +{ + if (level != CPU_LEVEL_WHICH) + return (false); + if (which != CPU_WHICH_TID && which != CPU_WHICH_PID && + which != CPU_WHICH_TIDPID) + return (false); + if (id != -1 && which == CPU_WHICH_TIDPID && + id != td->td_tid && id != td->td_proc->p_pid) + return (false); + if (id != -1 && + !(which == CPU_WHICH_TID && id == td->td_tid) && + !(which == CPU_WHICH_PID && id == td->td_proc->p_pid)) + return (false); + return (true); +} + +/* + * Check for capability violations and record them if ktrace(2) is active. + */ static int cpuset_check_capabilities(struct thread *td, cpulevel_t level, cpuwhich_t which, id_t id) { - if (IN_CAPABILITY_MODE(td)) { - if (level != CPU_LEVEL_WHICH) - return (ECAPMODE); - if (which != CPU_WHICH_TID && which != CPU_WHICH_PID && - which != CPU_WHICH_TIDPID) - return (ECAPMODE); - if (id != -1 && which == CPU_WHICH_TIDPID && - id != td->td_tid && id != td->td_proc->p_pid) - return (ECAPMODE); - if (id != -1 && - !(which == CPU_WHICH_TID && id == td->td_tid) && - !(which == CPU_WHICH_PID && id == td->td_proc->p_pid)) + if (IN_CAPABILITY_MODE(td) || CAP_TRACING(td)) { + if (cpuset_capmode_allowed(td, level, which, id)) + return (0); + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_CPUSET, NULL); + if (IN_CAPABILITY_MODE(td)) return (ECAPMODE); } return (0);