From: dlg Date: Tue, 6 Feb 2018 22:35:32 +0000 (+0000) Subject: slightly randomize the order that new pages populate their item lists in. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a544e172bbf221032329dc290631fe436d7c0ac7;p=openbsd slightly randomize the order that new pages populate their item lists in. ok tedu@ deraadt@ --- diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index cbcbffbfa3b..f1c08735591 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.221 2018/01/18 18:08:51 bluhm Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.222 2018/02/06 22:35:32 dlg Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -917,6 +917,8 @@ pool_p_alloc(struct pool *pp, int flags, int *slowdown) struct pool_page_header *ph; struct pool_item *pi; caddr_t addr; + unsigned int order; + int o; int n; pl_assert_unlocked(pp, &pp->pr_lock); @@ -951,10 +953,19 @@ pool_p_alloc(struct pool *pp, int flags, int *slowdown) #endif /* DIAGNOSTIC */ n = pp->pr_itemsperpage; + o = 32; while (n--) { pi = (struct pool_item *)addr; pi->pi_magic = POOL_IMAGIC(ph, pi); - XSIMPLEQ_INSERT_TAIL(&ph->ph_items, pi, pi_list); + + if (o == 32) { + order = arc4random(); + o = 0; + } + if (ISSET(order, 1 << o++)) + XSIMPLEQ_INSERT_TAIL(&ph->ph_items, pi, pi_list); + else + XSIMPLEQ_INSERT_HEAD(&ph->ph_items, pi, pi_list); #ifdef DIAGNOSTIC if (POOL_PHPOISON(ph))