Re: [PATCH] x86/microcode: Change checksum to u32

From: Henrique de Moraes Holschuh
Date: Sat Feb 27 2016 - 15:13:25 EST


On Sat, 27 Feb 2016, Borislav Petkov wrote:
> * sum is computed here:
>
> sum = orig_sum
> - (mc_header->sig + mc_header->pf + mc_header->cksum)
> + (ext_sig->sig + ext_sig->pf + ext_sig->cksum);

Well, orig_sum is always zero, because we exit early when it isn't. sum
really ought to be u32 in the first place (the only reason the code works is
because gcc isn't that insane), and the other fields should have been cast
to u32 as well before being added, for clarity if nothing else.

> and it adds a bunch of integers which can overflow, sure, but if it
> overflows, we exit early.

There is no reason why "sig + pf + cksum" wouldn't overflow 32 bits... in
fact, they often (always?) do on valid microcode.

And we need all of the intel-microcode-checksum-related arithmetic to be
done modulo-2^32, because it is expected to overflow *and* warp around when
it does so.

--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh