All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Cc: Hans de Goede <hansg@kernel.org>,
	platform-driver-x86@vger.kernel.org,  Patil.Reddy@amd.com,
	mario.limonciello@amd.com
Subject: Re: [PATCH 4/8] platform/x86/amd/pmf: Get policy binary signature size from PSP header
Date: Wed, 21 Oct 2026 15:00:25 +0300 (EEST)	[thread overview]
Message-ID: <d376fc11-21f4-7965-d763-49834863e3d8@linux.intel.com> (raw)
In-Reply-To: <20261011100554.1841309-5-Shyam-sundar.S-k@amd.com>

On Sun, 11 Oct 2026, Shyam Sundar S K wrote:

> The policy binary size is calculated as the payload length plus a fixed
> 512 bytes, which assumes a 256 byte PSP header and a 256 byte RSA2K
> signature. Newer policy binaries can be signed with RSA4K, which has a
> 512 byte signature.
> 
> Read the signature algorithm from the PSP header and use it to get the
> signature size. Check that the buffer is large enough before reading
> the header field, and that the size calculation does not overflow.
> 
> Policy binaries with an unknown signature algorithm are now rejected.
> 
> Co-developed-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
> Signed-off-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
> Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
> ---
>  drivers/platform/x86/amd/pmf/pmf.h    |  8 +++++++
>  drivers/platform/x86/amd/pmf/tee-if.c | 34 +++++++++++++++++++++++++--
>  2 files changed, 40 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
> index d9fa99c2750f..86999802602c 100644
> --- a/drivers/platform/x86/amd/pmf/pmf.h
> +++ b/drivers/platform/x86/amd/pmf/pmf.h
> @@ -29,6 +29,14 @@
>  #define POLICY_SIGN_COOKIE		0x31535024
>  #define POLICY_COOKIE_OFFSET		0x10
>  
> +/* Policy binary PSP header */
> +#define POLICY_PSP_HEADER_SIZE		256
> +#define POLICY_PSP_SIG_ALG_OFFSET	0x34
> +#define POLICY_PSP_SIG_ALG_RSA2K	0
> +#define POLICY_PSP_SIG_ALG_RSA4K	2
> +#define POLICY_PSP_SIG_SIZE_RSA2K	256
> +#define POLICY_PSP_SIG_SIZE_RSA4K	512

SZ_* x3

-- 
 i.

> +
>  /* List of supported CPU ids */
>  #define AMD_CPU_ID_RMB                  0x14b5
>  #define AMD_CPU_ID_PS                   0x14e8
> diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
> index e145eb7b03cd..9b328be1e8f4 100644
> --- a/drivers/platform/x86/amd/pmf/tee-if.c
> +++ b/drivers/platform/x86/amd/pmf/tee-if.c
> @@ -11,7 +11,9 @@
>  #include <linux/array_size.h>
>  #include <linux/debugfs.h>
>  #include <linux/dev_printk.h>
> +#include <linux/overflow.h>
>  #include <linux/tee_drv.h>
> +#include <linux/unaligned.h>
>  #include <linux/uuid.h>
>  #include "pmf.h"
>  
> @@ -327,9 +329,32 @@ static void amd_pmf_invoke_cmd(struct work_struct *work)
>  	schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms));
>  }
>  
> +static int amd_pmf_get_pb_sig_size(struct amd_pmf_dev *dev, u32 *sig_size)
> +{
> +	u32 sig_alg;
> +
> +	if (dev->policy_sz < POLICY_PSP_SIG_ALG_OFFSET + sizeof(sig_alg))
> +		return -EINVAL;
> +
> +	sig_alg = get_unaligned_le32(dev->policy_buf + POLICY_PSP_SIG_ALG_OFFSET);
> +
> +	switch (sig_alg) {
> +	case POLICY_PSP_SIG_ALG_RSA2K:
> +		*sig_size = POLICY_PSP_SIG_SIZE_RSA2K;
> +		return 0;
> +	case POLICY_PSP_SIG_ALG_RSA4K:
> +		*sig_size = POLICY_PSP_SIG_SIZE_RSA4K;
> +		return 0;
> +	default:
> +		dev_dbg(dev->dev, "Unknown PSP signature algorithm: %u\n", sig_alg);
> +		return -EINVAL;
> +	}
> +}
> +
>  int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
>  {
>  	struct cookie_header *header;
> +	u32 sig_size, total_sz;
>  	int res;
>  
>  	if (dev->policy_sz < POLICY_COOKIE_OFFSET + sizeof(*header))
> @@ -342,11 +367,16 @@ int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
>  		return -EINVAL;
>  	}
>  
> -	if (dev->policy_sz < header->length + 512)
> +	res = amd_pmf_get_pb_sig_size(dev, &sig_size);
> +	if (res)
> +		return res;
> +
> +	if (check_add_overflow(header->length, POLICY_PSP_HEADER_SIZE + sig_size, &total_sz) ||
> +	    dev->policy_sz < total_sz)
>  		return -EINVAL;
>  
>  	/* Update the actual length */
> -	dev->policy_sz = header->length + 512;
> +	dev->policy_sz = total_sz;
>  	res = dev->ta_ops->invoke_init(dev);
>  	if (res == TA_PMF_TYPE_SUCCESS) {
>  		/* Now its safe to announce that smart pc is enabled */
> 


  reply	other threads:[~2026-10-21 12:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 10:05 [PATCH 0/8] platform/x86/amd/pmf: Add 1AH_M80H support Shyam Sundar S K
2026-10-11 10:05 ` [PATCH 1/8] platform/x86/amd/pmf: Skip legacy DRAM address commands on 1AH_M80H Shyam Sundar S K
2026-10-11 10:05 ` [PATCH 2/8] platform/x86/amd/pmf: Add 1AH_M80H static slider support Shyam Sundar S K
2026-10-21 11:58   ` Ilpo Järvinen
2026-10-11 10:05 ` [PATCH 3/8] platform/x86/amd/pmf: Abstract TA dispatch through ta_ops table Shyam Sundar S K
2026-10-11 10:05 ` [PATCH 4/8] platform/x86/amd/pmf: Get policy binary signature size from PSP header Shyam Sundar S K
2026-10-21 12:00   ` Ilpo Järvinen [this message]
2026-10-11 10:05 ` [PATCH 5/8] platform/x86/amd/pmf: Add Smart PC builder support for 1AH_M80H Shyam Sundar S K
2026-10-21 12:09   ` Ilpo Järvinen
2026-10-11 10:05 ` [PATCH 6/8] platform/x86/amd/pmf: Remap metrics table on resume " Shyam Sundar S K
2026-10-11 10:05 ` [PATCH 7/8] platform/x86/amd/pmf: Add custom BIOS input support " Shyam Sundar S K
2026-10-11 10:05 ` [PATCH 8/8] platform/x86/amd/pmf: Share TA policy apply code between TA versions Shyam Sundar S K
2026-10-12 16:36 ` [PATCH 0/8] platform/x86/amd/pmf: Add 1AH_M80H support Mario Limonciello

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d376fc11-21f4-7965-d763-49834863e3d8@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=Patil.Reddy@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=hansg@kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.