X86 platform drivers
 help / color / mirror / Atom feed
From: Mario Limonciello <superm1@kernel.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: mario.limonciello@amd.com, Shyam-sundar.S-k@amd.com,
	Hans de Goede <hdegoede@redhat.com>,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH 2/2] drivers/platform/x86/amd: pmf: Handle bad policies in amd_pmf_get_pb_data()
Date: Wed, 23 Apr 2025 07:43:11 -0500	[thread overview]
Message-ID: <8793ece5-46a5-41c3-a87d-c08896cf2605@kernel.org> (raw)
In-Reply-To: <169663ff-6038-baf5-c872-2d485cf02ab5@linux.intel.com>



On 4/23/25 07:19, Ilpo Järvinen wrote:
> On Wed, 23 Apr 2025, Mario Limonciello wrote:
> 
>> From: Mario Limonciello <mario.limonciello@amd.com>
>>
>> If a policy is passed into amd_pmf_get_pb_data() that causes the engine
>> to fail to start there is a memory leak. Check for invalid policies as
>> well as an error in amd_pmf_start_policy_engine() and free the memory in
>> the failure path.
>>
>> Fixes: 10817f28e5337 ("platform/x86/amd/pmf: Add capability to sideload of policy binary")
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>>   drivers/platform/x86/amd/pmf/tee-if.c | 13 ++++++++++++-
>>   1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
>> index 41ab9eca5ff13..3c399dc1bfcca 100644
>> --- a/drivers/platform/x86/amd/pmf/tee-if.c
>> +++ b/drivers/platform/x86/amd/pmf/tee-if.c
>> @@ -377,12 +377,23 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf,
>>   	dev->policy_buf = new_policy_buf;
>>   	dev->policy_sz = length;
>>   
>> +	/* Check if the policy binary is valid */
>> +	if (!memchr_inv(dev->policy_buf, 0xff, dev->policy_sz)) {
> 
> Since you're adding an explaning comment into two places, it very much
> looks you want a reasonably named helper instead for this so there's no
> need for such comments.

OK; I was initially hesitant since it was a single call to memchr_inv() 
but I'll switch it to an inline helper instead.

> 
>> +		ret = -EINVAL;
>> +		goto cleanup;
>> +	}
>> +
>>   	amd_pmf_hex_dump_pb(dev);
>>   	ret = amd_pmf_start_policy_engine(dev);
>>   	if (ret < 0)
>> -		return ret;
>> +		goto cleanup;
> 
> Isn't this an independent fix that should be in its own patch?

Ack; will split into it's own patch.

> 
>>   
>>   	return length;
>> +
>> +cleanup:
>> +	kfree(dev->policy_buf);
>> +	dev->policy_buf = NULL;
>> +	return ret;
>>   }
>>   
>>   static const struct file_operations pb_fops = {
>>
> 


      reply	other threads:[~2025-04-23 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 12:10 [PATCH 0/2] Handle bad policies for AMD-PMF better Mario Limonciello
2025-04-23 12:10 ` [PATCH 1/2] drivers/platform/x86/amd: pmf: Check for invalid Smart PC Policies Mario Limonciello
2025-04-23 12:10 ` [PATCH 2/2] drivers/platform/x86/amd: pmf: Handle bad policies in amd_pmf_get_pb_data() Mario Limonciello
2025-04-23 12:19   ` Ilpo Järvinen
2025-04-23 12:43     ` Mario Limonciello [this message]

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=8793ece5-46a5-41c3-a87d-c08896cf2605@kernel.org \
    --to=superm1@kernel.org \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox