lkml.org 
[lkml]   [2019]   [Jan]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: BUG: unable to handle kernel NULL pointer dereference in setup_kmem_cache_node
On Wed, 2 Jan 2019, Dmitry Vyukov wrote:

> Am I missing something or __alloc_alien_cache misses check for
> kmalloc_node result?
>
> static struct alien_cache *__alloc_alien_cache(int node, int entries,
> int batch, gfp_t gfp)
> {
> size_t memsize = sizeof(void *) * entries + sizeof(struct alien_cache);
> struct alien_cache *alc = NULL;
>
> alc = kmalloc_node(memsize, gfp, node);
> init_arraycache(&alc->ac, entries, batch);
> spin_lock_init(&alc->lock);
> return alc;
> }
>


True _alloc_alien_cache() needs to check for NULL


From: Christoph Lameter <cl@linux.com>
Subject: slab: Alien caches must not be initialized if the allocation of the alien cache failed

Callers of __alloc_alien() check for NULL.
We must do the same check in __alloc_alien_cache to avoid NULL pointer dereferences
on allocation failures.

Signed-off-by: Christoph Lameter <cl@linux.com>


Index: linux/mm/slab.c
===================================================================
--- linux.orig/mm/slab.c
+++ linux/mm/slab.c
@@ -666,8 +666,10 @@ static struct alien_cache *__alloc_alien
struct alien_cache *alc = NULL;

alc = kmalloc_node(memsize, gfp, node);
- init_arraycache(&alc->ac, entries, batch);
- spin_lock_init(&alc->lock);
+ if (alc) {
+ init_arraycache(&alc->ac, entries, batch);
+ spin_lock_init(&alc->lock);
+ }
return alc;
}
\
 
 \ /
  Last update: 2019-01-02 16:51    [W:0.042 / U:2.324 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site