Commit d4a5fca592b9ab52b90bb261a90af3c8f53be011
Committed by
Linus Torvalds
1 parent
87e6d49a00
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
mm, slab: initialize object alignment on cache creation
Since commit 4590685546a3 ("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>
Showing 1 changed file with 2 additions and 9 deletions Side-by-side Diff
mm/slab.c
... | ... | @@ -2124,7 +2124,8 @@ |
2124 | 2124 | int |
2125 | 2125 | __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags) |
2126 | 2126 | { |
2127 | - size_t left_over, freelist_size, ralign; | |
2127 | + size_t left_over, freelist_size; | |
2128 | + size_t ralign = BYTES_PER_WORD; | |
2128 | 2129 | gfp_t gfp; |
2129 | 2130 | int err; |
2130 | 2131 | size_t size = cachep->size; |
... | ... | @@ -2156,14 +2157,6 @@ |
2156 | 2157 | size += (BYTES_PER_WORD - 1); |
2157 | 2158 | size &= ~(BYTES_PER_WORD - 1); |
2158 | 2159 | } |
2159 | - | |
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 | 2160 | |
2168 | 2161 | if (flags & SLAB_RED_ZONE) { |
2169 | 2162 | ralign = REDZONE_ALIGN; |