Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp3057608rdb; Fri, 22 Sep 2023 17:30:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDHT9TId/GCj1FpK0bGuauIPwrp4LYqIDyH5m0jGEjnT/DT80SbTjRgdBUdcZqwziF5uQn X-Received: by 2002:a17:902:900c:b0:1c4:4c73:94e6 with SMTP id a12-20020a170902900c00b001c44c7394e6mr911359plp.51.1695429056515; Fri, 22 Sep 2023 17:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695429056; cv=none; d=google.com; s=arc-20160816; b=UjVwGW+bikfKoip2L5U1PKdPKXyiTXVi8tYiWzN8JNiX4nVEs9jrRkG794DvArhbtp SG71I7Z01RCnaBDpigjEKL9ahAucMs5urrWkUCxi8cQaVIvAIXU7Qe1scswNAm1PABFs Ot/ROkjrIqiYumhgVkGe5JScG3bsgCLL0QTyMqvi18r3ZZlsz+9BPyyblJ9ySQs3YYuf hvjsNCwiJUjwPHfA92eFJgqUOjCx8y8eC/4RAyES5QIsHKESV80wXW1ad5Ejj5yw2ZCH LQ1hJNY57SJbjQLrB9SxI1k5UsOz8BIX8DSd9mFZhBoG44zxKraiMtajcEa6tyx1j7NH 8D6Q== 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=dQm4cO+cCTM/T9K79LB9vupo0n4e0TgnULPJMWBlvek=; fh=DZTEBuCdFfe2DSdaI+6ceTR59ce872SNjmboNXW/0pA=; b=gXdjB7h4RPFv0eq2zDkZIjGISDPJ+7goXZ1g7id646y1oUKMAl7umXjXryI2f41oHa U1LXoiDe8eDnFupxF0p3sUtI1wdnC5t9hmd8+S/O/AO23suAQgU5h6JhHmfyz9ryleVs n0Toxl6EZoZNOyLLXU5UKKnKw8IP3Z/xjs6FNZMZnNp4PTEwfPavnFofIZ2zh+TV1UUZ H+UvmC2Fc5lxY8Y3Vg1NmbaQPeIGnCVwpOo4e/aFYBglW0iI5mcsFItaiOuDq41jZNzC PubRGOBwwRhbU4fq5T3Q2QjglRiexoWV1F+8iw/DEWzcDkeFnGRdggDmvEScQHqobfK7 uyew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="DU/BspkB"; 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 cp1-20020a170902e78100b001bbac6722e6si4578679plb.371.2023.09.22.17.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 17:30:56 -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="DU/BspkB"; 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 8255F84E5D54; Fri, 22 Sep 2023 16:30:35 -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 S230384AbjIVXa3 (ORCPT + 99 others); Fri, 22 Sep 2023 19:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbjIVXaU (ORCPT ); Fri, 22 Sep 2023 19:30:20 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8BE1A2; Fri, 22 Sep 2023 16:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695425415; x=1726961415; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z2xVMnQI58sLbdVcqjR8OcknAIUGjYdqpeDyu5+gypg=; b=DU/BspkBPdN3PnSLMZ0iHNNGQ5u7ulaq9w+fhsfXQYBzKLVkbDJetYJ7 KiaeOoZtp8ifuIaLj92Tn6KVxYx31WoKXU7cSs2PH5Ubgcjej6b8fbWm7 LxknOn3bwzLmkH7400XZRickzn+nv+QyjEwnFD2n8k2Bj4LopD6h7xeU3 2cQ/1kwqjTwtgm44oo4g40k85H70GF0Tavp8J7QJfDsS9tc+KqnFwhGLb xuZO3QULPFqvz7beTU08KMdjj8bLXVbzUnQ30UiKjAKIT1Kna68mEMZID zUSZggRfUia9Jf7qmi4+Y9myzPpBuXNm6G+9nvTbBvVmnDmPtgW9w18pa Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="411896954" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="411896954" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 16:30:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="921350840" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="921350840" Received: from jithujos.sc.intel.com ([172.25.103.66]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 16:30:12 -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 v2 5/9] platform/x86/intel/ifs: Validate image size Date: Fri, 22 Sep 2023 16:26:02 -0700 Message-Id: <20230922232606.1928026-6-jithu.joseph@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922232606.1928026-1-jithu.joseph@intel.com> References: <20230913183348.1349409-1-jithu.joseph@intel.com> <20230922232606.1928026-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,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 (howler.vger.email [0.0.0.0]); Fri, 22 Sep 2023 16:30:35 -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..b09106034fac 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 -EBADFD; + } + ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data); if (ret) goto release; -- 2.25.1