Received: by 10.213.65.68 with SMTP id h4csp519920imn; Tue, 20 Mar 2018 08:45:10 -0700 (PDT) X-Google-Smtp-Source: AG47ELv3oBXR1oCPaf6W0QqG4dVBmAKv5DlgB1aruR7HUjk9TcyCla5yQYz6jgbifC5pjULVo/ud X-Received: by 2002:a17:902:44c:: with SMTP id 70-v6mr17322507ple.354.1521560710529; Tue, 20 Mar 2018 08:45:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521560710; cv=none; d=google.com; s=arc-20160816; b=0LV6WBXI+ZEgrBifp23kzZLnHyC28Ur/Pp4dA2fnSC/ysNvqno/1xpIUm1XTQuSQBJ 8jyC7SeyZDbiHIu0V9s1fe14sqdK4Pkb4x2xgJL1fBNVN4NW8lcFsCvDQTRpCY22rChP zv93++2U8ETs0zBm5Yc0VzbgMkS62XqdiPQmyvvr2ohMUTxo299w+QUPV+h55rm21zWi L6cVozSnpt1nhiNp0Nv88VCYyFIydc/ovHaTwUSyDbc/gqlj7B70b8Gw/Te3rPzuPM3Z xFy3ma/n/QiGKMJ70yozvE0tztYv6fO6IUuEj55pnEnUoUrBnDFNmAG5ymKdYBmAVI6s Yc0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=qqqbfVdFOg867SRul3nVzO+nf3AaZAIOfUtQWaWgwx8=; b=EotZO2gzHqssu4nGTi6t/xTbU04tnpKIFrONbeFrXwmQY6h464c7E6UbrjbPGzSpeY s+/dROzZUe3QXU8fAqUR0iMm/P/UUH/et2HnIXj05bClYTo+B5DNHYVSPvhnKrqQLGGO vWsBaZSFodaU564w4F0AhqGcgTNc7hF7Tc14WSvwwg4T15rgmgomTXBy8v9LByN/e9Xn v6wGkWsNlxOYgmEd6P5EoAojOhztbJ3DP+dgSjP/ADRJYGMTMMvLAjf/67pRlvXCmnMx NygSM/dLPdkQhnpOoPm2gaJk0ggCe5pSDVIYWcb3q+bFSGUVfAzdf4BXOSLbXRntoQuI oJ3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si1463768pfj.402.2018.03.20.08.44.55; Tue, 20 Mar 2018 08:45:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751459AbeCTPm0 (ORCPT + 99 others); Tue, 20 Mar 2018 11:42:26 -0400 Received: from mail.skyhub.de ([5.9.137.197]:48900 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186AbeCTPmV (ORCPT ); Tue, 20 Mar 2018 11:42:21 -0400 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Kct4BbOm1uwS; Tue, 20 Mar 2018 16:42:04 +0100 (CET) Received: from pd.tnic (unknown [165.204.77.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 45A561EC0A63; Tue, 20 Mar 2018 16:42:04 +0100 (CET) Date: Tue, 20 Mar 2018 16:41:47 +0100 From: Borislav Petkov To: "Maciej S. Szmigiero" Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 02/10] x86/microcode/AMD: Check equivalence table length in the early loader Message-ID: <20180320154147.GA6815@cz.tnic> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 16, 2018 at 12:07:50AM +0100, Maciej S. Szmigiero wrote: > Before loading a CPU equivalence table from a microcode container file we > need to verify whether this file is actually large enough to contain the > table of a size indicated in this file. > If it is not, there is no point of continuing with loading it since > microcode patches are located after the equivalence table anyway. > > This patch adds these checks to the early loader. > > Signed-off-by: Maciej S. Szmigiero > --- > arch/x86/kernel/cpu/microcode/amd.c | 35 +++++++++++++++++++++++------------ > 1 file changed, 23 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c > index 6a93be0f771c..138c9fb983f2 100644 > --- a/arch/x86/kernel/cpu/microcode/amd.c > +++ b/arch/x86/kernel/cpu/microcode/amd.c > @@ -80,20 +80,33 @@ static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig) > * 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; > + unsigned int cont_magic, cont_type; > + size_t equiv_tbl_len; > u16 eq_id; > u8 *buf; > > + if (size < CONTAINER_HDR_SZ) > + return 0; > + > + cont_magic = hdr[0]; > + cont_type = hdr[1]; > + equiv_tbl_len = hdr[2]; All three are u32. > /* Am I looking at an equivalence table header? */ > - if (hdr[0] != UCODE_MAGIC || > - hdr[1] != UCODE_EQUIV_CPU_TABLE_TYPE || > - hdr[2] == 0) > + if (cont_magic != UCODE_MAGIC || > + cont_type != UCODE_EQUIV_CPU_TABLE_TYPE || > + equiv_tbl_len == 0) > return CONTAINER_HDR_SZ; > > + if (equiv_tbl_len < sizeof(*eq) || If you do this, then the above == 0 check can go. > + size - CONTAINER_HDR_SZ < equiv_tbl_len) > + return size; > + > buf = ucode; > > eq = (struct equiv_cpu_entry *)(buf + CONTAINER_HDR_SZ); -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. Srsly.