mm: vmap fix overflow
Subsystems (2)
PATCH 1/1 mm: vmap fix overflow
This patch is appropriate for 2.6.28 too.
--
The new vmap allocator can wrap the address and get confused in the case of large allocations or VMALLOC_END near the end of address space.
Problem reported by Christoph Hellwig on a 32-bit XFS workload.
--- mm/vmalloc.c | 6 ++++++ 1 file changed, 6 insertions(+)
mm/vmalloc.c +6 -0
@@ -334,6 +334,9 @@ retry: addr =ALIGN (vstart, align);spin_lock (&vmap_area_lock); +if (addr + size < addr) + goto overflow; +/* XXX: could have a last_hole cache */ n = vmap_area_root.rb_node;if (n) {
@@ -365,6 +368,8 @@ retry:while (addr + size > first->va_start && addr + size <= vend) { addr =ALIGN (first->va_end +PAGE_SIZE , align); +if (addr + size < addr) + goto overflow; n =rb_next (&first->rb_node);if (n)
@@ -375,6 +380,7 @@ retry: } found:if (addr + size > vend) { +overflow:spin_unlock (&vmap_area_lock);if (!purged) {purge_vmap_area_lazy ();
Andrew Morton
maintainerQuoted 38 lines · On Tue, 10 Feb 2009 06:51:19 +0100 Nick Piggin <[email protected]> wrote:
This patch is appropriate for 2.6.28 too.
--
The new vmap allocator can wrap the address and get confused in the case of large allocations or
VMALLOC_ENDnear the end of address space.Problem reported by Christoph Hellwig on a 32-bit XFS workload.
Signed-off-by Nick Piggin <[email protected]>--- mm/vmalloc.c | 6 ++++++ 1 file changed, 6 insertions(+)Index:
linux-2.6/mm/vmalloc.c
===================================================================mm/vmalloc.c +5
-0@@ -334,6 +334,9 @@ retry: addr =ALIGN (vstart, align);spin_lock (&vmap_area_lock); +if (addr + size < addr) + goto overflow; +/* XXX: could have a last_hole cache */ n = vmap_area_root.rb_node;if (n) {@@ -365,6 +368,8 @@ retry:while (addr + size > first->va_start && addr + size <= vend) { addr =ALIGN (first->va_end +PAGE_SIZE , align); +if (addr + size < addr) + goto overflow; n =rb_next (&first->rb_node);if (n)
mm/vmalloc.c retry: · line 386
Quoted 7 lines
mm/vmalloc.c +1
-0@@ -375,6 +380,7 @@ retry: } found:if (addr + size > vend) { +overflow:spin_unlock (&vmap_area_lock);if (!purged) {purge_vmap_area_lazy ();
well...
If a caller tries to allocate 0x1000 bytes at address 0xfffff000, this code will think that it overflowed. But it didn't.
Presumably nobody ever tries to do that, but it seems a bit sloppy?
Quoted 52 lines · Andrew Morton
Quoted 38 lines · On Tue, 10 Feb 2009 06:51:19 +0100 Nick Piggin <[email protected]> wrote:
This patch is appropriate for 2.6.28 too.
--
The new vmap allocator can wrap the address and get confused in the case of large allocations or
VMALLOC_ENDnear the end of address space.Problem reported by Christoph Hellwig on a 32-bit XFS workload.
Signed-off-by Nick Piggin <[email protected]>--- mm/vmalloc.c | 6 ++++++ 1 file changed, 6 insertions(+)Index:
linux-2.6/mm/vmalloc.c
===================================================================mm/vmalloc.c +5
-0@@ -334,6 +334,9 @@ retry: addr =ALIGN (vstart, align);spin_lock (&vmap_area_lock); +if (addr + size < addr) + goto overflow; +/* XXX: could have a last_hole cache */ n = vmap_area_root.rb_node;if (n) {@@ -365,6 +368,8 @@ retry:while (addr + size > first->va_start && addr + size <= vend) { addr =ALIGN (first->va_end +PAGE_SIZE , align); +if (addr + size < addr) + goto overflow; n =rb_next (&first->rb_node);if (n)mm/vmalloc.c retry: · line 386
Quoted 7 lines
mm/vmalloc.c +1
-0@@ -375,6 +380,7 @@ retry: } found:if (addr + size > vend) { +overflow:spin_unlock (&vmap_area_lock);if (!purged) {purge_vmap_area_lazy ();well...
Quoted 4 lines
If a caller tries to allocate
0x1000bytes at address0xfffff000, this code will think that it overflowed. But it didn't.Presumably nobody ever tries to do that, but it seems a bit sloppy?
Oh that's true, good catch. I guess that should be (addr + size - 1)? Because we care about the last byte that was actually allocated to us (inclusive, rather than exclusive).
Andrew Morton
maintainerQuoted 53 lines · On Thu, 12 Feb 2009 02:39:31 +0100 Nick Piggin <[email protected]> wrote:
Quoted 52 lines · Andrew Morton
Quoted 38 lines · On Tue, 10 Feb 2009 06:51:19 +0100 Nick Piggin <[email protected]> wrote:
This patch is appropriate for 2.6.28 too.
--
The new vmap allocator can wrap the address and get confused in the case of large allocations or
VMALLOC_ENDnear the end of address space.Problem reported by Christoph Hellwig on a 32-bit XFS workload.
Signed-off-by Nick Piggin <[email protected]>--- mm/vmalloc.c | 6 ++++++ 1 file changed, 6 insertions(+)Index:
linux-2.6/mm/vmalloc.c
===================================================================mm/vmalloc.c +5
-0@@ -334,6 +334,9 @@ retry: addr =ALIGN (vstart, align);spin_lock (&vmap_area_lock); +if (addr + size < addr) + goto overflow; +/* XXX: could have a last_hole cache */ n = vmap_area_root.rb_node;if (n) {@@ -365,6 +368,8 @@ retry:while (addr + size > first->va_start && addr + size <= vend) { addr =ALIGN (first->va_end +PAGE_SIZE , align); +if (addr + size < addr) + goto overflow; n =rb_next (&first->rb_node);if (n)mm/vmalloc.c retry: · line 386
Quoted 7 lines
mm/vmalloc.c +1
-0@@ -375,6 +380,7 @@ retry: } found:if (addr + size > vend) { +overflow:spin_unlock (&vmap_area_lock);if (!purged) {purge_vmap_area_lazy ();well...
Quoted 8 lines
Quoted 4 lines
If a caller tries to allocate
0x1000bytes at address0xfffff000, this code will think that it overflowed. But it didn't.Presumably nobody ever tries to do that, but it seems a bit sloppy?
Oh that's true, good catch. I guess that should be (addr + size - 1)? Because we care about the last byte that was actually allocated to us (inclusive, rather than exclusive).
That would work. It wouldd give weird results for size==0, but probably that's already checked for somewhere(?)
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Thu, 12 Feb 2009 02:39:31 +0100 Nick Piggin <[email protected]> wrote:
Oh that's true, good catch. I guess that should be (addr + size - 1)? Because we care about the last byte that was actually allocated to us (inclusive, rather than exclusive).
That would work. It wouldd give weird results for size==0, but probably that's already checked for somewhere(?)
It's checked down in __get_vm_area_node.