Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3697022rdb; Wed, 13 Sep 2023 22:48:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgUW00dCvfJSrq96vmt8KelO/J+FFLTzd/BdGsyIvbE7oSZSjdXtwo02izkGbbzModiMZ/ X-Received: by 2002:a67:f74c:0:b0:44e:8ef9:336b with SMTP id w12-20020a67f74c000000b0044e8ef9336bmr4356721vso.15.1694670533664; Wed, 13 Sep 2023 22:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694670533; cv=none; d=google.com; s=arc-20160816; b=kOqP++cj6pAhP5Fji9I5Fj4HXKQs63UU/QHYV0o1gZEBDMXNp+PBlxVox/wJ9hLwvl ji75fpfpSreyYQfHboaQA3HVsYgAz+Bq4vSlL1KsUE+rbmLqfZCwyw2yAq9f5Jo184HP c4ZgfpIlfjLtxLSwzmroChzd7nwLHgn8Gqb/HnG6pUrrKznc/CklL2ZM3Abobz3nmTQL 70hxRlftSLEv764iRoMhkFNLnJir0U5zg+De78fUO2PyvH3Fcp7V5yaj7ZOi4yjZH9T/ 2EugsPd6xzXESIHES/cqfa0dqokcCyCQCvDCM+1veFsBPN4zUx/HRL/v+uAvFgNra5pR aRkQ== 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=NRMsg5ftdqMaSRAJN9gPrIpxylk/Xfx5TJFB1AqXEuE=; fh=8xS9zNNEexx7KHEczBpq5wXIDtxA/g5mXnxETx6X+p0=; b=xa7eYw6uygLhxlqsV/IPl2xUFJrv5kFtiQ0Jdz9FVm3pyAeYxpyZDCwkjRaMI1+nco K0o9BT3iVmXu4GV6dPk8vBlJMQOJ9Rj/8mIDVYFzXqDZpncwYLKOsO5JqSNOt8vfr+nB 8kF8hklqsbmjRAkHv2U2CR0jzEIAjkXLOmwH1DOnrMUaLKvJyWggixE7qVdTlfOq+zqH hxFvRmFnQSdUk0wCA4TMANP3DzG2JbN5D8GHXzlBXRLGWf4aVk+IRR4e6m3dEH9QUuIy Gly052Cpc0xDMhGquqHTb3A1SSalg3iJpuXSFOrDqm0GcWWV5TafbtbNgh2SmNgnBTIL s3qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KmkCiurj; 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 p186-20020a6342c3000000b005661e3f6b0dsi825903pga.329.2023.09.13.22.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 22:48:53 -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=KmkCiurj; 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 13DE0825E529; Wed, 13 Sep 2023 11:38:22 -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 S231982AbjIMSiQ (ORCPT + 99 others); Wed, 13 Sep 2023 14:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbjIMSiA (ORCPT ); Wed, 13 Sep 2023 14:38:00 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95C11BC6; Wed, 13 Sep 2023 11:37:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694630276; x=1726166276; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1QD1hfFNbY0dgb7El0Aw5L89YdqnDMRaACvnIzni/zs=; b=KmkCiurjD4OIJKYPCtR1x2bAZOtz1apLafTigQ6XdFkPtp3T0XfrOx/N 0cX645alEVU7+tytPxmwZOM1rh0IBUJNlAeZoYPxZ5insLq31iiMlu5T2 j6qL+8unc5Kqlti+IH7Kv0PgQKkB6xldueGN5YS/pRWR597H61WgT8+3V gSqdxCrCge8YE43qdeH3WgIJXof9mgEgFQwmCKgO/7b4R0juaJXm4DfI+ yANAoRumD4Qc4r3gn3Nv4K+m6l0JjxmT221j0SRnfNFG5I8HAhVQgT0Ha E17oB+vXiKRk2D22tiGm3vTsp0HKGnuytP291bGEgG0zTXyWHiTxHo2Uy g==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="369019171" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="369019171" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 11:37:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="744238590" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="744238590" Received: from jithujos.sc.intel.com ([172.25.103.66]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 11:37:55 -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 Subject: [PATCH 06/10] platform/x86/intel/ifs: Validate image size Date: Wed, 13 Sep 2023 11:33:44 -0700 Message-Id: <20230913183348.1349409-7-jithu.joseph@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230913183348.1349409-1-jithu.joseph@intel.com> References: <20230913183348.1349409-1-jithu.joseph@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, 13 Sep 2023 11:38:22 -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 e8fb03dd8bcf..778a3b89a24d 100644 --- a/drivers/platform/x86/intel/ifs/load.c +++ b/drivers/platform/x86/intel/ifs/load.c @@ -376,6 +376,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; @@ -390,6 +391,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 -EBADFD; + } + ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data); if (ret) goto release; -- 2.25.1