Re: [kernel-hardening] [PATCH 09/38] usercopy: Mark kmalloc caches as usercopy caches
From: Jiri Slaby
Date: Tue Nov 12 2019 - 02:18:08 EST
On 11. 01. 18, 3:02, Kees Cook wrote:
> From: David Windsor <dave@xxxxxxxxxxxx>
>
> Mark the kmalloc slab caches as entirely whitelisted. These caches
> are frequently used to fulfill kernel allocations that contain data
> to be copied to/from userspace. Internal-only uses are also common,
> but are scattered in the kernel. For now, mark all the kmalloc caches
> as whitelisted.
>
> This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY
> whitelisting code in the last public patch of grsecurity/PaX based on my
> understanding of the code. Changes or omissions from the original code are
> mine and don't reflect the original grsecurity/PaX code.
>
> Signed-off-by: David Windsor <dave@xxxxxxxxxxxx>
> [kees: merged in moved kmalloc hunks, adjust commit log]
> Cc: Pekka Enberg <penberg@xxxxxxxxxx>
> Cc: David Rientjes <rientjes@xxxxxxxxxx>
> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-xfs@xxxxxxxxxxxxxxx
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
> Acked-by: Christoph Lameter <cl@xxxxxxxxx>
> ---
> mm/slab.c | 3 ++-
> mm/slab.h | 3 ++-
> mm/slab_common.c | 10 ++++++----
> 3 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/mm/slab.c b/mm/slab.c
> index b9b0df620bb9..dd367fe17a4e 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
...
> @@ -1098,7 +1099,8 @@ void __init setup_kmalloc_cache_index_table(void)
> static void __init new_kmalloc_cache(int idx, slab_flags_t flags)
> {
> kmalloc_caches[idx] = create_kmalloc_cache(kmalloc_info[idx].name,
> - kmalloc_info[idx].size, flags);
> + kmalloc_info[idx].size, flags, 0,
> + kmalloc_info[idx].size);
> }
>
> /*
> @@ -1139,7 +1141,7 @@ void __init create_kmalloc_caches(slab_flags_t flags)
>
> BUG_ON(!n);
> kmalloc_dma_caches[i] = create_kmalloc_cache(n,
> - size, SLAB_CACHE_DMA | flags);
> + size, SLAB_CACHE_DMA | flags, 0, 0);
Hi,
was there any (undocumented) reason NOT to mark DMA caches as usercopy?
We are seeing this on s390x:
> usercopy: Kernel memory overwrite attempt detected to SLUB object
'dma-kmalloc-1k' (offset 0, size 11)!
> ------------[ cut here ]------------
> kernel BUG at mm/usercopy.c:99!
See:
https://bugzilla.suse.com/show_bug.cgi?id=1156053
This indeed fixes it:
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1290,7 +1290,8 @@ void __init create_kmalloc_caches(slab_flags_t flags)
kmalloc_caches[KMALLOC_DMA][i] =
create_kmalloc_cache(
kmalloc_info[i].name[KMALLOC_DMA],
kmalloc_info[i].size,
- SLAB_CACHE_DMA | flags, 0, 0);
+ SLAB_CACHE_DMA | flags, 0,
+ kmalloc_info[i].size);
}
}
#endif
thanks,
--
js
suse labs