Avoid a possible race during the time we give up our lock in order to
allocate memory. (From yamt)
This commit is contained in:
parent
0f48b53686
commit
ae9d3eacae
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_resource.c,v 1.89 2005/03/23 01:16:44 christos Exp $ */
|
||||
/* $NetBSD: kern_resource.c,v 1.90 2005/03/23 04:01:04 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1991, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.89 2005/03/23 01:16:44 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.90 2005/03/23 04:01:04 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -893,21 +893,28 @@ struct uidinfo *
|
|||
uid_find(uid_t uid)
|
||||
{
|
||||
struct uidinfo *uip;
|
||||
struct uidinfo *newuip = NULL;
|
||||
struct uihashhead *uipp;
|
||||
|
||||
uipp = UIHASH(uid);
|
||||
|
||||
again:
|
||||
simple_lock(&uihashtbl_slock);
|
||||
LIST_FOREACH(uip, uipp, ui_hash)
|
||||
if (uip->ui_uid == uid) {
|
||||
simple_unlock(&uihashtbl_slock);
|
||||
if (newuip)
|
||||
free(newuip, M_PROC);
|
||||
return uip;
|
||||
}
|
||||
simple_unlock(&uihashtbl_slock);
|
||||
|
||||
MALLOC(uip, struct uidinfo *, sizeof(*uip), M_PROC, M_WAITOK|M_ZERO);
|
||||
if (newuip == NULL) {
|
||||
simple_unlock(&uihashtbl_slock);
|
||||
newuip = malloc(sizeof(*uip), M_PROC, M_WAITOK | M_ZERO);
|
||||
goto again;
|
||||
}
|
||||
uip = newuip;
|
||||
|
||||
simple_lock(&uihashtbl_slock);
|
||||
LIST_INSERT_HEAD(uipp, uip, ui_hash);
|
||||
uip->ui_uid = uid;
|
||||
simple_unlock(&uihashtbl_slock);
|
||||
|
|
Loading…
Reference in New Issue