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.