Messages in this thread | | | Subject | Re: [PATCH v5 3/6] x86/microcode/AMD: Check microcode container data in the early loader | From | "Maciej S. Szmigiero" <> | Date | Tue, 1 May 2018 00:27:34 +0200 |
| |
On 30.04.2018 11:05, Borislav Petkov wrote: > On Mon, Apr 23, 2018 at 11:34:08PM +0200, Maciej S. Szmigiero wrote: >> --- a/arch/x86/kernel/cpu/microcode/amd.c >> +++ b/arch/x86/kernel/cpu/microcode/amd.c >> @@ -216,29 +216,33 @@ static bool verify_patch(u8 family, const u8 *buf, size_t buf_size, bool early) >> * Returns the amount of bytes consumed while scanning. @desc contains all the >> * data we're going to use in later stages of the application. >> */ >> -static ssize_t parse_container(u8 *ucode, ssize_t size, struct cont_desc *desc) >> +static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc) >> { >> struct equiv_cpu_entry *eq; >> - ssize_t orig_size = size; >> + size_t orig_size = size; >> u32 *hdr = (u32 *)ucode; >> + u32 equiv_tbl_len; >> u16 eq_id; >> u8 *buf; >> >> - /* Am I looking at an equivalence table header? */ >> - if (hdr[0] != UCODE_MAGIC || >> - hdr[1] != UCODE_EQUIV_CPU_TABLE_TYPE || >> - hdr[2] == 0) >> + if (!verify_container(ucode, size, true)) >> + return 0; > > return CONTAINER_HDR_SZ; > > We want to make some forward progress after all.
Even if the container file main magic number is wrong? In this case parsing is terminated by returning a zero from the above function.
If we want to make the parser more resistant to garbage or forward-compatible to containers with a different main magic number in their headers we probably should return a length of a single byte here instead of 12 (CONTAINER_HDR_SZ) so the parser would correctly skip unknown data of size which isn't an integer multiple of this number.
Thanks, Maciej
| |