From nobody Sun Apr 07 23:57:07 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 4VCTfW3qq0z5FbWn; Sun, 7 Apr 2024 23:57:07 +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 4VCTfW3KK2z4CM8; Sun, 7 Apr 2024 23:57:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712534227; 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=8jZYVYPropIxNeetFgu4damJcI4ZfVj09VpYBW6nXHU=; b=X5c2KAN9TIeAaWDE6b+OiH6L8N3FDA01E5tN20+AHAYYMaY13irKIuz50s4YRN0dR5Do4d h5rRMV0sCE8x/7sb5DNt7rTKftBOzqt8TPtqeUSoV+K7bT3y6KIce3HkQasKNwxOR4PuE4 W8etboXbF9m2vEMYX3CwP/lVRY4TF8aylyEwdqEaPRtjgouuV2DqXjy6SXr1N2lbj6dUqs YDsQsGRvs6inu0gkMduoz+oPBX6LUhQ5mNLNeDVzapIwYfbsh39IHj6H/J6lP+Z2uV0t6c e5YhZDYuHlCgoE0VovHKiWI0BCz3RdokttI20VL7QJZuyR7obNjBfG5CBFW5ZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712534227; a=rsa-sha256; cv=none; b=jJZUuaSXYkPYmCbXjzIcuU4w9V5T0mNYqAv2VdCgCbJ9nHEo8NF47iLIbivdHdsVXGXV3W bD8NJfNeh4GVC52IihhR+0bsIUVSOrmreeM451/BSouUHlMNNE4rQ0bA1XpLhoorW7dBlb 7OMFA5CZzYnak60dYlDyfgH+ZubxsBnNVLpYnkWj7y/ez9Ptx49lszGF7n2lMa+d/fPbvE oTxHDN2mncARB4+8GwwGXvfoMNbTVUfHBr956/cnwr66x26AOUqKFlqeLeSydw2xDscggI l1fMBW7g24L7v7+puF+wUq2/TOkmqXDrAdzLKHc71Zhn6Qa6QUhdwW3EUOT0QA== 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=1712534227; 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=8jZYVYPropIxNeetFgu4damJcI4ZfVj09VpYBW6nXHU=; b=bF/mU/HLokFnJtB+EoXxKpXM/mP6CNYVLpuNvH4afcv4c1pgbVDl4tKeDAj+T5wS5lhTmr DanPVOeJDlBZNP3gqnik2QdeqRwpFv/ddnjDHa0K6YD9VhdnlBiFP1FDXtPwlg9qPwREZ3 1Yz6IyXMp10iF6O2C1YgnX+Uv89mp5JJXsmVHrxHWtuhPr+T7phDuyHhiSgqwR5/GVw0C7 C0WJAcOf/aPcWQoqQN9EvBTQbjaKZpFyKTHTjzvfOHkEpRzmM7IpLWN4lX2K4JYeGJOsAP 0uynTdbs5QU6odlgGvQFg1b/YhlgNaBoPG27iDNXrn0mznJFQwaNjMJerHrTjg== 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 4VCTfW2xN7zpPw; Sun, 7 Apr 2024 23:57:07 +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 437Nv7M7037382; Sun, 7 Apr 2024 23:57:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 437Nv7Ol037379; Sun, 7 Apr 2024 23:57:07 GMT (envelope-from git) Date: Sun, 7 Apr 2024 23:57:07 GMT Message-Id: <202404072357.437Nv7Ol037379@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: 96c8b3e50988 - main - ktrace: Record cpuset 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: 96c8b3e509882e5a51a5ae58d366b812be4d2773 Auto-Submitted: auto-generated The branch main has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=96c8b3e509882e5a51a5ae58d366b812be4d2773 commit 96c8b3e509882e5a51a5ae58d366b812be4d2773 Author: Jake Freeland AuthorDate: 2024-04-06 18:31:14 +0000 Commit: Jake Freeland CommitDate: 2024-04-07 23:52:51 +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 --- 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);