Received: by 2002:aa6:c429:0:b029:98:93ff:f56f with SMTP id g9csp3386276lkq; Mon, 23 Nov 2020 04:30:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDN9d6cIdiPMz+5RC3QJiaTQw4/BR36qLL8kcoays38GED1HNU9AvyhG5ErUKUYmH+mmCE X-Received: by 2002:aa7:c546:: with SMTP id s6mr46166317edr.114.1606134651396; Mon, 23 Nov 2020 04:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606134651; cv=none; d=google.com; s=arc-20160816; b=YFg4w1RVu6zTtltIfADZ6xfQVbZ7BDcI3jX7l1yyroJbKoy1JJoFXa+Fb7BmCL5iDI MqECoD88iu1PGf+r+ZgxMVLxS/tBSczgCOtyxZO8RALcGonyFH0TgBQA34hDmmHyQUV4 69+sE4tBLQUxAnU+tHdJ1JFDzPzU6rgaFnJ++5jj6+GDLHz7oiNiBjzzaXx2LFkPsEBS jwnAsnApIZeaWxK89KpLVWeiVLfJhzVSizHiITgq5D2FefpRDpjEyvY56ZyhddQmgR0y geH0YV0b5upkX1Q48I5/hnC0/n8gG236bc1IisnjdKGlbUZishR0TgB30zZZZMwmnP+r nhMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3AG0+6I8bqwHnlphFORvOCO+y5ICoxs4AY0oVvOCdLk=; b=y/bZXSP1w8KF0Cnf4WGVejAElcSRLsnC8iMxkuA0qqQMzw5rqViXVckxLuq3R2vN7S NtIEKi3AVJ/kD253/43viemM2PidwPj42W1cNw7KY9gi8p9qmqlDSnoPsdYYlVtA+u8+ jULaqW4+IJiloOv4SZd4N2mBaPpQz//IA7xls+KxHwuIUrlclfavpajkLJyPB98UrG1y k0/rPxMjC+JIoOjPrlfb5XKJ9XkqFrJhQ1N94PW5dwmvQhVxL+wqRg0nRRVnJl6IDV4B 8P+5Jr6G+bih9RNXpTx7+v7ZxzHrER1U3XuiiTChOM3Qsi7KZI0izaG89Rn7rc7ICBmy IaGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AtHlzR9w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb26si2246750ejb.328.2020.11.23.04.30.28; Mon, 23 Nov 2020 04:30:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AtHlzR9w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729497AbgKWM00 (ORCPT + 99 others); Mon, 23 Nov 2020 07:26:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:36104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730142AbgKWM0Z (ORCPT ); Mon, 23 Nov 2020 07:26:25 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAF5F20728; Mon, 23 Nov 2020 12:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134384; bh=rvtwpOY2qZD5jY9Rm8wCR7/h5Zars/46CGP8FGSjJ8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AtHlzR9woZYT4wY5DO/Odnu3W+TymcexuF8GVZoJBNu34NaTF4stqGbgJJ6bExk3G z5BmxbML7DO408lDTBebp+Un3jpVmGuVm9JIRLm6CgNsIZjYt2J13DhAfwjpaBZi39 45vIapS1A1xcpqApfrl8W+NOIw0FAIRyJakCZnos= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen Yu , Borislav Petkov Subject: [PATCH 4.9 47/47] x86/microcode/intel: Check patch signature before saving microcode for early loading Date: Mon, 23 Nov 2020 13:22:33 +0100 Message-Id: <20201123121807.829684525@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121805.530891002@linuxfoundation.org> References: <20201123121805.530891002@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen Yu commit 1a371e67dc77125736cc56d3a0893f06b75855b6 upstream. Currently, scan_microcode() leverages microcode_matches() to check if the microcode matches the CPU by comparing the family and model. However, the processor stepping and flags of the microcode signature should also be considered when saving a microcode patch for early update. Use find_matching_signature() in scan_microcode() and get rid of the now-unused microcode_matches() which is a good cleanup in itself. Complete the verification of the patch being saved for early loading in save_microcode_patch() directly. This needs to be done there too because save_mc_for_early() will call save_microcode_patch() too. The second reason why this needs to be done is because the loader still tries to support, at least hypothetically, mixed-steppings systems and thus adds all patches to the cache that belong to the same CPU model albeit with different steppings. For example: microcode: CPU: sig=0x906ec, pf=0x2, rev=0xd6 microcode: mc_saved[0]: sig=0x906e9, pf=0x2a, rev=0xd6, total size=0x19400, date = 2020-04-23 microcode: mc_saved[1]: sig=0x906ea, pf=0x22, rev=0xd6, total size=0x19000, date = 2020-04-27 microcode: mc_saved[2]: sig=0x906eb, pf=0x2, rev=0xd6, total size=0x19400, date = 2020-04-23 microcode: mc_saved[3]: sig=0x906ec, pf=0x22, rev=0xd6, total size=0x19000, date = 2020-04-27 microcode: mc_saved[4]: sig=0x906ed, pf=0x22, rev=0xd6, total size=0x19400, date = 2020-04-23 The patch which is being saved for early loading, however, can only be the one which fits the CPU this runs on so do the signature verification before saving. [ bp: Do signature verification in save_microcode_patch() and rewrite commit message. ] Fixes: ec400ddeff20 ("x86/microcode_intel_early.c: Early update ucode on Intel's CPU") Signed-off-by: Chen Yu Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org Link: https://bugzilla.kernel.org/show_bug.cgi?id=208535 Link: https://lkml.kernel.org/r/20201113015923.13960-1-yu.c.chen@intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/microcode/intel.c | 48 +--------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -147,51 +147,6 @@ load_microcode(struct mc_saved_data *mcs } } -/* - * Given CPU signature and a microcode patch, this function finds if the - * microcode patch has matching family and model with the CPU. - */ -static enum ucode_state -matching_model_microcode(struct microcode_header_intel *mc_header, - unsigned long sig) -{ - unsigned int fam, model; - unsigned int fam_ucode, model_ucode; - struct extended_sigtable *ext_header; - unsigned long total_size = get_totalsize(mc_header); - unsigned long data_size = get_datasize(mc_header); - int ext_sigcount, i; - struct extended_signature *ext_sig; - - fam = x86_family(sig); - model = x86_model(sig); - - fam_ucode = x86_family(mc_header->sig); - model_ucode = x86_model(mc_header->sig); - - if (fam == fam_ucode && model == model_ucode) - return UCODE_OK; - - /* Look for ext. headers: */ - if (total_size <= data_size + MC_HEADER_SIZE) - return UCODE_NFOUND; - - ext_header = (void *) mc_header + data_size + MC_HEADER_SIZE; - ext_sig = (void *)ext_header + EXT_HEADER_SIZE; - ext_sigcount = ext_header->count; - - for (i = 0; i < ext_sigcount; i++) { - fam_ucode = x86_family(ext_sig->sig); - model_ucode = x86_model(ext_sig->sig); - - if (fam == fam_ucode && model == model_ucode) - return UCODE_OK; - - ext_sig++; - } - return UCODE_NFOUND; -} - static int save_microcode(struct mc_saved_data *mcs, struct microcode_intel **mc_saved_src, @@ -332,7 +287,8 @@ get_matching_model_microcode(unsigned lo * the platform, we need to find and save microcode patches * with the same family and model as the BSP. */ - if (matching_model_microcode(mc_header, uci->cpu_sig.sig) != UCODE_OK) { + if (!find_matching_signature(mc_header, uci->cpu_sig.sig, + uci->cpu_sig.pf)) { ucode_ptr += mc_size; continue; }