From nobody Thu Sep 19 20:11:12 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 4X8mqj1NkBz5XK3F; Thu, 19 Sep 2024 20:11:13 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X8mqj0f37z4VgR; Thu, 19 Sep 2024 20:11:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726776673; 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=cH+cQhLWuELlpMjQw8pfcgQxn8D6T/mHF8yqZGX0DTE=; b=h6D257KAEx+U++1fnfxDW1KaiOi8xk1kfaPkxfY6SUjilrfo7Azidx4pflIsyYdrBWnw1H rpI/7HwDM4mFwx9V2LFRcWIjWRO0yyWecI7k8tjT2nZLb/ZlCUYIlWnBwTub6kPk2c6H/l wkdCEi9bTtyeFsQjl1Unhi8UyBV5f4to8MmCStX9aG3ICgSblieN38Iav2uNqQnS/FFdth Uu2/Es2o7DIGDnjnjMP487MLWuvEHDX4Jl0vgzXK8GHt/2v9kLy2rT4YIDGhoNjOt4yH+W ra3PnwlLSBuCYhkpxnAlQma1Eipss98sr7xTa4HDlOoyqE3zR/JDxGAU7qbyjg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726776673; a=rsa-sha256; cv=none; b=QYW1II0/NrK4iYvu2pGrIs/u/X3TdXz5Ze9ARxeQSwBxxWU5K1h7Avo3ZK+R8FZSaBNRez lZtzMN12lkk9H3RrDk2PdRM1DZXPabeZk518Q+ItJ/UGkhg97YfraxR2wOFJlZikMPMUa3 c1Kw/1WzDCeg0r5oGmVRWsDPZ5TvrxahQV3j/14XkJeFti04FSQ5ROe/bNwBEiv9HwrRpj y6ho6kcMweXV3oOINJOlP/n1B/9UZ4FVR7tcOhFNiZqf9xkqNaLbZsgU1WIfXluVVioXG0 NvImESvqTZoQaDl0s5+7EZDZuT/RgNHxj3RLhk7nJc2GKMBBocGB3TnVR+Hgkw== 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=1726776673; 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=cH+cQhLWuELlpMjQw8pfcgQxn8D6T/mHF8yqZGX0DTE=; b=TjsmVyA1h5WOGjcBjLFHFrAFw0WS/gi4bsqhaO4N41avBE/MbvQXZ2XAedlSn5Jhq+Iu9x t5D1X2ugqZ6Iu+4sVrmaaKgEB4RoPALmJacY33UrkN9bdYSR/XTRQS4dWsJpSxXjlgieEg WOxDXYDJcUQWmqjAdowvU1If4Drpn6H1yAiwmB9TT1613ZKY6r3sIq77ToWr6Du1J3MSnA j70HsAE718fgt5h1vTk2JH9uB+0Gkvl2CIDj/ZHxSN1p+PyHrkl/W6otV7ujbRzmSvTNHS 6b9r33P3KeftOjSUVpWBnq0M+NQHhESMagVRLOPxS3OEuesp/HIWfuonKt7sGg== 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 4X8mqj05cLzKsG; Thu, 19 Sep 2024 20:11:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48JKBCSW030828; Thu, 19 Sep 2024 20:11:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JKBCr5030825; Thu, 19 Sep 2024 20:11:12 GMT (envelope-from git) Date: Thu, 19 Sep 2024 20:11:12 GMT Message-Id: <202409192011.48JKBCr5030825@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Simon J. Gerraty" Subject: git: 4a5fa1086184 - main - procfs require PRIV_PROC_MEM_WRITE to write mem 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4a5fa1086184f7450f63d4a8e403b16f40a78fce Auto-Submitted: auto-generated The branch main has been updated by sjg: URL: https://cgit.FreeBSD.org/src/commit/?id=4a5fa1086184f7450f63d4a8e403b16f40a78fce commit 4a5fa1086184f7450f63d4a8e403b16f40a78fce Author: Simon J. Gerraty AuthorDate: 2024-09-19 20:10:27 +0000 Commit: Simon J. Gerraty CommitDate: 2024-09-19 20:10:27 +0000 procfs require PRIV_PROC_MEM_WRITE to write mem Add a priv_check for PRIV_PROC_MEM_WRITE which will be blocked by mac_veriexec if being enforced, unless the process has a maclabel to grant priv. Reviewed by: stevek Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D46692 --- sys/fs/procfs/procfs_mem.c | 3 +++ sys/kern/kern_priv.c | 4 +++- sys/security/mac_grantbylabel/mac_grantbylabel.c | 2 ++ sys/security/mac_veriexec/mac_veriexec.c | 1 + sys/sys/priv.h | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/fs/procfs/procfs_mem.c b/sys/fs/procfs/procfs_mem.c index 6ef725ee0ee7..159b40785172 100644 --- a/sys/fs/procfs/procfs_mem.c +++ b/sys/fs/procfs/procfs_mem.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,8 @@ procfs_doprocmem(PFS_FILL_ARGS) PROC_LOCK(p); error = p_candebug(td, p); + if (error == 0 && uio->uio_rw == UIO_WRITE) + error = priv_check(td, PRIV_PROC_MEM_WRITE); PROC_UNLOCK(p); if (error == 0) error = proc_rwmem(p, uio); diff --git a/sys/kern/kern_priv.c b/sys/kern/kern_priv.c index c146f9e6f8d5..83fd246eef9b 100644 --- a/sys/kern/kern_priv.c +++ b/sys/kern/kern_priv.c @@ -242,7 +242,9 @@ priv_check_cred(struct ucred *cred, int priv) * but non-root users are expected to be able to read it (provided they * have permission to access /dev/[k]mem). */ - if (priv == PRIV_KMEM_READ) { + switch (priv) { + case PRIV_KMEM_READ: + case PRIV_PROC_MEM_WRITE: /* we already checked candebug */ error = 0; goto out; } diff --git a/sys/security/mac_grantbylabel/mac_grantbylabel.c b/sys/security/mac_grantbylabel/mac_grantbylabel.c index 848131e54590..4d14577820eb 100644 --- a/sys/security/mac_grantbylabel/mac_grantbylabel.c +++ b/sys/security/mac_grantbylabel/mac_grantbylabel.c @@ -218,6 +218,7 @@ mac_grantbylabel_priv_grant(struct ucred *cred, int priv) return rc; /* not interested */ switch (priv) { + case PRIV_PROC_MEM_WRITE: case PRIV_KMEM_READ: case PRIV_KMEM_WRITE: break; @@ -244,6 +245,7 @@ mac_grantbylabel_priv_grant(struct ucred *cred, int priv) if (label & GBL_IPC) rc = 0; break; + case PRIV_PROC_MEM_WRITE: case PRIV_KMEM_READ: case PRIV_KMEM_WRITE: if (label & GBL_KMEM) diff --git a/sys/security/mac_veriexec/mac_veriexec.c b/sys/security/mac_veriexec/mac_veriexec.c index 7ac09e2acf0f..490601863197 100644 --- a/sys/security/mac_veriexec/mac_veriexec.c +++ b/sys/security/mac_veriexec/mac_veriexec.c @@ -435,6 +435,7 @@ mac_veriexec_priv_check(struct ucred *cred, int priv) error = 0; switch (priv) { case PRIV_KMEM_WRITE: + case PRIV_PROC_MEM_WRITE: case PRIV_VERIEXEC_CONTROL: /* * Do not allow writing to memory or manipulating veriexec, diff --git a/sys/sys/priv.h b/sys/sys/priv.h index a61de8d32fe0..7a5773da220f 100644 --- a/sys/sys/priv.h +++ b/sys/sys/priv.h @@ -513,6 +513,7 @@ */ #define PRIV_KMEM_READ 680 /* Open mem/kmem for reading. */ #define PRIV_KMEM_WRITE 681 /* Open mem/kmem for writing. */ +#define PRIV_PROC_MEM_WRITE 682 /* Open /proc//mem for writing. */ /* * Kernel debugger privileges.