x86/microcode/intel: Refactor Intel microcode blob loading
authorJann Horn <jannh@google.com>
Thu, 4 Apr 2019 11:11:28 +0000 (13:11 +0200)
committerBorislav Petkov <bp@suse.de>
Wed, 10 Apr 2019 20:40:25 +0000 (22:40 +0200)
commit7e94a7b659eefedda82cde97229a26f319fb1182
tree2a2ecc5eb53754522f0c3112bb6626c3f23ed13e
parent79a3aaa7b82e3106be97842dedfd8429248896e6
x86/microcode/intel: Refactor Intel microcode blob loading

Change generic_load_microcode() to use the iov_iter API instead of a
clumsy open-coded version which has to pay attention to __user data
or kernel data, depending on the loading method. This allows to avoid
explicit casting between user and kernel pointers.

Because the iov_iter API makes it hard to read the same location twice,
as a side effect, also fix a double-read of the microcode header (which
could e.g. lead to out-of-bounds reads in microcode_sanity_check()).

Not that it matters much, only root is allowed to load microcode
anyway...

 [ bp: Massage a bit, sort function-local variables. ]

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190404111128.131157-1-jannh@google.com
arch/x86/kernel/cpu/microcode/intel.c