mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access
@ 2024-02-27 14:04 Armin Wolf
  2024-02-27 14:05 ` [PATCH 2/2] platform/x86/amd/pmf: Fix possible out-of-bound memory accesses Armin Wolf
  2024-02-27 14:09 ` [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access Ilpo Järvinen
  0 siblings, 2 replies; 3+ messages in thread
From: Armin Wolf @ 2024-02-27 14:04 UTC (permalink / raw)
  To: Shyam-sundar.S-k
  Cc: hdegoede, ilpo.jarvinen, platform-driver-x86, linux-kernel

The policy buffer is allocated using normal memory allocation
functions, so readl() should not be used on it.

Compile-tested only.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/amd/pmf/tee-if.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index 16973bebf55f..70d09103ab18 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -249,8 +249,8 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
 	u32 cookie, length;
 	int res;

-	cookie = readl(dev->policy_buf + POLICY_COOKIE_OFFSET);
-	length = readl(dev->policy_buf + POLICY_COOKIE_LEN);
+	cookie = dev->policy_buf[POLICY_COOKIE_OFFSET];
+	length = dev->policy_buf[POLICY_COOKIE_LEN];

 	if (cookie != POLICY_SIGN_COOKIE || !length)
 		return -EINVAL;
--
2.39.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] platform/x86/amd/pmf: Fix possible out-of-bound memory accesses
  2024-02-27 14:04 [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
@ 2024-02-27 14:05 ` Armin Wolf
  2024-02-27 14:09 ` [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Armin Wolf @ 2024-02-27 14:05 UTC (permalink / raw)
  To: Shyam-sundar.S-k
  Cc: hdegoede, ilpo.jarvinen, platform-driver-x86, linux-kernel

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>
---
 drivers/platform/x86/amd/pmf/tee-if.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index 70d09103ab18..f2f9204b3a11 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)
+		return -EINVAL;
+
 	cookie = dev->policy_buf[POLICY_COOKIE_OFFSET];
 	length = 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);
--
2.39.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access
  2024-02-27 14:04 [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
  2024-02-27 14:05 ` [PATCH 2/2] platform/x86/amd/pmf: Fix possible out-of-bound memory accesses Armin Wolf
@ 2024-02-27 14:09 ` Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2024-02-27 14:09 UTC (permalink / raw)
  To: Armin Wolf; +Cc: Shyam-sundar.S-k, Hans de Goede, platform-driver-x86, LKML

On Tue, 27 Feb 2024, Armin Wolf wrote:

> The policy buffer is allocated using normal memory allocation
> functions, so readl() should not be used on it.
> 
> Compile-tested only.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>  drivers/platform/x86/amd/pmf/tee-if.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
> index 16973bebf55f..70d09103ab18 100644
> --- a/drivers/platform/x86/amd/pmf/tee-if.c
> +++ b/drivers/platform/x86/amd/pmf/tee-if.c
> @@ -249,8 +249,8 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
>  	u32 cookie, length;
>  	int res;
> 
> -	cookie = readl(dev->policy_buf + POLICY_COOKIE_OFFSET);
> -	length = readl(dev->policy_buf + POLICY_COOKIE_LEN);
> +	cookie = dev->policy_buf[POLICY_COOKIE_OFFSET];
> +	length = dev->policy_buf[POLICY_COOKIE_LEN];

Hmm, the next question is, is it okay to get just 8 bits instead the full 
dword (the policy_buf is unsigned char *)?

-- 
 i.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-27 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 14:04 [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
2024-02-27 14:05 ` [PATCH 2/2] platform/x86/amd/pmf: Fix possible out-of-bound memory accesses Armin Wolf
2024-02-27 14:09 ` [PATCH 1/2] platform/x86/amd/pmf: Do not use readl() for policy buffer access Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®