mm/slub: only zero requested size of buffer for kzalloc when debug enabled
authorFeng Tang <feng.tang@intel.com>
Fri, 21 Oct 2022 03:24:03 +0000 (11:24 +0800)
committerVlastimil Babka <vbabka@suse.cz>
Thu, 10 Nov 2022 15:25:55 +0000 (16:25 +0100)
commit9ce67395f5a0cdec6ce152d26bfda13b98b25c01
tree5949b5aa83e3bed842ea147a41d3e10042ac9cca
parentc18c20f16219516b12a4f2fd29c25e06be97e064
mm/slub: only zero requested size of buffer for kzalloc when debug enabled

kzalloc/kmalloc will round up the request size to a fixed size
(mostly power of 2), so the allocated memory could be more than
requested. Currently kzalloc family APIs will zero all the
allocated memory.

To detect out-of-bound usage of the extra allocated memory, only
zero the requested part, so that redzone sanity check could be
added to the extra space later.

For kzalloc users who will call ksize() later and utilize this
extra space, please be aware that the space is not zeroed any
more when debug is enabled. (Thanks to Kees Cook's effort to
sanitize all ksize() user cases [1], this won't be a big issue).

[1]. https://lore.kernel.org/all/20220922031013.2150682-1-keescook@chromium.org/#r

Signed-off-by: Feng Tang <feng.tang@intel.com>
Acked-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slab.c
mm/slab.h
mm/slub.c