Skip to contentSkip to conversation

futexs: fix infinite loop in get_futex_key on huge page

PATCH In review Sonny Rao 3 participants 5 messages Jul 10, 2009 – Jul 11, 2009

lore
Share & tools
lore

Sonny Rao

author
#0 lore raw

PATCH 1/1 futexs: fix infinite loop in get_futex_key on huge page

get_futex_key() can infinitely loop if it is called on a virtual address that is within a huge page but not aligned to the beginning of that page. The call to get_user_pages_fast will return the struct page for a sub-page within the huge page and the check for page->mapping will always fail.

The fix is to call compound_head on the page before checking that it's mapped.

kernel/futex.c +1 -0
Index: linux-2.6.31-rc2/kernel/futex.c
===================================================================
@@ -247,6 +247,7 @@
 	if (err < 0)
 		return err;
 
+	page = compound_head(page);
 	lock_page(page);
 	if (!page->mapping) {
 		unlock_page(page);
#1 lore raw
Quoted 18 lines · Sonny Rao

get_futex_key() can infinitely loop if it is called on a virtual address that is within a huge page but not aligned to the beginning of that page. The call to get_user_pages_fast will return the struct page for a sub-page within the huge page and the check for page->mapping will always fail.

The fix is to call compound_head on the page before checking that it's mapped.

Index: linux-2.6.31-rc2/kernel/futex.c
===================================================================

kernel/futex.c line 253

Quoted 7 lines
kernel/futex.c +1 -0
@@ -247,6 +247,7 @@
 	if (err < 0)
 		return err;
 
+	page = compound_head(page);
 	lock_page(page);
 	if (!page->mapping) {
 		unlock_page(page);

Nice catch! Applied it to tip:core/urgent - Thomas, do you agree with the fix?

Ingo

#2 lore raw
Quoted 24 lines · Ingo Molnar
Quoted 21 lines · Sonny Rao

get_futex_key() can infinitely loop if it is called on a virtual address that is within a huge page but not aligned to the beginning of that page. The call to get_user_pages_fast will return the struct page for a sub-page within the huge page and the check for page->mapping will always fail.

The fix is to call compound_head on the page before checking that it's mapped.

Index: linux-2.6.31-rc2/kernel/futex.c
===================================================================

kernel/futex.c +0 -0
@@ -247,6 +247,7 @@
 	if (err < 0)
 		return err;
 
Quoted 7 lines

kernel/futex.c line 253

Quoted 4 lines
kernel/futex.c +1 -0
+	page = compound_head(page);
 	lock_page(page);
 	if (!page->mapping) {
 		unlock_page(page);

Nice catch! Applied it to tip:core/urgent - Thomas, do you agree with the fix?

Acked-by-me.

#3 lore raw

[tip:core/urgent] futexes: Fix infinite loop in get_futex_key() on huge page

In reply to Sonny Rao
Commit-ID:  7c8fa4f04ab956076605422d5ed37410893a8a73
Gitweb:     http://git.kernel.org/tip/7c8fa4f04ab956076605422d5ed37410893a8a73
Author:     Sonny Rao <[email protected]>
AuthorDate: Fri, 10 Jul 2009 18:13:13 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 11 Jul 2009 10:18:45 +0200

futexes: Fix infinite loop in get_futex_key() on huge page

get_futex_key() can infinitely loop if it is called on a virtual address that is within a huge page but not aligned to the beginning of that page. The call to get_user_pages_fast will return the struct page for a sub-page within the huge page and the check for page->mapping will always fail.

The fix is to call compound_head on the page before checking that it's mapped.

LKML-Reference: <[email protected]>

---
 kernel/futex.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kernel/futex.c +1 -0
index 794c862..0672ff8 100644
@@ -247,6 +247,7 @@ again:
 	if (err < 0)
 		return err;
 
+	page = compound_head(page);
 	lock_page(page);
 	if (!page->mapping) {
 		unlock_page(page);
#4 lore raw

[tip:core/urgent] futexes: Fix infinite loop in get_futex_key() on huge page

In reply to Sonny Rao
Commit-ID:  ce2ae53b750abfaa012ce408e93da131a5b5649b
Gitweb:     http://git.kernel.org/tip/ce2ae53b750abfaa012ce408e93da131a5b5649b
Author:     Sonny Rao <[email protected]>
AuthorDate: Fri, 10 Jul 2009 18:13:13 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 11 Jul 2009 12:40:44 +0200

futexes: Fix infinite loop in get_futex_key() on huge page

get_futex_key() can infinitely loop if it is called on a virtual address that is within a huge page but not aligned to the beginning of that page. The call to get_user_pages_fast will return the struct page for a sub-page within the huge page and the check for page->mapping will always fail.

The fix is to call compound_head on the page before checking that it's mapped.

LKML-Reference: <[email protected]>

---
 kernel/futex.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kernel/futex.c +1 -0
index 794c862..0672ff8 100644
@@ -247,6 +247,7 @@ again:
 	if (err < 0)
 		return err;
 
+	page = compound_head(page);
 	lock_page(page);
 	if (!page->mapping) {
 		unlock_page(page);