Skip to contentSkip to conversation

Fix SLAB freelist randomization duplicate entries

PATCH Applied Thomas Garnier 2 participants 5 messages Jan 3, 2017 – Jan 6, 2017 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix SLAB freelist randomization duplicate entries

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")
---
 mm/slab.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/slab.c +4 -4
index 29bc6c0dedd0..4f2ec6bb46eb 100644
@@ -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 */
Signature · 7 lines
2.11.0.390.gc69c2f50cf-goog

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw
Quoted 3 lines · On Tue, 3 Jan 2017 10:19:08 -0800 Thomas Garnier <[email protected]> wrote:

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.

Important: what are the user-visible runtime effects of the bug?

Quoted 3 lines
Fixes c7ce4f60ac19 ("mm: SLAB freelist randomization")

This should have been signed off by yourself.

I'm guessing that the author was in fact John? If so, you should indicate this by putting his From: line at the start of the changelog. Otherwise, authorship will default to the sender (ie, yourself).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Tue, 3 Jan 2017 10:19:08 -0800 Thomas Garnier <[email protected]> wrote:

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.

Important: what are the user-visible runtime effects of the bug?

It will result in odd behaviours and crashes. It should be uncommon but it depends on the machines. We saw it happening more often on some machines (every few hours of running tests).

Quoted 11 lines
Quoted 4 lines
Fixes c7ce4f60ac19 ("mm: SLAB freelist randomization")

This should have been signed off by yourself.

I'm guessing that the author was in fact John? If so, you should indicate this by putting his From: line at the start of the changelog. Otherwise, authorship will default to the sender (ie, yourself).

Sorry, I though the sign-off was enough. Do you want me to send a v2?

Signature · 7 lines
Thomas

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#3 lore raw
Quoted 7 lines · On Fri, 6 Jan 2017 09:58:48 -0800 Thomas Garnier <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Tue, 3 Jan 2017 10:19:08 -0800 Thomas Garnier <[email protected]> wrote:

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.

Quoted 5 lines
Quoted 1 line

Important: what are the user-visible runtime effects of the bug?

It will result in odd behaviours and crashes. It should be uncommon but it depends on the machines. We saw it happening more often on some machines (every few hours of running tests).

So should the fix be backported into -stable kernels?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes c7ce4f60ac19 ("mm: SLAB freelist randomization")
Quoted 8 lines
Quoted 6 lines

This should have been signed off by yourself.

I'm guessing that the author was in fact John? If so, you should indicate this by putting his From: line at the start of the changelog. Otherwise, authorship will default to the sender (ie, yourself).

Sorry, I though the sign-off was enough. Do you want me to send a v2?

I have the patch as

From: John Sperbeck <[email protected]>

Is that correct? Is John the primary author?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Fri, 6 Jan 2017 09:58:48 -0800 Thomas Garnier <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Tue, 3 Jan 2017 10:19:08 -0800 Thomas Garnier <[email protected]> wrote:

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.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Important: what are the user-visible runtime effects of the bug?

It will result in odd behaviours and crashes. It should be uncommon but it depends on the machines. We saw it happening more often on some machines (every few hours of running tests).

So should the fix be backported into -stable kernels?

I think it should, yes.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes c7ce4f60ac19 ("mm: SLAB freelist randomization")
Quoted 8 lines
Quoted 6 lines

This should have been signed off by yourself.

I'm guessing that the author was in fact John? If so, you should indicate this by putting his From: line at the start of the changelog. Otherwise, authorship will default to the sender (ie, yourself).

Sorry, I though the sign-off was enough. Do you want me to send a v2?

Quoted 7 lines

I have the patch as

From: John Sperbeck <[email protected]>

Is that correct? Is John the primary author?

That's correct.

Signature · 7 lines
Thomas

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>