Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp20937rdb; Fri, 29 Sep 2023 15:10:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPyok0Ie+oFpTFqER2Ci0eNWg8TpySxsAKEbfOLjcXf65hi0nUjXnXaOMnqAlX7p6O5ukR X-Received: by 2002:a05:6808:1ab2:b0:3ae:1e08:4209 with SMTP id bm50-20020a0568081ab200b003ae1e084209mr5347056oib.39.1696025419277; Fri, 29 Sep 2023 15:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696025419; cv=none; d=google.com; s=arc-20160816; b=qF4pR8Gk0huV3pjnp3ZigjzqzEn1QG+JbL/Q7ifSla8/xtzYaTMMxf1o3ko21O4AK1 LUTP3lBH7s6bWBrR5l2zGIg+LNm+7VD+0670QaGHgwnCbxLH38qIbIck59wOAvKXkrq/ SNuokUvH1iuoYPbdCC1N4TFbSirmA/gAm5gxndiODfuMpRePkGZ3PiX39kc2VGaFSR7T twCRz1E2QvSzOgLXmbf8PNq+k9gwNFBCvN46BpuCpvMPIJmU2cA5XrqhMiVHpfSA6fnO ZrFMuZ+MZJbs09g5eYeGjnZg1zDGFcJ2qdF39cAm+P0z4lXWEYZ/3vX96KudpTREldv5 RHDQ== 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=Bqj4mG9txmrPkkjf2oCH3Pf8ALKTSxdhNA63Hh0WDAo=; fh=DZTEBuCdFfe2DSdaI+6ceTR59ce872SNjmboNXW/0pA=; b=ae2NA51mslkpe/fy7/E+LwOEvcex5wnSjRiNxZXLmzAi0/pRwTdDmcbNzAvz56tu9d AzDHxfhxX4t64mmonqotNGzD9Ap/cLNLB2aMpsY/AJKjbwkGmb9MOaGmzqRQCpIUWcA1 Otwz4s9EfUUkjSgPaOaRs1uunBH1Qc3zy7p2E1+GDkSXvkbIvBUX8Q7P1Ryr58Q1MUeU r4S3OGCgOW8EP/tWP0APbW0qZo9q4/diN59K0KWKP/HssadcjCZdoT2FFt8ttUgjp0Ej VfBwkUop6mpIpysn3L2kZlK5BCkKeVhWQKcrGpHpUzuBEbuxF/M8iiM2e1fLjMGK4C49 BO1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WI1idGjn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id w20-20020a63fb54000000b00578c10ff649si21746583pgj.796.2023.09.29.15.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 15:10:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WI1idGjn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 840D88051907; Fri, 29 Sep 2023 13:45:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233876AbjI2Upm (ORCPT + 99 others); Fri, 29 Sep 2023 16:45:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233807AbjI2Up1 (ORCPT ); Fri, 29 Sep 2023 16:45:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D561B9; Fri, 29 Sep 2023 13:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696020324; x=1727556324; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5hK8PYdSqpMVTtIO5x+qGkBJOJzZIeEW/a5RmMzipn4=; b=WI1idGjnod0AUE7lht+lm/cl6rHSrXvVhrchdAyIJ3rfsXaA2/MJQRDB CmBDUj/EChSjvTWBUuvbs7AAo/cfPBeV0E8Aj23EP3qbKVyUpsKmjHM9S bgnJfgoN2i5jrAuAqj/Rz6GZDItkaP3bWiNXouH0wbEYxM4mw1ON3Wp9f g04FFXzryt+504ToSgYMAvwIwvSVeyq7nKlRoxaSqyMvWBvKutHDI9Xjz ZJXj5g9Eh2JRBk7MgT/5xh/tZ/JmkmROs4Z0qRstbMOW9X1b9xQc/9goT po6S/peTMa6wLYS60909d9gHXEWoAf4npkoMZr+JrvgOIrktaIUPmg1Ik w==; X-IronPort-AV: E=McAfee;i="6600,9927,10848"; a="468654460" X-IronPort-AV: E=Sophos;i="6.03,188,1694761200"; d="scan'208";a="468654460" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2023 13:28:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10848"; a="893539240" X-IronPort-AV: E=Sophos;i="6.03,188,1694761200"; d="scan'208";a="893539240" Received: from jithujos.sc.intel.com ([172.25.103.66]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2023 13:27:29 -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: Fri, 29 Sep 2023 13:24:32 -0700 Message-Id: <20230929202436.2850388-6-jithu.joseph@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230929202436.2850388-1-jithu.joseph@intel.com> References: <20230922232606.1928026-1-jithu.joseph@intel.com> <20230929202436.2850388-1-jithu.joseph@intel.com> MIME-Version: 1.0 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,SPF_HELO_NONE,SPF_NONE 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 (howler.vger.email [0.0.0.0]); Fri, 29 Sep 2023 13:45:58 -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 Tested-by: Pengfei Xu --- 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..da54fd060878 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 %d, actual %ld). 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