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 v3 3/4] platform/x86/amd/pmf: Use struct for cookie header
Date: Mon, 4 Mar 2024 21:50:04 +0100 [thread overview]
Message-ID: <20240304205005.10078-4-W_Armin@gmx.de> (raw)
In-Reply-To: <20240304205005.10078-1-W_Armin@gmx.de>
The cookie header consists of a sign field and a length field.
Combine both in a single struct to make accesses simpler.
Compile-tested only.
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/platform/x86/amd/pmf/pmf.h | 6 +++++-
drivers/platform/x86/amd/pmf/tee-if.c | 9 ++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
index bcf777a5659a..0c90805dc85b 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -17,7 +17,11 @@
#define POLICY_BUF_MAX_SZ 0x4b000
#define POLICY_SIGN_COOKIE 0x31535024
#define POLICY_COOKIE_OFFSET 0x10
-#define POLICY_COOKIE_LEN 0x14
+
+struct cookie_header {
+ u32 sign;
+ u32 length;
+} __packed;
/* APMF Functions */
#define APMF_FUNC_VERIFY_INTERFACE 0
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index 58ec2c9606e1..71ea7eefc211 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -246,17 +246,16 @@ static void amd_pmf_invoke_cmd(struct work_struct *work)
static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
{
- u32 cookie, length;
+ struct cookie_header *header;
int res;
- cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET);
- length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN);
+ header = (struct cookie_header *)(dev->policy_buf + POLICY_COOKIE_OFFSET);
- if (cookie != POLICY_SIGN_COOKIE || !length)
+ if (header->sign != POLICY_SIGN_COOKIE || !header->length)
return -EINVAL;
/* Update the actual length */
- dev->policy_sz = length + 512;
+ dev->policy_sz = header->length + 512;
res = amd_pmf_invoke_cmd_init(dev);
if (res == TA_PMF_TYPE_SUCCESS) {
/* Now its safe to announce that smart pc is enabled */
--
2.39.2
next prev parent reply other threads:[~2024-03-04 20:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 20:50 [PATCH v3 0/4] platform/x86/amd/pmf: Fix policy binary handling Armin Wolf
2024-03-04 20:50 ` [PATCH v3 1/4] platform/x86/amd/pmf: Fix return value of amd_pmf_start_policy_engine() Armin Wolf
2024-03-04 20:50 ` [PATCH v3 2/4] platform/x86/amd/pmf: Do not use readl() for policy buffer access Armin Wolf
2024-03-04 20:50 ` Armin Wolf [this message]
2024-03-04 20:50 ` [PATCH v3 4/4] platform/x86/amd/pmf: Fix possible out-of-bound memory accesses Armin Wolf
2024-03-06 5:09 ` [PATCH v3 0/4] platform/x86/amd/pmf: Fix policy binary handling Shyam Sundar S K
2024-03-06 9:53 ` Ilpo Järvinen
2024-03-06 10:50 ` Ilpo Järvinen
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=20240304205005.10078-4-W_Armin@gmx.de \
--to=w_armin@gmx.de \
--cc=Shyam-sundar.S-k@amd.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--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 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®