Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2815241rdb; Wed, 4 Oct 2023 12:14:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFfYUlqVJzLn2MWSdKUcKLkZlEuJeu6ZoPlg/7D91ytRm+lo+2N+y3g04H//d/vezg+Vrw X-Received: by 2002:a17:903:1c8:b0:1c0:afda:7707 with SMTP id e8-20020a17090301c800b001c0afda7707mr762022plh.34.1696446882907; Wed, 04 Oct 2023 12:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696446882; cv=none; d=google.com; s=arc-20160816; b=rAbM+kiJvf3qzxGiSZi4t2s0v2tbB80wb+JAPFWtdyKGhrCAFQ4X1tUVju/pBTrxA2 oOHOxLOkOKL5MAI/ZpfSUMxF1ByKwxghZrsePIFfdqpwMRzON6oo4XDs30CifJrq6TFl kTW59ye8nO46tG8GKj21TQpKeGLKZ0XkTTOncHxmu9J0pcL0LbS9nGPcZcKydua1xNKs /TA1WBU2vbFCoHMGOcJS3OTvDM7ps17xf2sn8EYICagR4AY2SKz6RzGWVCThoLlEJDal ABJhOjHk9lpyOTGis4SJZsBWG/xXB5AJeE5js5eIT0gi2NCIGCeUU06rJz72k/yYy9+G fWNA== 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=OhqNiI+AkoeqQKJX6Gt8w7NxLSnlWzxNG+5RKpNibLQ=; fh=DZTEBuCdFfe2DSdaI+6ceTR59ce872SNjmboNXW/0pA=; b=l3v8A1b6uzn6qMGH6wW1Rv3Do3UuyMW6bwpJzHZnKXJvYEmEnTOsWL4UxubHT5Ofc3 9+Jt9hb2VcmmKmKXg+S0yByfkimYuHAKrHFJVWnTiYuBT4tZDmU5PwehT6h68Oa3yANb 8kIVXn4RGjwHRLtd2PWH27AhvNZQ5XQHFDgId0R91iipxGTexKc9IVo7fYfOnxaL2SFi 9SdJXqIMJ5scFBRDeW0HuZxTVGkNR7aD8JV7QwusSnkOXIujRpIovLVjNFlucCxSJtT8 kBx98u2JvmSAygfirilJ3ycvffpQ+4mpvaFw/6Z15JfQiTktogRqqzlIr/Yv3/tRH1re zBjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H+KHdJmV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id lc6-20020a170902fa8600b001c5616520cfsi3989756plb.204.2023.10.04.12.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 12:14:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H+KHdJmV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 268CA8217ECE; Wed, 4 Oct 2023 12:14:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245520AbjJDTOf (ORCPT + 99 others); Wed, 4 Oct 2023 15:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245387AbjJDTO1 (ORCPT ); Wed, 4 Oct 2023 15:14:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B724902B; Wed, 4 Oct 2023 12:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696446021; x=1727982021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cwaZnSVcVuM6qrMky+ZTKlliEs+Pp1T+fUkqoVUBGYQ=; b=H+KHdJmVmDd/Lf4DqmQLN6vmk17x327AyrdEmEtAq8tkB6PViwUPVd+p +SjVO7ebd5S8xKVI9D2N8q/s1I9ubS/zpirdbdzdJIEFhmn7XtyWuajWE Bvclo535rffotEoFI0gahNJh1gTVJaKd8rVx0bRJ4Msbu7bS7D2Ygd3TN OXO8+IPmJZCS/XO/OVS2uk26qfwST6IgCi0LXgZNStqX6lftSFtHl/15T fNlrAaD1biSjewSf4m3OiLkj8xSbD8AsiD47BQnM9a/hyhrDFeM8ARlkk l9dWjvxm3/ZLbFL5WOKSNZJLnDg3S6dWK+BfSmAXxnx89uKt5nSjtW/i3 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10853"; a="386097073" X-IronPort-AV: E=Sophos;i="6.03,201,1694761200"; d="scan'208";a="386097073" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2023 12:00:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10853"; a="895093750" X-IronPort-AV: E=Sophos;i="6.03,201,1694761200"; d="scan'208";a="895093750" Received: from jithujos.sc.intel.com ([172.25.103.66]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2023 11:58:45 -0700 From: Jithu Joseph 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, rostedt@goodmis.org, jithu.joseph@intel.com, ashok.raj@intel.com, tony.luck@intel.com, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@lists.linux.dev, ravi.v.shankar@intel.com, pengfei.xu@intel.com, ilpo.jarvinen@linux.intel.com Subject: [PATCH v3 5/9] platform/x86/intel/ifs: Validate image size Date: Wed, 4 Oct 2023 11:56:07 -0700 Message-Id: <20231004185607.3028392-1-jithu.joseph@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 12:14:41 -0700 (PDT) Perform additional validation prior to loading IFS image. Error out if the size of the file being loaded doesn't match the size specified in the header. Signed-off-by: Jithu Joseph Reviewed-by: Tony Luck Reviewed-by: Ilpo Järvinen Tested-by: Pengfei Xu --- - changed the dev_err printk format specifiers (Ilpo Järvinen) drivers/platform/x86/intel/ifs/load.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c index 6b827247945b..582f1801aaaa 100644 --- a/drivers/platform/x86/intel/ifs/load.c +++ b/drivers/platform/x86/intel/ifs/load.c @@ -375,6 +375,7 @@ int ifs_load_firmware(struct device *dev) { const struct ifs_test_caps *test = ifs_get_test_caps(dev); struct ifs_data *ifsd = ifs_get_data(dev); + unsigned int expected_size; const struct firmware *fw; char scan_path[64]; int ret = -EINVAL; @@ -389,6 +390,13 @@ int ifs_load_firmware(struct device *dev) goto done; } + expected_size = ((struct microcode_header_intel *)fw->data)->totalsize; + if (fw->size != expected_size) { + dev_err(dev, "File size mismatch (expected %u, actual %zu). Corrupted IFS image.\n", + expected_size, fw->size); + return -EINVAL; + } + ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data); if (ret) goto release; -- 2.25.1