From nobody Thu May 16 17:53:49 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 4VgHlL1KFfz5LcLt; Thu, 16 May 2024 17:53:50 +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 4VgHlK6p14z4V8L; Thu, 16 May 2024 17:53:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715882030; 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=ob8FVukx3ZRRCJhcrssQGeG5i3EdFv0cLvQcc6aYIOU=; b=Ufu1CKNRn7TtpoYNQzI0ihVFId+6LFA3oeZBsHXxFo/U7h9iCQaF9s5yOVbWdqr8RQMUzY e7i/Xu802zNf10rs/xvljgFky+go5tRtd/5CTQhfEi0Ci1Kp0jogfi9Z02hJvaZSpXtmdq af8ZKoWWW4k/LUnOTa3re0DvKXq+kWW2KQ8BMJpf1f/5xobCoxmtPQ8V8KjFki32QHJmV+ 57WaN3UsvTGclc2owEdQ6B9cfx3+UfoQOAmGnX0adaG/nn4sk6mJt2RgTxqHHWFOFM7S/R pHbPPFkA66CpUSOB/HD8j3R0D2+5TjKkzlUrHSU04RNV4CHXm/ZshRr9kQCGrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715882030; a=rsa-sha256; cv=none; b=X7KgbPHnOuBcj3UsoyJh5Ux84c0tUEkNlXwgf7F7E8bm204H9dn0UYUG16cw61kg/x2kea ZJ6PSTCQXN39dKc+TUHcdDJTZ2rw6PLAlcH4/gAEh5zeKBBqukb+wSkKcJiNg5XeJ9e0IX Tzgm39+9jekY8YuaCJ/zXTgX19j6U1ua28sG4yA2Dds37KOd4RA5d6Va4v5mxzRB+y2Ur2 /Ym6+Sw1umtfDBd1LdI2wP9XsWf4IB7V9AsMIK36v40iFrYjBNkR/OJNxf1Z65XlFDcuwG a+VZlvvYy0XAY/Q2hhv8tuRpZH4lkCQxFF9GmRh68rMSxl8YOTUDfIIqMTVy9w== 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=1715882030; 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=ob8FVukx3ZRRCJhcrssQGeG5i3EdFv0cLvQcc6aYIOU=; b=OLRKdmOgbrnna/tZsbEr090/v2+LnwXLuM/Ri9+FjDGLyxOolPecD785WudOE1Grnxj20X mBELBjgyiEnRP8IgGZ9Mx6DNNHD1BaR8j+Nma5lkgvkOF0HdaLSW83eYmzglp6dkxituD4 AXR4bOoqHmF9Yc7el+NGZ3rj0Bw+/SMAo6SWe4Ii0FG0Tbay9xKno+AaRTsDhlzVeWsw7p k3SlyjOiL2QNQGqxMfQv0sdQWc9mjE9IdkFyIWr8waCQOgac1K4Qk+eBfMichtcQZjYqnK agEItQeZKaEeM9x4/dq/nly4DyUffb9BGY3M7DD+bFLH02n6U3XoG9W6zm2jGw== 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 4VgHlK6P7Vz188N; Thu, 16 May 2024 17:53:49 +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 44GHrnta003182; Thu, 16 May 2024 17:53:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44GHrn39003179; Thu, 16 May 2024 17:53:49 GMT (envelope-from git) Date: Thu, 16 May 2024 17:53:49 GMT Message-Id: <202405161753.44GHrn39003179@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 87a156527563 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 87a156527563d0728bff355093e26943da3d7fad Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=87a156527563d0728bff355093e26943da3d7fad commit 87a156527563d0728bff355093e26943da3d7fad Author: Konstantin Belousov AuthorDate: 2024-05-13 17:17:47 +0000 Commit: Konstantin Belousov CommitDate: 2024-05-16 17:53:31 +0000 SysV IPC: provide in-kernel helpers to obtain ipcs(8)-like information PR: 278949 Reviewed by: markj Tested by: Ricardo Branco Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D45175 --- 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 */