Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1550059

[PATCH] Fix SLAB freelist randomization duplicate entries

From Thomas Garnier <thgarnie@google.com>
Newsgroups linux.kernel
Subject [PATCH] Fix SLAB freelist randomization duplicate entries
Date 2017-01-03 19:20 +0100
Message-ID <sVBQL-1Kc-67@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


This patch fixes a bug in the freelist randomization code. When a high
random number is used, the freelist will contain duplicate entries. It
will result in different allocations sharing the same chunk.

Fixes: c7ce4f60ac19 ("mm: SLAB freelist randomization")
Signed-off-by: John Sperbeck <jsperbeck@google.com>
Reviewed-by: Thomas Garnier <thgarnie@google.com>
---
 mm/slab.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 29bc6c0dedd0..4f2ec6bb46eb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2457,7 +2457,6 @@ union freelist_init_state {
 		unsigned int pos;
 		unsigned int *list;
 		unsigned int count;
-		unsigned int rand;
 	};
 	struct rnd_state rnd_state;
 };
@@ -2483,8 +2482,7 @@ static bool freelist_state_initialize(union freelist_init_state *state,
 	} else {
 		state->list = cachep->random_seq;
 		state->count = count;
-		state->pos = 0;
-		state->rand = rand;
+		state->pos = rand % count;
 		ret = true;
 	}
 	return ret;
@@ -2493,7 +2491,9 @@ static bool freelist_state_initialize(union freelist_init_state *state,
 /* Get the next entry on the list and randomize it using a random shift */
 static freelist_idx_t next_random_slot(union freelist_init_state *state)
 {
-	return (state->list[state->pos++] + state->rand) % state->count;
+	if (state->pos >= state->count)
+		state->pos = 0;
+	return state->list[state->pos++];
 }
 
 /* Swap two freelist entries */
-- 
2.11.0.390.gc69c2f50cf-goog

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] Fix SLAB freelist randomization duplicate entries Thomas Garnier <thgarnie@google.com> - 2017-01-03 19:20 +0100
  Re: [PATCH] Fix SLAB freelist randomization duplicate entries Andrew Morton <akpm@linux-foundation.org> - 2017-01-06 01:40 +0100
    Re: [PATCH] Fix SLAB freelist randomization duplicate entries Thomas Garnier <thgarnie@google.com> - 2017-01-06 19:00 +0100
      Re: [PATCH] Fix SLAB freelist randomization duplicate entries Andrew Morton <akpm@linux-foundation.org> - 2017-01-06 21:50 +0100
        Re: [PATCH] Fix SLAB freelist randomization duplicate entries Thomas Garnier <thgarnie@google.com> - 2017-01-06 22:50 +0100

csiph-web