Message ID | 20240227145500.299683-2-W_Armin@gmx.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-83436-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2747062dyb; Tue, 27 Feb 2024 06:55:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXME04G7szDmJvIbadlqocEMXiMjtNZMeTnacka6DAN4sDgvjY7HJdvnlntKz7BANgJjCPAYv8mJQTohL6iRIaDP15MPQ== X-Google-Smtp-Source: AGHT+IGHHj69eoEQKmodvjwYUERvJjM77EVC25NcqnZsv5M+Xq3R7IsgEyj5jnsHwKsI3jtVSTND X-Received: by 2002:a05:6214:3d88:b0:68f:e858:a1e1 with SMTP id om8-20020a0562143d8800b0068fe858a1e1mr4320230qvb.25.1709045754804; Tue, 27 Feb 2024 06:55:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709045754; cv=pass; d=google.com; s=arc-20160816; b=sHkw3svzUQQVletdLrqj9zRqirXmGPQPNBzHSHiJd9sXOsRk5Omc0eNOZGRp5CSn9W IW+ZQsP19P1XGsiOSVVzdC/FGSOl79wJ9Ui3pA1zFcGDdHlKqOn7Vz7jvokFgdz6LwUs nw2P8Tvfl7BWJsItvdMkmjbFQ142XNeuOdr3cOCRg5iyzlhOxKRw7JmXqAiZGvDdRr2S etM0xwDtOF1h/SD8KPr5PoZPtIW/3ogudZvSPAxM8w5Wqg33U9unBYEsIYkXXyNXjt5g mWw557HNgqu7wM5zSf8rpzLJCoZ1/N+L08lXy6pB7G9NpblLCvAKkg92dgsVqCu1JWHl lDuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=6jUL+5ZGtLoopOVO/3uujcO6Ldk69hQdRsWCVfk7qV4=; fh=Iw0cdpf9yN87ufu137c7ThcNR/cLOoX+JIMwqQQfbho=; b=PCBLZxl0YN9liL2szDHlJ7K60Nqm75UQqnkYvzdTxSfOdttsxPWMyvyxm5n198nb3G smdeJDIQF5b1i+gBPwJozZ06+MVTgjAM1yQJiuPmPjtjkCly69SMPdiSRif/6NJIa4oO +u49BCjNuZd87vrbglcEQ99YO/kXHHeBY9ziriydfzSX+35wvK/IDleb8CEeJg+QD/4I YMa4xx0DGODuykRiPkkVByAL4Hx4f1U2/r2JukZEGyIkQW6gjRE5//im/TmIsr6wthnX 66cUYA10whwAMZo2FtrpRdvA/m8u+bikDZHVIU5jHAgnHv9FtCEKQeyyQ411Vkv3q9ho pHYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=iV49nW+P; arc=pass (i=1 spf=pass spfdomain=gmx.de dkim=pass dkdomain=gmx.de dmarc=pass fromdomain=gmx.de); spf=pass (google.com: domain of linux-kernel+bounces-83436-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83436-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gi1-20020a056214248100b0069019d45e93si2616719qvb.195.2024.02.27.06.55.54 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 06:55:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83436-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=iV49nW+P; arc=pass (i=1 spf=pass spfdomain=gmx.de dkim=pass dkdomain=gmx.de dmarc=pass fromdomain=gmx.de); spf=pass (google.com: domain of linux-kernel+bounces-83436-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83436-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7F62E1C22CAE for <ouuuleilei@gmail.com>; Tue, 27 Feb 2024 14:55:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E11421420A0; Tue, 27 Feb 2024 14:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="iV49nW+P" Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (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 B3CCC13B289; Tue, 27 Feb 2024 14:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709045726; cv=none; b=iBcXdBR7IfXluP2palF86MLFvjcx3jvdRJMA9ODf1DiVOCgfVN1srcksBkl8DzMzX5iYhgyvYlKQIh/KEt1nhT7qxNFnD02QGVYq55jRnV8wudCIr0jTEXR/BGMqKAb0IarbyoRyynTf9yRePuDOCDjZv4vSq2qGz1tqmSTTleY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709045726; c=relaxed/simple; bh=fBLBJnTXEesUlwnv6flfi7CtneDxF1nsqo3zSFZ/SCs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D67rGPOroS/7VtcRpTOZOsu1sz7RtHtzSrVlS+IKuWTnu5ferB9KWQ6PIcqLQAzB+YwJHt5VPdphy4vaNk2M55Irug7xC6XwFm7tuVoi4LWO3UoqI2xB/ck88v1ro7617tXsjAeBM10R3yAbTruRzIHhAfUsqANaz9T1uEmOUso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=iV49nW+P; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709045708; x=1709650508; i=w_armin@gmx.de; bh=fBLBJnTXEesUlwnv6flfi7CtneDxF1nsqo3zSFZ/SCs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=iV49nW+PM1NvK+0/Fb5KnrvKctrOzz088gPi78nErBhSlex1JBHymmG9e4ITqitD Gj5N7wEWXWhkYHqHqWj3+oGRDRWtZ2p42J2McAosJkiVb9MhRVT1a5MOYW2Y+7iUk cHm5NzdebPpsrUoW+q7NjgB+VpLy86J/itI8PQsHLdEeSb29XWn6MDBG+LNhRG6TQ SgpRx3wun2SYkmYuWGItwtt+Hlpdjf3DeCPpaqBMxQpHeCxPR+uDA6RorCR4Hy9bw X2I/sb7fOOn4JAAwwWT1xrjmgQkq3qppUWjsIbJI2gWsG8fOck7viHc17uiDwe+sj repCWkx/NSeLGcYWuA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mulm5-1qoFTz26Vv-00rqYP; Tue, 27 Feb 2024 15:55:08 +0100 From: Armin Wolf <W_Armin@gmx.de> To: Shyam-sundar.S-k@amd.com Cc: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] platform/x86/amd/pmf: Fix possible out-of-bound memory accesses Date: Tue, 27 Feb 2024 15:55:00 +0100 Message-Id: <20240227145500.299683-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240227145500.299683-1-W_Armin@gmx.de> References: <20240227145500.299683-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:mwB/4+OQxc3beQYvIPV5xzGZIUOShegwwrNBgf2oo3MXenhZKFn bLP7TMzPgdsBYdgMbfx/KV+sy/zk32uwTlQjBeZRJIXYhi5A1ym5YXoBbmabvZb5R+iEMhH ZpB5nX7NBegF/ok7HNjUd5y5eU8tywxrGPW4gq0k33+ZHTV6bZ6RbHdjHzlj3vgo8gWIi6s d9Y/faRB1BIVmDPrv2Zsw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:zQEp+AMOBAE=;RccVHBJEzxHJeOPYwc5sLut92VT 4zv4X4Yy9b7mGc4eOoSAwV0vzU+2vlT17wh42WWplCbusylS/AoMQI4gFPMm9r1tlFKpMH4cj KoliPSYlRfOzK09yDNcr4BVYgNGAJitXG0jJVNLED5OoWyLBCv8US2bC+QEagXQEGuD2uHJXD kEYT2FhIxs/YT0XQ1GG3dwalo7xqbSeEag27UGKYPpSJdnVbyktyloz3VDfVDHZlRRL19/Lzk KmrNYiBua4wfQ7NvLYI35MG8Y0AkKxmK0b/aQj258qvq1dzub9DYwNCQODXn0ekUhntJy6FXl SII3l6uVYuW042qxHFQ3vBjjlyhCnD46Ch/amn+UBvP1BQF0fNhUH0D27jCBfVTOi02ry/0Oy m/wJiw5ZFo6ju6q1ER7YrygVrWhLsZeCzqpc3OUYNV9qjSyOM/ferF598b5UpteIg8L8zOe71 XmMlADWNMo2x96JmPRAiVl7sTwbCSm0vjzjSRE166YO+cgwhQN4a7wwO8oceBmS4bGUzLY7ZF XZS8nyZJ3uShNWldDXzCBJYvJNEUCINCENB0bjx0GI/XLAS4B1OuqUkgbhvk8ev18EULiUyp4 zEUKdEntPWmYJqsnXb8uNFX8Juamh3KKhQ3/5Dqd1BHkQfBe6LpY147A0n+xZaX0kEcDo6a08 V1fYHsNUHZwpO623W0TIZMzU127Ur3DcMgGevEQTm23N0WhNloakK7MMnbn6AaeZQDdpRgxP0 jXEU6rOLuQHSQL8HXXpyislqhz3PtZkmRi8+bjg9hb/TSLQwhOkA9v0vNu5eDJDZ3mjKdyFS3 n7xWznp81IBYR5mP9/gCMWqg/Rw+VxprF0Z6IfKFaOCnM= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792064361253154922 X-GMAIL-MSGID: 1792064361253154922 |
Series |
[v2,1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access
|
|
Commit Message
Armin Wolf
Feb. 27, 2024, 2:55 p.m. UTC
The length of the policy buffer is not validated before accessing it,
which means that multiple out-of-bounds memory accesses can occur.
This is especially bad since userspace can load policy binaries over
debugfs.
Compile-tested only.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
Changes since v1:
- check if the policy buffer also has enough room for storing the length
---
drivers/platform/x86/amd/pmf/tee-if.c | 6 ++++++
1 file changed, 6 insertions(+)
--
2.39.2
Comments
Hi Shyam & Armin, Shyam, please take a look at the question below. On Tue, 27 Feb 2024, Armin Wolf wrote: > The length of the policy buffer is not validated before accessing it, > which means that multiple out-of-bounds memory accesses can occur. > > This is especially bad since userspace can load policy binaries over > debugfs. > + if (dev->policy_sz < POLICY_COOKIE_LEN + sizeof(length)) > + return -EINVAL; > + > cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET); > length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN); This starts to feel like adding a struct for the header(?) would be better course of action here as then one could compare against sizeof(*header) and avoid all those casts (IMO, just access the header fields directly w/o the local variables). Shyam, do you think a struct makes sense here? There's some header in this policy, right? There are more thing to address here... 1) amd_pmf_start_policy_engine() function returns -EINVAL & res that is TA_PMF_* which inconsistent in type of the return value 2) Once 1) is fixed, the caller shadowing the return code can be fixed as well: ret = amd_pmf_start_policy_engine(dev); if (ret) return -EINVAL;
Hi Ilpo, On 2/27/2024 21:15, Ilpo Järvinen wrote: > Hi Shyam & Armin, > > Shyam, please take a look at the question below. > > On Tue, 27 Feb 2024, Armin Wolf wrote: > >> The length of the policy buffer is not validated before accessing it, >> which means that multiple out-of-bounds memory accesses can occur. >> >> This is especially bad since userspace can load policy binaries over >> debugfs. > IMO, this patch is not required, reason being: - the debugfs patch gets created only when CONFIG_AMD_PMF_DEBUG is enabled. - Sideload of policy binaries is only supported with a valid signing key. (think like this can be tested & verified within AMD environment) - Also, in amd_pmf_get_pb_data() there are boundary conditions that are being checked. Is that not sufficient enough? >> + if (dev->policy_sz < POLICY_COOKIE_LEN + sizeof(length)) >> + return -EINVAL; >> + >> cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET); >> length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN); > > This starts to feel like adding a struct for the header(?) would be better > course of action here as then one could compare against sizeof(*header) > and avoid all those casts (IMO, just access the header fields directly > w/o the local variables). Not sure if I get your question clearly. Can you elaborate a bit more on the struct you are envisioning? but IHMO, we actually don't need a struct - as all that we would need is to make sure the signing cookie is part of the policy binary and leave the rest of the error handling to ASP/TEE modules (we can rely on the feedback from those modules). > > Shyam, do you think a struct makes sense here? There's some header in > this policy, right? Yes, the policy binary on a whole has multiple sections within it and there are multiple headers (like signing, OEM header, etc). But that might be not real interest to the PMF driver. The only thing the driver has to make sure is that the policy binary going into ASP (AMD Secure Processor) is with in the limits and has a valid signing cookie. So this part is already taken care in the current code. > > > There are more thing to address here... > > 1) amd_pmf_start_policy_engine() function returns -EINVAL & res that is > TA_PMF_* which inconsistent in type of the return value > ah! it has mix of both int and u32 :-) Armin, would you like to amend this in your current series? or else I will submit a change for this in my next series. Thanks, Shyam > 2) Once 1) is fixed, the caller shadowing the return code can be fixed as > well: > ret = amd_pmf_start_policy_engine(dev); > if (ret) > return -EINVAL; > >
Am 28.02.24 um 12:16 schrieb Shyam Sundar S K: > Hi Ilpo, > > On 2/27/2024 21:15, Ilpo Järvinen wrote: >> Hi Shyam & Armin, >> >> Shyam, please take a look at the question below. >> >> On Tue, 27 Feb 2024, Armin Wolf wrote: >> >>> The length of the policy buffer is not validated before accessing it, >>> which means that multiple out-of-bounds memory accesses can occur. >>> >>> This is especially bad since userspace can load policy binaries over >>> debugfs. > IMO, this patch is not required, reason being: > - the debugfs patch gets created only when CONFIG_AMD_PMF_DEBUG is > enabled. > - Sideload of policy binaries is only supported with a valid signing > key. (think like this can be tested & verified within AMD environment) > - Also, in amd_pmf_get_pb_data() there are boundary conditions that > are being checked. Is that not sufficient enough? IMHO, amd_pmf_get_pb_data() only checks if the length of the binary is between 0 and the maximum buffer size. If for example the binary contains only 4 bytes, then there will be an out-of-bounds access when trying to read the cookie and length. Or if the length is bigger than the binary buffer, then the driver just updates the buffer length even if the buffer is too small. I think the driver should catch such cases and return an error. (Please note that we are talking about the binary buffer, not the internal structure of the remaining policy binary itself). >>> + if (dev->policy_sz < POLICY_COOKIE_LEN + sizeof(length)) >>> + return -EINVAL; >>> + >>> cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET); >>> length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN); >> This starts to feel like adding a struct for the header(?) would be better >> course of action here as then one could compare against sizeof(*header) >> and avoid all those casts (IMO, just access the header fields directly >> w/o the local variables). > Not sure if I get your question clearly. Can you elaborate a bit more > on the struct you are envisioning? I think he envisions something like this: struct __packed cookie_header { u32 magic; u32 length; }; > > but IHMO, we actually don't need a struct - as all that we would need > is to make sure the signing cookie is part of the policy binary and > leave the rest of the error handling to ASP/TEE modules (we can rely > on the feedback from those modules). > >> Shyam, do you think a struct makes sense here? There's some header in >> this policy, right? > Yes, the policy binary on a whole has multiple sections within it and > there are multiple headers (like signing, OEM header, etc). > > But that might be not real interest to the PMF driver. The only thing > the driver has to make sure is that the policy binary going into ASP > (AMD Secure Processor) is with in the limits and has a valid signing > cookie. So this part is already taken care in the current code. > >> >> There are more thing to address here... >> >> 1) amd_pmf_start_policy_engine() function returns -EINVAL & res that is >> TA_PMF_* which inconsistent in type of the return value >> > ah! it has mix of both int and u32 :-) > > Armin, would you like to amend this in your current series? or else I > will submit a change for this in my next series. > > Thanks, > Shyam I can do so, but i will be unable to send a new patch series for the rest of this week. Thanks, Armin Wolf >> 2) Once 1) is fixed, the caller shadowing the return code can be fixed as >> well: >> ret = amd_pmf_start_policy_engine(dev); >> if (ret) >> return -EINVAL; >> >>
On Wed, 28 Feb 2024, Armin Wolf wrote: > Am 28.02.24 um 12:16 schrieb Shyam Sundar S K: > > On 2/27/2024 21:15, Ilpo Järvinen wrote: > > > On Tue, 27 Feb 2024, Armin Wolf wrote: > > > > > > > The length of the policy buffer is not validated before accessing it, > > > > which means that multiple out-of-bounds memory accesses can occur. > > > > > > > > This is especially bad since userspace can load policy binaries over > > > > debugfs. > > IMO, this patch is not required, reason being: > > - the debugfs patch gets created only when CONFIG_AMD_PMF_DEBUG is > > enabled. > > - Sideload of policy binaries is only supported with a valid signing > > key. (think like this can be tested & verified within AMD environment) > > - Also, in amd_pmf_get_pb_data() there are boundary conditions that > > are being checked. Is that not sufficient enough? > > IMHO, amd_pmf_get_pb_data() only checks if the length of the binary is > between 0 and the maximum buffer size. > > If for example the binary contains only 4 bytes, then there will be an > out-of-bounds access when trying to read the cookie and length. > > Or if the length is bigger than the binary buffer, then the driver just > updates the buffer length even if the buffer is too small. > > I think the driver should catch such cases and return an error. > > (Please note that we are talking about the binary buffer, not the internal > structure of the remaining policy binary itself). Yes. Out of bound accesses are not okay during validation even if the binary itself would get rejected at a later stage. It doesn't matter if the interface is only for debug or wider scope. > > > > + if (dev->policy_sz < POLICY_COOKIE_LEN + sizeof(length)) > > > > + return -EINVAL; > > > > + > > > > cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET); > > > > length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN); > > > This starts to feel like adding a struct for the header(?) would be better > > > course of action here as then one could compare against sizeof(*header) > > > and avoid all those casts (IMO, just access the header fields directly > > > w/o the local variables). > > Not sure if I get your question clearly. Can you elaborate a bit more > > on the struct you are envisioning? > > I think he envisions something like this: > > struct __packed cookie_header { > u32 magic; > u32 length; > }; > > > > > but IHMO, we actually don't need a struct - as all that we would need > > is to make sure the signing cookie is part of the policy binary and > > leave the rest of the error handling to ASP/TEE modules (we can rely > > on the feedback from those modules). > > > > > Shyam, do you think a struct makes sense here? There's some header in > > > this policy, right? > > Yes, the policy binary on a whole has multiple sections within it and > > there are multiple headers (like signing, OEM header, etc). > > > > But that might be not real interest to the PMF driver. The only thing > > the driver has to make sure is that the policy binary going into ASP > > (AMD Secure Processor) is with in the limits and has a valid signing > > cookie. So this part is already taken care in the current code. Clearly the PMF driver is interested in the header which contains the cookie and length fields as proven by the code (even if that's for the validation purposes only). I'm not asking about add various other headers which are of no interest. > > > There are more thing to address here... > > > > > > 1) amd_pmf_start_policy_engine() function returns -EINVAL & res that is > > > TA_PMF_* which inconsistent in type of the return value > > > > > ah! it has mix of both int and u32 :-) I was talking more on a logical level not so much about C type itself. It is confusing to return error in two ways: as -Exx values and TA_PMF_* which are positive. As a general rule (IMO), the HW specific errors should be mapped to -Exx codes at latest when a function returns also -Exx code which is the case here.
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index b3491268b6a0..09e3c620a9c7 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -249,12 +249,18 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev) u32 cookie, length; int res; + if (dev->policy_sz < POLICY_COOKIE_LEN + sizeof(length)) + return -EINVAL; + cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET); length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN); if (cookie != POLICY_SIGN_COOKIE || !length) return -EINVAL; + if (dev->policy_sz < length + 512) + return -EINVAL; + /* Update the actual length */ dev->policy_sz = length + 512; res = amd_pmf_invoke_cmd_init(dev);