Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp991508pxb; Fri, 22 Apr 2022 16:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfuY2xc/9qSHw0ONMOobg+oLY/ksRjfwJbcWjnx+SLefBUeYR+BcIeLQKhqOcoYv7IAayG X-Received: by 2002:a17:902:6b0b:b0:158:d1e7:3d0f with SMTP id o11-20020a1709026b0b00b00158d1e73d0fmr6745979plk.71.1650668984091; Fri, 22 Apr 2022 16:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650668984; cv=none; d=google.com; s=arc-20160816; b=Vd2sBBeYrfIhUjcwHoHb9BxbWkc4eTDoqsRQ+1qcdSacRJv1dm/2xR+0+yv2JW7zOw 8/XMynKN40Np40CoPSk3Rc7c8C43IdenvL/0AYTqXeZ2M/SfYYFvuNcCQ22LFNVsxW2y zIrY6kJmBNn1Aj2P8uxB1FwemX/2ptEqabZHHAq11tU6SgqHGgO4VQhxXw2vcX4Y9cxh kiiZhrd9pWBJuDNpUZJqicP46ZsjPixtoamQRz6jsEzlE4mhAadOYTVENejUDmCI4lA6 3znpmZaUnWN7kSxJs2L+UKKJ3ikgyeR+9anq9yJQhIfvwJkiEOvrEVs91Sz0nyM+WoYQ 7R+g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rL5kLAHUgMipuKKRb+XGyKRYNNSGk0PTHcqnIpcFm1U=; b=OZyCeAhXk5XIO0rxW878lykac//HRoEu9XBhvMRvh9Dq2tc1uWXR9ZnAAy5HkwmGt4 KAR+Snt/hsML44QwF6yNM0XZfnsbeASbkERJrpIwiq4QEUfk8i6c3JVot2jK/y/pIpVc zNGiTJAIiMR9kb1Ix/FDEfNddg9lIQsv6kns/NCQoKuVk/qjXZ6BzK17S1g4CFkB1xkG Z+w9E0Ib5Ls496RZgww+cFFZRsaEXmLPVox2Sj4YhHpZeXY8wlA6nQEiH/VOSqtPJv6y ltTYT4T9EYG4FAv2eCsRoEl7uTa8i1Q4E/2v7c6R/eakHbORSu+bRMlO1AbeVCmK+IFc MDDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RKt6TbDA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x143-20020a633195000000b0039958cf0f48si8303002pgx.249.2022.04.22.16.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 16:09:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RKt6TbDA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46E63303811; Fri, 22 Apr 2022 15:09:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232246AbiDVWLt (ORCPT + 99 others); Fri, 22 Apr 2022 18:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231972AbiDVWJe (ORCPT ); Fri, 22 Apr 2022 18:09:34 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1744F2D8239; Fri, 22 Apr 2022 13:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650660986; x=1682196986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CuWq5/+Z/B81lbzlKa//2RLsdmx1GbsReZrpsHXJ32k=; b=RKt6TbDAScVHDD10ubDkWtlBKlUBA7VV5BHrLZs69PMe11QlxwALE6sM zfFaIUbkNwS7MJwu/VmsTErdULCP6v+2FzkmXOK4dL2NA58k8vBpfQjC+ 4Zy1wXukfFxVBOjzTxXS+Td4OqNaOufoP7LTynelzKrU1qvCv6vJ8qLY8 OtIJqsmNgY//Bd965oMK8A703sMqa7nmL2AL3rU1eEbk+bLW4FDul725h PLRe6EMrRm17v23AiDou2jCrLwrr7uuVKvBGDlSTW9EZsijOulWKpL6Ce UHbyJZIKARrRuoXB9rv5riJfb4rTg8oLhoo2VjpgRG2LdIvBOBlGRvUxl g==; X-IronPort-AV: E=McAfee;i="6400,9594,10324"; a="289897459" X-IronPort-AV: E=Sophos;i="5.90,282,1643702400"; d="scan'208";a="289897459" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2022 13:02:27 -0700 X-IronPort-AV: E=Sophos;i="5.90,282,1643702400"; d="scan'208";a="511719340" Received: from agluck-desk3.sc.intel.com ([172.25.222.78]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2022 13:02:27 -0700 From: Tony Luck To: hdegoede@redhat.com, markgross@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, corbet@lwn.net, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, jithu.joseph@intel.com, ashok.raj@intel.com, tony.luck@intel.com, rostedt@goodmis.org, dan.j.williams@intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@lists.linux.dev, ravi.v.shankar@intel.com Subject: [PATCH v4 05/10] platform/x86/intel/ifs: Check IFS Image sanity Date: Fri, 22 Apr 2022 13:02:14 -0700 Message-Id: <20220422200219.2843823-6-tony.luck@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220422200219.2843823-1-tony.luck@intel.com> References: <20220419163859.2228874-1-tony.luck@intel.com> <20220422200219.2843823-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jithu Joseph IFS image is designed specifically for a given family, model and stepping of the processor. Like Intel microcode header, the IFS image has the Processor Signature, Checksum and Processor Flags that must be matched with the information returned by the CPUID. Reviewed-by: Dan Williams Signed-off-by: Jithu Joseph Co-developed-by: Tony Luck Signed-off-by: Tony Luck --- drivers/platform/x86/intel/ifs/load.c | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c index 9fb71d38c819..aece78d1c757 100644 --- a/drivers/platform/x86/intel/ifs/load.c +++ b/drivers/platform/x86/intel/ifs/load.c @@ -2,9 +2,74 @@ /* Copyright(c) 2022 Intel Corporation. */ #include +#include +#include #include "ifs.h" +static int ifs_sanity_check(struct device *dev, + const struct microcode_header_intel *mc_header) +{ + unsigned long total_size, data_size; + u32 sum, i; + u8 *mc; + + total_size = get_totalsize(mc_header); + data_size = get_datasize(mc_header); + + if ((data_size + MC_HEADER_SIZE > total_size) || (total_size % sizeof(u32))) { + dev_err(dev, "bad ifs data file size.\n"); + return -EINVAL; + } + + if (mc_header->ldrver != 1 || mc_header->hdrver != 1) { + dev_err(dev, "invalid/unknown ifs update format.\n"); + return -EINVAL; + } + + mc = (u8 *)mc_header; + sum = 0; + i = total_size / sizeof(u32); + while (i--) + sum += ((u32 *)mc)[i]; + + if (sum) { + dev_err(dev, "bad ifs data checksum, aborting.\n"); + return -EINVAL; + } + + return 0; +} + +static bool find_ifs_matching_signature(struct device *dev, struct ucode_cpu_info *uci, + const struct microcode_header_intel *shdr) +{ + unsigned int mc_size; + + mc_size = get_totalsize(shdr); + + if (!mc_size || ifs_sanity_check(dev, shdr) < 0) { + dev_err(dev, "ifs sanity check failure\n"); + return false; + } + + if (!intel_cpu_signatures_match(uci->cpu_sig.sig, uci->cpu_sig.pf, shdr->sig, shdr->pf)) { + dev_err(dev, "ifs signature, pf not matching\n"); + return false; + } + + return true; +} + +static bool ifs_image_sanity_check(struct device *dev, const struct microcode_header_intel *data) +{ + struct ucode_cpu_info uci; + + intel_cpu_collect_info(&uci); + + return find_ifs_matching_signature(dev, &uci, data); +} + /* * Load ifs image. Before loading ifs module, the ifs image must be located * in /lib/firmware/intel/ifs and named as {family/model/stepping}.{testname}. @@ -24,5 +89,8 @@ void ifs_load_firmware(struct device *dev) return; } + if (!ifs_image_sanity_check(dev, (struct microcode_header_intel *)fw->data)) + dev_err(dev, "ifs header sanity check failed\n"); + release_firmware(fw); } -- 2.35.1