Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp525586rdb; Thu, 5 Oct 2023 12:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4Q07j/ndfQlcfr75hKx/Wn8SAVhluJyRqIpzDj2pc/bWk3f+bv95uFZGPx8qa00IeIcD6 X-Received: by 2002:a17:90a:cd05:b0:274:9409:bbca with SMTP id d5-20020a17090acd0500b002749409bbcamr5634727pju.3.1696535800535; Thu, 05 Oct 2023 12:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696535800; cv=none; d=google.com; s=arc-20160816; b=tnynyRJDGtA+Iqd0oTYQqxQ2ab0PYVv0fUBEIzR5Dgrlj4ZHXSdBNOuNrpSCl2VUtO eLfApwkFuBsu2hGs58TFq8HUxnT9SGJN5X4sciNjsER9oamK25LgLzQ7ss+2L5HHO5+s oDG2RYG8yEzbymq1vippFCEp4rorKqDFl1D+j4LykC8iT1I6YojojDOMO1w9hA9mzUJ/ Bu7onzuNQpt68So0ETm9UnzxcmJwQ2lQ6lQsO0ieKF7PjsziV/JULJcjAQk57Q+BZHXW 1NDCnUwzHXrcZE0fe8kUp+LiVOfkL8+jCrhbjXX9djvqWAXsQ+/Fe8Q3nhYgcq3i5RTh TqjQ== 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=/gw1kIbJOpjPn0qjDCV4o2b17F/qYUJ8e4rF9s6IZe8=; fh=dyN8rlR8DIsO7hGArNuYLUXtXvDlE6dkZecyfb1jp0w=; b=uEGsMARjZvPDyuDqVNHMwo0YuKpSFF0TrgoNxA2tJ54DHsed0tBMkdc7gRjDidcL2f +MUMtMq4TpwrSaOSakjKctxsj2750dzh6MTmN1rrvF6gGSGNnU+dRVXAYt24G7BLbB33 b3TDItz0BxD5QQgCjmXmyHmZQwKOS8U07Y3CYUsJ9zDf4x8Z/0jhV9gQjf1AIV2ZsUQa i1I+CMrhyGi9nufZYA9gWCWfeS+MW4rO4lgXwof3efeFIy4rVCxE0imSZ3/SbdnFy1DR DXY5tZ252rCayWKOluzaWgXhM/ZNGyDvaqmuQ6dmlotjt3qlvmTRpImKVC2ZeHdbRS3H Vh9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aIKcgTcF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id a8-20020a17090a740800b0026d40e6a7d0si2193310pjg.56.2023.10.05.12.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 12:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aIKcgTcF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 9432882D1C1D; Thu, 5 Oct 2023 12:56:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231997AbjJET4C (ORCPT + 99 others); Thu, 5 Oct 2023 15:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231671AbjJETzs (ORCPT ); Thu, 5 Oct 2023 15:55:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28743DB; Thu, 5 Oct 2023 12:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696535747; x=1728071747; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GOHBkM4E1xt6ifRLwPO4brJgQO1Uu7WIe/PQmNjPNOU=; b=aIKcgTcF/3ctJ0qwKnY/ghJbdOJe9m2e4KUMHgZQ5EIAol5M8lYWdwks dbhCrkIdf1ra4b06le+0tA9BXk2gQ2v7mljluIXY5VhYh/m1BUCWP18ip F+ZqOumWBcgNS1Bg044ek1Ut6GiG3GRKUJbwo5FiWpE9bEc5Z79GQsWQf 1AktpU/Cuw128YRP4iHBBWm42MsBlXFQGXqPXE9PbPp2JFUEU+JisqEFx TFjA8xRBzSm6pQ83aVG8LJI5gNYuSFp/4R733uGiMmXBVLMs5oNXbYBHq +d9CY8WJ6KsqFhpc3rkMqwi98bJPGyaxTriRYjtHaJs37qFQ20w9vrf2G A==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="386432558" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="386432558" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:55:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="755600129" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="755600129" Received: from jithujos.sc.intel.com ([172.25.103.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 12:55:44 -0700 From: Jithu Joseph To: ilpo.jarvinen@linux.intel.com, 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 v4 5/9] platform/x86/intel/ifs: Validate image size Date: Thu, 5 Oct 2023 12:51:33 -0700 Message-Id: <20231005195137.3117166-6-jithu.joseph@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231005195137.3117166-1-jithu.joseph@intel.com> References: <20230929202436.2850388-1-jithu.joseph@intel.com> <20231005195137.3117166-1-jithu.joseph@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Thu, 05 Oct 2023 12:56:31 -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 --- 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