Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Jul 2009 15:03:10 +0000 (UTC)
From:      Brooks Davis <brooks@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r195843 - in head: lib/libkvm sys/kern sys/sys
Message-ID:  <200907241503.n6OF3ATP013228@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brooks
Date: Fri Jul 24 15:03:10 2009
New Revision: 195843
URL: http://svn.freebsd.org/changeset/base/195843

Log:
  Revert the changes to struct kinfo_proc in r194498.  Instead, fill
  in up to 16 (KI_NGROUPS) values and steal a bit from ki_cr_flags
  (all bits currently unused) to indicate overflow with the new flag
  KI_CRF_GRP_OVERFLOW.
  
  This fixes procstat -s.
  
  Approved by: re (kib)

Modified:
  head/lib/libkvm/kvm_proc.c
  head/sys/kern/kern_proc.c
  head/sys/sys/user.h

Modified: head/lib/libkvm/kvm_proc.c
==============================================================================
--- head/lib/libkvm/kvm_proc.c	Fri Jul 24 14:57:02 2009	(r195842)
+++ head/lib/libkvm/kvm_proc.c	Fri Jul 24 15:03:10 2009	(r195843)
@@ -145,8 +145,14 @@ kvm_proclist(kd, what, arg, p, bp, maxcn
 			kp->ki_svuid = ucred.cr_svuid;
 			kp->ki_rgid = ucred.cr_rgid;
 			kp->ki_svgid = ucred.cr_svgid;
-			kp->ki_ngroups = ucred.cr_ngroups;
-			kp->ki_groups = ucred.cr_groups;
+			kp->ki_cr_flags = ucred.cr_flags;
+			if (ucred.cr_ngroups > KI_NGROUPS) {
+				kp->ki_ngroups = KI_NGROUPS;
+				kp->ki_cr_flags |= KI_CRF_GRP_OVERFLOW;
+			}
+				kp->ki_ngroups = ucred.cr_ngroups;
+			bcopy(ucred.cr_groups, kp->ki_groups,
+			    kp->ki_ngroups * sizeof(gid_t));
 			kp->ki_uid = ucred.cr_uid;
 			if (ucred.cr_prison != NULL) {
 				if (KREAD(kd, (u_long)ucred.cr_prison, &pr)) {

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Fri Jul 24 14:57:02 2009	(r195842)
+++ head/sys/kern/kern_proc.c	Fri Jul 24 15:03:10 2009	(r195843)
@@ -730,11 +730,17 @@ fill_kinfo_proc_only(struct proc *p, str
 		kp->ki_uid = cred->cr_uid;
 		kp->ki_ruid = cred->cr_ruid;
 		kp->ki_svuid = cred->cr_svuid;
-		kp->ki_ngroups = cred->cr_ngroups;
-		kp->ki_groups = cred->cr_groups;
+		kp->ki_cr_flags = cred->cr_flags;
+		/* XXX bde doesn't like KI_NGROUPS */
+		if (cred->cr_ngroups > KI_NGROUPS) {
+			kp->ki_ngroups = KI_NGROUPS;
+			kp->ki_cr_flags |= KI_CRF_GRP_OVERFLOW;
+		} else
+			kp->ki_ngroups = cred->cr_ngroups;
+		bcopy(cred->cr_groups, kp->ki_groups,
+		    kp->ki_ngroups * sizeof(gid_t));
 		kp->ki_rgid = cred->cr_rgid;
 		kp->ki_svgid = cred->cr_svgid;
-		kp->ki_cr_flags = cred->cr_flags;
 		/* If jailed(cred), emulate the old P_JAILED flag. */
 		if (jailed(cred)) {
 			kp->ki_flag |= P_JAILED;

Modified: head/sys/sys/user.h
==============================================================================
--- head/sys/sys/user.h	Fri Jul 24 14:57:02 2009	(r195842)
+++ head/sys/sys/user.h	Fri Jul 24 15:03:10 2009	(r195843)
@@ -85,7 +85,7 @@
  */
 #define	KI_NSPARE_INT	9
 #define	KI_NSPARE_LONG	12
-#define	KI_NSPARE_PTR	6
+#define	KI_NSPARE_PTR	7
 
 #ifdef __amd64__
 #define	KINFO_PROC_SIZE	1088
@@ -117,8 +117,15 @@
 #define	OCOMMLEN	16		/* size of returned thread name */
 #define	COMMLEN		19		/* size of returned ki_comm name */
 #define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
+#define KI_NGROUPS	16		/* number of groups in ki_groups */
 #define	LOGNAMELEN	17		/* size of returned ki_login */
 
+/*
+ * Steal a bit from ki_cr_flags (cr_flags is never used) to indicate
+ * that the cred had more than KI_NGROUPS groups.
+ */
+#define KI_CRF_GRP_OVERFLOW	0x80000000
+
 struct kinfo_proc {
 	int	ki_structsize;		/* size of this structure */
 	int	ki_layout;		/* reserved: layout identifier */
@@ -150,7 +157,7 @@ struct kinfo_proc {
 	gid_t	ki_svgid;		/* Saved effective group id */
 	short	ki_ngroups;		/* number of groups */
 	short	ki_spare_short2;	/* unused (just here for alignment) */
-	uint32_t __was_ki_groups[16];	/* unused; left for bin compat */
+	gid_t 	ki_groups[KI_NGROUPS];	/* groups */
 	vm_size_t ki_size;		/* virtual size */
 	segsz_t ki_rssize;		/* current resident set size in pages */
 	segsz_t ki_swrss;		/* resident set size before last swap */
@@ -200,7 +207,6 @@ struct kinfo_proc {
 	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
 	void	*ki_kstack;		/* kernel virtual addr of stack */
 	void	*ki_udata;		/* User convenience pointer */
-	gid_t	*ki_groups;		/* groups */
 	/*
 	 * When adding new variables, take space for pointers from the
 	 * front of ki_spareptrs, and longs from the end of ki_sparelongs.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907241503.n6OF3ATP013228>