From nobody Sun Apr 07 23:57:11 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 4VCTfc0g9zz5FbWt; Sun, 7 Apr 2024 23:57:12 +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 4VCTfb6gQMz4CT6; Sun, 7 Apr 2024 23:57:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712534231; 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=iOOUVCKuwGzdQjDiZGxwJEOJ4t0mjLaxyIlbxsuuzWY=; b=PEHyJIksqd18u2uFKb0V8jncb6RwJPM37cbFiBOI8LwBK2VBHKBkdrVZ5uS30QFMhUsCyQ kplDukKxcLo+CekCPopWXkEHAqEWeWCpVm+a5WSWNPNtMxT0XXHV46g2q/GlUoFdw4VLu5 7EfTtaojS4EBBXuuEhAmZOwnf7GrRr4fHiG3Pj0W0sZrrmghYWaydCOXV4AUYBtnL487wM xCZasHW3pwY7GUjGj2KMLfgsXBpRRObud1+S19aFKIeOfU+3h7SXihY9Ce2eoEe/fNIN/7 fDiZ+zzUKohuxD+d2ECXrmV6wH7xW3jnzLySBXnL1XAUlUzRQXXRb/heNWynzQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712534231; a=rsa-sha256; cv=none; b=O4/9HLLICf4qoS/dmcZXeb8eKAI9pOB1IIebpj61jthUyA6mB9qtlh9oXW+CQRO5nmLAvl uqQDCp2u1e5meIXpVWPrUONJWQKpd4X1Z+J5moTiKFLcBOy79KPvl7rA3nnzwY4T9MsNHy wSYM2BT8cB/u7IU/IcRNkcHrRtLD74WE+7QQs2HFCPDGMD6GmfXtFAtY3xl3gUKPJWf2+E ricuvtBPFAeF7kp6/HNuOq1qgFcBYuCaTGvebqQg7f/rJbwEuse82slY7lmhOGX6TtGNP6 imb0iH1X3Kaq3KJTfBOtZcPRUfcV3HO/x82skPUzxZNJQN5cE7tzI1ptqdZZbg== 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=1712534231; 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=iOOUVCKuwGzdQjDiZGxwJEOJ4t0mjLaxyIlbxsuuzWY=; b=keeLb7n1lfdejNANcyqhKkMt6zzv2KNUx+9IyH/9/oEmtqCsoLprUdsz7N24OICQX9QAod klvz/X/S73Og1xVrUEyuqaAgsg4lySVvIZD97UNoPWuVbl26N0SPhu0fhgrg77fI1H56/g tj6p+qaM6Piz5aJS7Ael2rwJ0yPYmazXBmYawJwJV3mCrwkKVbscXlbT/SqWO8S3p/+QF+ UkM80/5SBUGkdoZ9XwcqrNXIyFcPtAkE3nklYd624+eDnqrFCH6irXZtw2a+/QCedo4Yld /AkBSGK7cGGrzyE+JKJyNajfvvaFKapP+5davQTu8The2tue2hdfv3BBPVypNQ== 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 4VCTfb6GGPznpJ; Sun, 7 Apr 2024 23:57:11 +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 437NvBGK037569; Sun, 7 Apr 2024 23:57:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 437NvB5W037566; Sun, 7 Apr 2024 23:57:11 GMT (envelope-from git) Date: Sun, 7 Apr 2024 23:57:11 GMT Message-Id: <202404072357.437NvB5W037566@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: aa32d7cbc92c - main - ktrace: Record socket 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: 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: jfree X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aa32d7cbc92c818622462635641d240ae4342eb2 Auto-Submitted: auto-generated The branch main has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=aa32d7cbc92c818622462635641d240ae4342eb2 commit aa32d7cbc92c818622462635641d240ae4342eb2 Author: Jake Freeland AuthorDate: 2024-04-06 18:31:28 +0000 Commit: Jake Freeland CommitDate: 2024-04-07 23:52:51 +0000 ktrace: Record socket violations with KTR_CAPFAIL Report restricted access to socket addresses and protocols while Capsicum violation tracing with CAPFAIL_ADDR and CAPFAIL_PROTO. Reviewed by: markj Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D40681 --- sys/kern/uipc_socket.c | 9 +++++++-- sys/kern/uipc_syscalls.c | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 82fbcd4a922d..ce618eeba3ba 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -104,6 +104,7 @@ #include "opt_inet.h" #include "opt_inet6.h" #include "opt_kern_tls.h" +#include "opt_ktrace.h" #include "opt_sctp.h" #include @@ -522,8 +523,12 @@ socreate(int dom, struct socket **aso, int type, int proto, MPASS(prp->pr_attach); - if (IN_CAPABILITY_MODE(td) && (prp->pr_flags & PR_CAPATTACH) == 0) - return (ECAPMODE); + if ((prp->pr_flags & PR_CAPATTACH) == 0) { + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_PROTO, &proto); + if (IN_CAPABILITY_MODE(td)) + return (ECAPMODE); + } if (prison_check_af(cred, prp->pr_domain->dom_family) != 0) return (EPROTONOSUPPORT); diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 58b993dea5f2..318415245ab7 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -654,11 +654,6 @@ sendit(struct thread *td, int s, struct msghdr *mp, int flags) struct sockaddr *to; int error; -#ifdef CAPABILITY_MODE - if (IN_CAPABILITY_MODE(td) && (mp->msg_name != NULL)) - return (ECAPMODE); -#endif - if (mp->msg_name != NULL) { error = getsockaddr(&to, mp->msg_name, mp->msg_namelen); if (error != 0) { @@ -666,6 +661,14 @@ sendit(struct thread *td, int s, struct msghdr *mp, int flags) goto bad; } mp->msg_name = to; +#ifdef CAPABILITY_MODE + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_SOCKADDR, mp->msg_name); + if (IN_CAPABILITY_MODE(td)) { + error = ECAPMODE; + goto bad; + } +#endif } else { to = NULL; }