[PATCH] Finish the task 'Embedd group table into struct ucred'
Tiwei Bie
btw at mail.ustc.edu.cn
Tue Nov 4 12:42:36 UTC 2014
On Tue, Nov 04, 2014 at 11:01:30AM +0100, Mateusz Guzik wrote:
> On Tue, Nov 04, 2014 at 05:51:26PM +0800, Tiwei Bie wrote:
> > diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
> > index 9b2bcd8..76d2cfc 100644
> > --- a/sys/kern/kern_prot.c
> > +++ b/sys/kern/kern_prot.c
> > @@ -1864,7 +1864,8 @@ crfree(struct ucred *cr)
> > #ifdef MAC
> > mac_cred_destroy(cr);
> > #endif
> > - free(cr->cr_groups, M_CRED);
> > + if (cr->cr_groups != cr->cr_smallgroups)
> > + free(cr->cr_groups, M_CRED);
> > free(cr, M_CRED);
> > }
> > }
> > @@ -1976,6 +1977,12 @@ crextend(struct ucred *cr, int n)
> > if (n <= cr->cr_agroups)
> > return;
> >
> > + if (n <= XU_NGROUPS) {
> > + cr->cr_groups = cr->cr_smallgroups;
> > + cr->cr_agroups = XU_NGROUPS;
> > + return;
> > + }
> > +
>
> This should be initialized in crget, which should no longer call this
> function.
Sorry for my delay...
Yeah, you are right. I didn't notice it... :-( My new patch:
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 9b2bcd8..c83af66 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1817,7 +1817,9 @@ crget(void)
#ifdef MAC
mac_cred_init(cr);
#endif
- crextend(cr, XU_NGROUPS);
+ cr->cr_groups = cr->cr_smallgroups;
+ cr->cr_agroups = XU_NGROUPS;
+
return (cr);
}
@@ -1864,7 +1866,8 @@ crfree(struct ucred *cr)
#ifdef MAC
mac_cred_destroy(cr);
#endif
- free(cr->cr_groups, M_CRED);
+ if (cr->cr_groups != cr->cr_smallgroups)
+ free(cr->cr_groups, M_CRED);
free(cr, M_CRED);
}
}
@@ -1997,7 +2000,7 @@ crextend(struct ucred *cr, int n)
cnt = roundup2(n, PAGE_SIZE / sizeof(gid_t));
/* Free the old array. */
- if (cr->cr_groups)
+ if (cr->cr_groups != cr->cr_smallgroups)
free(cr->cr_groups, M_CRED);
cr->cr_groups = malloc(cnt * sizeof(gid_t), M_CRED, M_WAITOK | M_ZERO);
diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h
index 81e4520..a6531c4 100644
--- a/sys/sys/ucred.h
+++ b/sys/sys/ucred.h
@@ -37,6 +37,8 @@
struct loginclass;
+#define XU_NGROUPS 16
+
/*
* Credentials.
*
@@ -64,13 +66,12 @@ struct ucred {
struct auditinfo_addr cr_audit; /* Audit properties. */
gid_t *cr_groups; /* groups */
int cr_agroups; /* Available groups */
+ gid_t cr_smallgroups[XU_NGROUPS]; /* storage for small groups */
};
#define NOCRED ((struct ucred *)0) /* no credential available */
#define FSCRED ((struct ucred *)-1) /* filesystem credential */
#endif /* _KERNEL || _WANT_UCRED */
-#define XU_NGROUPS 16
-
/*
* Flags for cr_flags.
*/
--
2.1.0
Tiwei Bie
More information about the freebsd-hackers
mailing list