From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66D391D54A for ; Wed, 4 Oct 2023 19:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="X9TBpBvA" Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696446014; x=1727982014; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cwaZnSVcVuM6qrMky+ZTKlliEs+Pp1T+fUkqoVUBGYQ=; b=X9TBpBvAUH8TJ2IkbIihg+9YKehcVwvfsJzUsED5r0QIyOXGZ3/hY4G0 RTjf9WewgZxAqZGg16JqlHjx2vPI28ZgkyuN42cfbbr9rDTHYtgDq1nJX lUtR55SFCsKnuMFai8ue7bDu/KTDQ/9ch2EDLUXk/iZGKtR8nYdY+h/08 mKa+QTqU5S5KTaG5XZ7wCql36BWkMg3aBL3y1JxbpX2cZvysr7b8hTMi7 wvE4dsMOAg9I/tYiamxChFySFKo6wsYonNjbeGIMIfU21kv88FeyWdGWL u5WUmM9YWn4f4Xufkx1POdG56EIT0wUU8KXgJZSxpqn49IeKz5SocxoGc A==; X-IronPort-AV: E=McAfee;i="6600,9927,10853"; a="373610385" X-IronPort-AV: E=Sophos;i="6.03,201,1694761200"; d="scan'208";a="373610385" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.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: Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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