From nobody Thu May 23 00:27: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 4Vl8BS0g0gz5LLSF; Thu, 23 May 2024 00:27: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 4Vl8BS05GRz4gFq; Thu, 23 May 2024 00:27:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716424032; 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=7RUFn7EQI4JlcIAwPBKCEN8Imr04m233Qpv3OzMEnBA=; b=L3KGa+n6nvHv6P29Gdvae0osgmZy19kgoNqkQ5J4KwfIkzqAkisdRkfFQMzYH/mGra9UL0 fCXUdyZ77EDLI9ntbb1Ia8C8xSlX9I6lOAMRMA7w8rljIbLxVuNmG/isMvP0f147MIdKpo PesvMnE6pf0lbXwO7pRtYVW9yi4Huh9eC09EqLAeWzQYCr3FaoHb2yjffI78msK9nt7TtR sLBt6BZcFzWF8HP1fGXFiEaGsR1IeGqaTbYap3/MfMa9PhF7nG0XMhvLyRbjz/SHECNFeB HbO5qJhs7bOM9YN9slEcQTNP02MxgRV60eAV02A8oBvb2QOrpSqdecaagV36BQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716424032; a=rsa-sha256; cv=none; b=QzU5INBMT6CIqr+mwhvZ4ef5LxzZZqThz+5IKyDVlzc+sFYh7ZFLAMtuZC8FfDpD4IDw9J 2j0655LzRUOqiDA4EAQNcR6J4qgGsOLTveOusa7lozATIMIedS9XiZYmSYvZNQA/ljLPAc qg43mUdXX5Cs1+3x1sJgqPoE1WmF1ZJ9yWDJZWUJ4CM3JlYQBlVP2ST3HPUAzFeYNzCYB+ 9PPyFnVNyW21Ye8q3sjsN6XTloNRHmeYhI7acY3u+ExdFM+NaV5fgNJqshUcwPaDq3/wHq vYJxyBdvbSXwHZeo/M8GBc8C9TuABWDaQZIfS2PMeNAPB2PIwhgOTm6vYE579w== 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=1716424032; 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=7RUFn7EQI4JlcIAwPBKCEN8Imr04m233Qpv3OzMEnBA=; b=nvgxULW7xw0MBNq8dyh5F8zbjzUK6GNQAva3FmMaRELUR2SUP0D9xFAhEpy9Ga2lWbpq5p Ibo9JflTBF403lDMcp3CspiDbOvHpHC75m4ZwpPhSGqn6nhDlrPiA72qENK5CSmF0L4nKf AMtH4oXq1hesihlQ48OWvwacJ5Umk+oFvCH0GQRyS5YNG0MNXAys4sU+2PySFQwM2Hk3Sl IhJ8qJRecxHO1nki41RHYWO/nq30VOx2MTlJNbwm22Z5jSQ7qPY33A8tdTYGQj6V+Au3HG 9dr+WCjcM2vz9C0/c7HFMMlkPzuVtZ6Csq98J1VaedpZlB3m9E3DnE0Hc/RpQA== 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 4Vl8BR6nGNzS64; Thu, 23 May 2024 00:27: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 44N0RBHh020701; Thu, 23 May 2024 00:27:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44N0RBoO020698; Thu, 23 May 2024 00:27:11 GMT (envelope-from git) Date: Thu, 23 May 2024 00:27:11 GMT Message-Id: <202405230027.44N0RBoO020698@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: b76674a73988 - stable/14 - SysV IPC: provide in-kernel helpers to obtain ipcs(8)-like information 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: b76674a73988eb708bdb53e11c5c54e8488b33a1 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b76674a73988eb708bdb53e11c5c54e8488b33a1 commit b76674a73988eb708bdb53e11c5c54e8488b33a1 Author: Konstantin Belousov AuthorDate: 2024-05-13 17:17:47 +0000 Commit: Konstantin Belousov CommitDate: 2024-05-23 00:26:44 +0000 SysV IPC: provide in-kernel helpers to obtain ipcs(8)-like information PR: 278949 (cherry picked from commit 87a156527563d0728bff355093e26943da3d7fad) --- sys/kern/sysv_msg.c | 34 ++++++++++++++++++++++++++++++++++ sys/kern/sysv_sem.c | 33 +++++++++++++++++++++++++++++++++ sys/kern/sysv_shm.c | 36 ++++++++++++++++++++++++++++++++++++ sys/sys/msg.h | 3 +++ sys/sys/sem.h | 3 +++ sys/sys/shm.h | 2 ++ 6 files changed, 111 insertions(+) diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c index 078151627dfc..0620fbd175af 100644 --- a/sys/kern/sysv_msg.c +++ b/sys/kern/sysv_msg.c @@ -1477,6 +1477,40 @@ sysctl_msqids(SYSCTL_HANDLER_ARGS) return (error); } +int +kern_get_msqids(struct thread *td, struct msqid_kernel **res, size_t *sz) +{ + struct msqid_kernel *pmsqk; + struct prison *pr, *rpr; + int i, mi; + + *sz = mi = msginfo.msgmni; + if (res == NULL) + return (0); + + pr = td->td_ucred->cr_prison; + rpr = msg_find_prison(td->td_ucred); + *res = malloc(sizeof(struct msqid_kernel) * mi, M_TEMP, M_WAITOK); + for (i = 0; i < mi; i++) { + pmsqk = &(*res)[i]; + mtx_lock(&msq_mtx); + if (msqids[i].u.msg_qbytes == 0 || rpr == NULL || + msq_prison_cansee(rpr, &msqids[i]) != 0) + bzero(pmsqk, sizeof(*pmsqk)); + else { + *pmsqk = msqids[i]; + if (pmsqk->cred->cr_prison != pr) + pmsqk->u.msg_perm.key = IPC_PRIVATE; + } + mtx_unlock(&msq_mtx); + pmsqk->u.__msg_first = NULL; + pmsqk->u.__msg_last = NULL; + pmsqk->label = NULL; + pmsqk->cred = NULL; + } + return (0); +} + SYSCTL_INT(_kern_ipc, OID_AUTO, msgmax, CTLFLAG_RD, &msginfo.msgmax, 0, "Maximum message size"); SYSCTL_INT(_kern_ipc, OID_AUTO, msgmni, CTLFLAG_RDTUN, &msginfo.msgmni, 0, diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c index 6a668906ebd0..d8c10f837105 100644 --- a/sys/kern/sysv_sem.c +++ b/sys/kern/sysv_sem.c @@ -1574,6 +1574,39 @@ sysctl_sema(SYSCTL_HANDLER_ARGS) return (error); } +int +kern_get_sema(struct thread *td, struct semid_kernel **res, size_t *sz) +{ + struct prison *pr, *rpr; + struct semid_kernel *psemak; + int i, mi; + + *sz = mi = seminfo.semmni; + if (res == NULL) + return (0); + + pr = td->td_ucred->cr_prison; + rpr = sem_find_prison(td->td_ucred); + *res = malloc(sizeof(struct semid_kernel) * mi, M_TEMP, M_WAITOK); + for (i = 0; i < mi; i++) { + psemak = &(*res)[i]; + mtx_lock(&sema_mtx[i]); + if ((sema[i].u.sem_perm.mode & SEM_ALLOC) == 0 || + rpr == NULL || sem_prison_cansee(rpr, &sema[i]) != 0) + bzero(psemak, sizeof(*psemak)); + else { + *psemak = sema[i]; + if (psemak->cred->cr_prison != pr) + psemak->u.sem_perm.key = IPC_PRIVATE; + } + mtx_unlock(&sema_mtx[i]); + psemak->u.__sem_base = NULL; + psemak->label = NULL; + psemak->cred = NULL; + } + return (0); +} + static int sem_prison_check(void *obj, void *data) { diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 8f67cb63f33c..835b44ab332a 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -1089,6 +1089,42 @@ sysctl_shmsegs(SYSCTL_HANDLER_ARGS) return (error); } +int +kern_get_shmsegs(struct thread *td, struct shmid_kernel **res, size_t *sz) +{ + struct shmid_kernel *pshmseg; + struct prison *pr, *rpr; + int i; + + SYSVSHM_LOCK(); + *sz = shmalloced; + if (res == NULL) + goto out; + + pr = td->td_ucred->cr_prison; + rpr = shm_find_prison(td->td_ucred); + *res = malloc(sizeof(struct shmid_kernel) * shmalloced, M_TEMP, + M_WAITOK); + for (i = 0; i < shmalloced; i++) { + pshmseg = &(*res)[i]; + if ((shmsegs[i].u.shm_perm.mode & SHMSEG_ALLOCATED) == 0 || + rpr == NULL || shm_prison_cansee(rpr, &shmsegs[i]) != 0) { + bzero(pshmseg, sizeof(*pshmseg)); + pshmseg->u.shm_perm.mode = SHMSEG_FREE; + } else { + *pshmseg = shmsegs[i]; + if (pshmseg->cred->cr_prison != pr) + pshmseg->u.shm_perm.key = IPC_PRIVATE; + } + pshmseg->object = NULL; + pshmseg->label = NULL; + pshmseg->cred = NULL; + } +out: + SYSVSHM_UNLOCK(); + return (0); +} + static int shm_prison_check(void *obj, void *data) { diff --git a/sys/sys/msg.h b/sys/sys/msg.h index 29fb8c2106b5..d8c950e66c47 100644 --- a/sys/sys/msg.h +++ b/sys/sys/msg.h @@ -152,6 +152,9 @@ struct msqid_kernel { #ifdef _KERNEL extern struct msginfo msginfo; +int kern_get_msqids(struct thread *td, struct msqid_kernel **res, + size_t *sz); + #else /* _KERNEL */ __BEGIN_DECLS diff --git a/sys/sys/sem.h b/sys/sys/sem.h index 05b69f64cd05..5634f4b0cfcc 100644 --- a/sys/sys/sem.h +++ b/sys/sys/sem.h @@ -142,6 +142,9 @@ extern struct seminfo seminfo; */ void semexit(struct proc *p); +int kern_get_sema(struct thread *td, struct semid_kernel **res, + size_t *sz); + #else /* !_KERNEL */ __BEGIN_DECLS diff --git a/sys/sys/shm.h b/sys/sys/shm.h index 9c6dad5d43cc..a1aa6ca54c60 100644 --- a/sys/sys/shm.h +++ b/sys/sys/shm.h @@ -158,6 +158,8 @@ extern struct shminfo shminfo; void shmexit(struct vmspace *); void shmfork(struct proc *, struct proc *); +int kern_get_shmsegs(struct thread *td, struct shmid_kernel **res, + size_t *sz); #else /* !_KERNEL */