Skip to content

Commit 3c0f396

Browse files
committed
Merge tag 'slab-for-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab
Pull slab fixes from Vlastimil Babka: - Fix a possible use-after-free in SLUB's kmem_cache removal, introduced in this cycle, by Feng Tang. - WQ_MEM_RECLAIM dependency fix for the workqueue-based cpu slab flushing introduced in 5.15, by Maurizio Lombardi. - Add missing KASAN hooks in two kmalloc entry paths, by Peter Collingbourne. - A BUG_ON() removal in SLUB's kmem_cache creation when allocation fails (too small to possibly happen in practice, syzbot used fault injection), by Chao Yu. * tag 'slab-for-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab: mm: slub: fix flush_cpu_slab()/__free_slab() invocations in task context. mm/slab_common: fix possible double free of kmem_cache kasan: call kasan_malloc() from __kmalloc_*track_caller() mm/slub: fix to return errno if kmalloc() fails
2 parents c69cf88 + e45cc28 commit 3c0f396

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

mm/slab_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,16 @@ void slab_kmem_cache_release(struct kmem_cache *s)
475475
void kmem_cache_destroy(struct kmem_cache *s)
476476
{
477477
int refcnt;
478+
bool rcu_set;
478479

479480
if (unlikely(!s) || !kasan_check_byte(s))
480481
return;
481482

482483
cpus_read_lock();
483484
mutex_lock(&slab_mutex);
484485

486+
rcu_set = s->flags & SLAB_TYPESAFE_BY_RCU;
487+
485488
refcnt = --s->refcount;
486489
if (refcnt)
487490
goto out_unlock;
@@ -492,7 +495,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
492495
out_unlock:
493496
mutex_unlock(&slab_mutex);
494497
cpus_read_unlock();
495-
if (!refcnt && !(s->flags & SLAB_TYPESAFE_BY_RCU))
498+
if (!refcnt && !rcu_set)
496499
kmem_cache_release(s);
497500
}
498501
EXPORT_SYMBOL(kmem_cache_destroy);

mm/slub.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ static inline void stat(const struct kmem_cache *s, enum stat_item si)
310310
*/
311311
static nodemask_t slab_nodes;
312312

313+
/*
314+
* Workqueue used for flush_cpu_slab().
315+
*/
316+
static struct workqueue_struct *flushwq;
317+
313318
/********************************************************************
314319
* Core slab cache functions
315320
*******************************************************************/
@@ -2730,7 +2735,7 @@ static void flush_all_cpus_locked(struct kmem_cache *s)
27302735
INIT_WORK(&sfw->work, flush_cpu_slab);
27312736
sfw->skip = false;
27322737
sfw->s = s;
2733-
schedule_work_on(cpu, &sfw->work);
2738+
queue_work_on(cpu, flushwq, &sfw->work);
27342739
}
27352740

27362741
for_each_online_cpu(cpu) {
@@ -4858,6 +4863,8 @@ void __init kmem_cache_init(void)
48584863

48594864
void __init kmem_cache_init_late(void)
48604865
{
4866+
flushwq = alloc_workqueue("slub_flushwq", WQ_MEM_RECLAIM, 0);
4867+
WARN_ON(!flushwq);
48614868
}
48624869

48634870
struct kmem_cache *
@@ -4926,6 +4933,8 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
49264933
/* Honor the call site pointer we received. */
49274934
trace_kmalloc(caller, ret, s, size, s->size, gfpflags);
49284935

4936+
ret = kasan_kmalloc(s, ret, size, gfpflags);
4937+
49294938
return ret;
49304939
}
49314940
EXPORT_SYMBOL(__kmalloc_track_caller);
@@ -4957,6 +4966,8 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
49574966
/* Honor the call site pointer we received. */
49584967
trace_kmalloc_node(caller, ret, s, size, s->size, gfpflags, node);
49594968

4969+
ret = kasan_kmalloc(s, ret, size, gfpflags);
4970+
49604971
return ret;
49614972
}
49624973
EXPORT_SYMBOL(__kmalloc_node_track_caller);
@@ -5890,7 +5901,8 @@ static char *create_unique_id(struct kmem_cache *s)
58905901
char *name = kmalloc(ID_STR_LENGTH, GFP_KERNEL);
58915902
char *p = name;
58925903

5893-
BUG_ON(!name);
5904+
if (!name)
5905+
return ERR_PTR(-ENOMEM);
58945906

58955907
*p++ = ':';
58965908
/*
@@ -5948,6 +5960,8 @@ static int sysfs_slab_add(struct kmem_cache *s)
59485960
* for the symlinks.
59495961
*/
59505962
name = create_unique_id(s);
5963+
if (IS_ERR(name))
5964+
return PTR_ERR(name);
59515965
}
59525966

59535967
s->kobj.kset = kset;

0 commit comments

Comments
 (0)