Commit 993d0b28 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Kees Cook

usercopy: Handle vm_map_ram() areas

vmalloc does not allocate a vm_struct for vm_map_ram() areas.  That causes
us to deny usercopies from those areas.  This affects XFS which uses
vm_map_ram() for its directories.

Fix this by calling find_vmap_area() instead of find_vm_area().

Fixes: 0aef499f ("mm/usercopy: Detect vmalloc overruns")
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarUladzislau Rezki (Sony) <urezki@gmail.com>
Tested-by: default avatarZorro Lang <zlang@redhat.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220612213227.3881769-2-willy@infradead.org
parent 57cd6d15
...@@ -215,6 +215,7 @@ extern struct vm_struct *__get_vm_area_caller(unsigned long size, ...@@ -215,6 +215,7 @@ extern struct vm_struct *__get_vm_area_caller(unsigned long size,
void free_vm_area(struct vm_struct *area); void free_vm_area(struct vm_struct *area);
extern struct vm_struct *remove_vm_area(const void *addr); extern struct vm_struct *remove_vm_area(const void *addr);
extern struct vm_struct *find_vm_area(const void *addr); extern struct vm_struct *find_vm_area(const void *addr);
struct vmap_area *find_vmap_area(unsigned long addr);
static inline bool is_vm_area_hugepages(const void *addr) static inline bool is_vm_area_hugepages(const void *addr)
{ {
......
...@@ -173,16 +173,14 @@ static inline void check_heap_object(const void *ptr, unsigned long n, ...@@ -173,16 +173,14 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
} }
if (is_vmalloc_addr(ptr)) { if (is_vmalloc_addr(ptr)) {
struct vm_struct *area = find_vm_area(ptr); struct vmap_area *area = find_vmap_area((unsigned long)ptr);
unsigned long offset; unsigned long offset;
if (!area) { if (!area)
usercopy_abort("vmalloc", "no area", to_user, 0, n); usercopy_abort("vmalloc", "no area", to_user, 0, n);
return;
}
offset = ptr - area->addr; offset = (unsigned long)ptr - area->va_start;
if (offset + n > get_vm_area_size(area)) if ((unsigned long)ptr + n > area->va_end)
usercopy_abort("vmalloc", NULL, to_user, offset, n); usercopy_abort("vmalloc", NULL, to_user, offset, n);
return; return;
} }
......
...@@ -1798,7 +1798,7 @@ static void free_unmap_vmap_area(struct vmap_area *va) ...@@ -1798,7 +1798,7 @@ static void free_unmap_vmap_area(struct vmap_area *va)
free_vmap_area_noflush(va); free_vmap_area_noflush(va);
} }
static struct vmap_area *find_vmap_area(unsigned long addr) struct vmap_area *find_vmap_area(unsigned long addr)
{ {
struct vmap_area *va; struct vmap_area *va;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment