Skip to content

Commit d4a5fca

Browse files
rientjestorvalds
authored andcommitted
mm, slab: initialize object alignment on cache creation
Since commit 4590685 ("mm/sl[aou]b: Common alignment code"), the "ralign" automatic variable in __kmem_cache_create() may be used as uninitialized. The proper alignment defaults to BYTES_PER_WORD and can be overridden by SLAB_RED_ZONE or the alignment specified by the caller. This fixes https://bugzilla.kernel.org/show_bug.cgi?id=85031 Signed-off-by: David Rientjes <rientjes@google.com> Reported-by: Andrei Elovikov <a.elovikov@gmail.com> Acked-by: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 87e6d49 commit d4a5fca

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

‎mm/slab.c‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,8 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp)
21242124
int
21252125
__kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
21262126
{
2127-
size_t left_over, freelist_size, ralign;
2127+
size_t left_over, freelist_size;
2128+
size_t ralign = BYTES_PER_WORD;
21282129
gfp_t gfp;
21292130
int err;
21302131
size_t size = cachep->size;
@@ -2157,14 +2158,6 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
21572158
size &= ~(BYTES_PER_WORD - 1);
21582159
}
21592160

2160-
/*
2161-
* Redzoning and user store require word alignment or possibly larger.
2162-
* Note this will be overridden by architecture or caller mandated
2163-
* alignment if either is greater than BYTES_PER_WORD.
2164-
*/
2165-
if (flags & SLAB_STORE_USER)
2166-
ralign = BYTES_PER_WORD;
2167-
21682161
if (flags & SLAB_RED_ZONE) {
21692162
ralign = REDZONE_ALIGN;
21702163
/* If redzoning, ensure that the second redzone is suitably

0 commit comments

Comments
 (0)