x86/microcode/AMD: Track patch allocation size explicitly
authorKees Cook <keescook@chromium.org>
Thu, 22 Sep 2022 03:10:10 +0000 (20:10 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:34:45 +0000 (12:34 +0200)
commit3c27a13807988fe4ef2f643575ed70a1361e8677
tree52755cb59fc6cf55ee933cae3cac305cdc6876c3
parent3e2b805a68ab1eef8d09f831160baba988d63965
x86/microcode/AMD: Track patch allocation size explicitly

[ Upstream commit 712f210a457d9c32414df246a72781550bc23ef6 ]

In preparation for reducing the use of ksize(), record the actual
allocation size for later memcpy(). This avoids copying extra
(uninitialized!) bytes into the patch buffer when the requested
allocation size isn't exactly the size of a kmalloc bucket.
Additionally, fix potential future issues where runtime bounds checking
will notice that the buffer was allocated to a smaller value than
returned by ksize().

Fixes: 757885e94a22 ("x86, microcode, amd: Early microcode patch loading support for AMD")
Suggested-by: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/lkml/CA+DvKQ+bp7Y7gmaVhacjv9uF6Ar-o4tet872h4Q8RPYPJjcJQA@mail.gmail.com/
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/include/asm/microcode.h
arch/x86/kernel/cpu/microcode/amd.c