* [PATCH] ksm: fix rmap_item use after free
@ 2009-06-03 14:45 Andrea Arcangeli
2009-06-03 14:47 ` [PATCH] ksm: fix losing visibility of part of rmap_item->next list Andrea Arcangeli
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Arcangeli @ 2009-06-03 14:45 UTC (permalink / raw)
To: akpm; +Cc: hugh, linux-kernel, Izik Eidus, nickpiggin, chrisw, linux-mm, riel
From: Andrea Arcangeli <aarcange@redhat.com>
This avoid crashing with slab debugging enabled by removing a window
for memory corruption if freed slab entries are reused before we read
the next pointer. Against mmotm.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
diff --git a/mm/ksm.c b/mm/ksm.c
index 74d921b..f060e87 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -892,7 +892,7 @@ static struct rmap_item *stable_tree_search(struct page *page,
{
struct rb_node *node = root_stable_tree.rb_node;
struct tree_item *tree_item;
- struct rmap_item *found_rmap_item;
+ struct rmap_item *found_rmap_item, *next_rmap_item;
while (node) {
int ret;
@@ -907,9 +907,11 @@ static struct rmap_item *stable_tree_search(struct page *page,
found_rmap_item->address == rmap_item->address)) {
if (!is_zapped_item(found_rmap_item, page2))
break;
+ next_rmap_item = found_rmap_item->next;
remove_rmap_item_from_tree(found_rmap_item);
- }
- found_rmap_item = found_rmap_item->next;
+ found_rmap_item = next_rmap_item;
+ } else
+ found_rmap_item = found_rmap_item->next;
}
if (!found_rmap_item)
goto out_didnt_find;
@@ -959,7 +961,7 @@ static int stable_tree_insert(struct page *page,
while (*new) {
int ret;
- struct rmap_item *insert_rmap_item;
+ struct rmap_item *insert_rmap_item, *next_rmap_item;
tree_item = rb_entry(*new, struct tree_item, node);
BUG_ON(!tree_item);
@@ -973,9 +975,11 @@ static int stable_tree_insert(struct page *page,
insert_rmap_item->address == rmap_item->address)) {
if (!is_zapped_item(insert_rmap_item, page2))
break;
+ next_rmap_item = insert_rmap_item->next;
remove_rmap_item_from_tree(insert_rmap_item);
- }
- insert_rmap_item = insert_rmap_item->next;
+ insert_rmap_item = next_rmap_item;
+ } else
+ insert_rmap_item = insert_rmap_item->next;
}
if (!insert_rmap_item)
return 1;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] ksm: fix losing visibility of part of rmap_item->next list
2009-06-03 14:45 [PATCH] ksm: fix rmap_item use after free Andrea Arcangeli
@ 2009-06-03 14:47 ` Andrea Arcangeli
0 siblings, 0 replies; 2+ messages in thread
From: Andrea Arcangeli @ 2009-06-03 14:47 UTC (permalink / raw)
To: akpm; +Cc: hugh, linux-kernel, Izik Eidus, nickpiggin, chrisw, linux-mm, riel
From: Andrea Arcangeli <aarcange@redhat.com>
The tree_item->rmap_item is the head of the list and as such it must
not be overwritten except in the case that the element we removed
(rmap_item) was the previous head of the list, in which case it would
also have rmap_item->prev set to null.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
diff --git a/mm/ksm.c b/mm/ksm.c
index 74d921b..6d8dfee 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -397,10 +397,10 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item)
free_tree_item(tree_item);
nnodes_stable_tree--;
} else if (!rmap_item->prev) {
+ BUG_ON(tree_item->rmap_item != rmap_item);
tree_item->rmap_item = rmap_item->next;
- } else {
- tree_item->rmap_item = rmap_item->prev;
- }
+ } else
+ BUG_ON(tree_item->rmap_item == rmap_item);
} else {
/*
* We dont rb_erase(&tree_item->node) here, beacuse
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-06-03 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-03 14:45 [PATCH] ksm: fix rmap_item use after free Andrea Arcangeli
2009-06-03 14:47 ` [PATCH] ksm: fix losing visibility of part of rmap_item->next list Andrea Arcangeli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox