Skip to contentSkip to conversation

Prevent NULL pointer deref in grab_swap_token

PATCH In review Dean Roe 4 participants 5 messages Mar 7, 2006 – Mar 8, 2006 Memory management

lore
Share & tools
lore

Dean Roe

author
#0 lore raw

PATCH 1/1 Prevent NULL pointer deref in grab_swap_token

grab_swap_token() assumes that the current process has an mm struct, which is not true for kernel threads invoking get_user_pages(). Since this should be extremely rare, just return from grab_swap_token() without doing anything.

mm/thrash.c +3 -0
Index: linux-2.6/mm/thrash.c
===================================================================
@@ -54,6 +54,9 @@
 	struct mm_struct *mm;
 	int reason;
 
+	if (current->mm == NULL)
+		return;
+
 	/* We have the token. Let others know we still need it. */
 	if (has_swap_token(current->mm)) {
 		current->mm->recent_pagein = 1;
#1 lore raw
Quoted 6 lines · Dean Roe

grab_swap_token() assumes that the current process has an mm struct, which is not true for kernel threads invoking get_user_pages(). Since this should be extremely rare, just return from grab_swap_token() without doing anything.

Fair enough.

Which kernel threads are running get_user_pages()?

#2 lore raw
In reply to Dean Roe
Quoted 4 lines · Dean Roe

grab_swap_token() assumes that the current process has an mm struct, which is not true for kernel threads invoking get_user_pages(). Since this should be extremely rare, just return from grab_swap_token() without doing anything.

There's a few things that will break if a kernel thread calls get_user_pages, so we should rather fix those.

#3 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Dean Roe

grab_swap_token() assumes that the current process has an mm struct, which is not true for kernel threads invoking get_user_pages(). Since this should be extremely rare, just return from grab_swap_token() without doing anything.

There's a few things that will break if a kernel thread calls get_user_pages, so we should rather fix those.

What things will break? Anything which dinks with current->mm in or under get_user_pages() is probably already broken.

#4 lore raw
In reply to Dean Roe
Quoted 2 lines · Dean Roe

grab_swap_token() assumes that the current process has an mm struct, which is not true for kernel threads invoking get_user_pages().

well WHICH user ? ;)