From: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
markgross@kernel.org, Sanket.Goswami@amd.com,
mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH v7 1/3] platform/x86/amd/pmc: Use flex array when calling amd_pmc_stb_debugfs_open_v2()
Date: Mon, 9 Oct 2023 21:36:55 +0530 [thread overview]
Message-ID: <cc3369d1-0953-4cd3-8218-8e77637cbef0@amd.com> (raw)
In-Reply-To: <8bb675d-8bbf-c6cb-cec1-f53910ac673e@linux.intel.com>
On 10/9/2023 8:42 PM, Ilpo Järvinen wrote:
> On Mon, 9 Oct 2023, Shyam Sundar S K wrote:
>
>> Currently in amd_pmc_stb_debugfs_open_v2() the buffer size is assumed to
>> be fixed and a second call to amd_pmc_stb_debugfs_open_v2() may race with
>> a process holding open another fd. This could change "fsize" to a
>> bigger size causing an out of bounds read.
>>
>> Instead create a struct with a flexarray to solve this.
>>
>> Suggested-by: Hans de Goede <hdegoede@redhat.com>
>> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
>> Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
>> Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
>> ---
>> v6->v7:
>> - No change
>>
>> v6:
>> - Handle release buffer case as per Hans remarks
>> - based on review-ilpo branch
>>
>> v5:
>> - new patch based on comments in v4 from Hans.
>> - based on review-ilpo branch
>>
>> drivers/platform/x86/amd/pmc/pmc.c | 30 ++++++++++++++++++------------
>> 1 file changed, 18 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/platform/x86/amd/pmc/pmc.c b/drivers/platform/x86/amd/pmc/pmc.c
>> index c92dd5077a16..fdc1e104c437 100644
>> --- a/drivers/platform/x86/amd/pmc/pmc.c
>> +++ b/drivers/platform/x86/amd/pmc/pmc.c
>> @@ -122,6 +122,11 @@ enum s2d_arg {
>> S2D_DRAM_SIZE,
>> };
>>
>> +struct amd_pmc_stb_v2_data {
>> + size_t size;
>> + u8 data[] __counted_by(size);
>> +};
>> +
>> struct amd_pmc_bit_map {
>> const char *name;
>> u32 bit_mask;
>> @@ -239,7 +244,8 @@ static const struct file_operations amd_pmc_stb_debugfs_fops = {
>> static int amd_pmc_stb_debugfs_open_v2(struct inode *inode, struct file *filp)
>> {
>> struct amd_pmc_dev *dev = filp->f_inode->i_private;
>> - u32 *buf, fsize, num_samples, val, stb_rdptr_offset = 0;
>> + u32 fsize, num_samples, val, stb_rdptr_offset = 0;
>> + struct amd_pmc_stb_v2_data *flex_arr;
>> int ret;
>>
>> /* Write dummy postcode while reading the STB buffer */
>> @@ -247,10 +253,6 @@ static int amd_pmc_stb_debugfs_open_v2(struct inode *inode, struct file *filp)
>> if (ret)
>> dev_err(dev->dev, "error writing to STB: %d\n", ret);
>>
>> - buf = kzalloc(S2D_TELEMETRY_BYTES_MAX, GFP_KERNEL);
>> - if (!buf)
>> - return -ENOMEM;
>> -
>> /* Spill to DRAM num_samples uses separate SMU message port */
>> dev->msg_port = 1;
>>
>> @@ -264,10 +266,16 @@ static int amd_pmc_stb_debugfs_open_v2(struct inode *inode, struct file *filp)
>> dev->msg_port = 0;
>> if (ret) {
>> dev_err(dev->dev, "error: S2D_NUM_SAMPLES not supported : %d\n", ret);
>> - kfree(buf);
>> return ret;
>> }
>>
>> + fsize = (num_samples > S2D_TELEMETRY_BYTES_MAX) ? S2D_TELEMETRY_BYTES_MAX : num_samples;
>
> min() but that will only work when you add U postfix to
> S2D_TELEMETRY_BYTES_MAX (I see no reason why it couldn't make it
> unsigned).
>
> Make sure to add the include for it too.
>
Sure, I will address this.
Thanks,
Shyam
prev parent reply other threads:[~2023-10-09 16:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 14:12 [PATCH v7 1/3] platform/x86/amd/pmc: Use flex array when calling amd_pmc_stb_debugfs_open_v2() Shyam Sundar S K
2023-10-09 14:12 ` [PATCH v7 2/3] platform/x86/amd/pmc: Handle overflow cases where the num_samples range is higher Shyam Sundar S K
2023-10-09 15:21 ` Ilpo Järvinen
2023-10-09 16:06 ` Shyam Sundar S K
2023-10-09 14:12 ` [PATCH v7 3/3] platform/x86/amd/pmc: Add dump_custom_stb module parameter Shyam Sundar S K
2023-10-09 15:06 ` Ilpo Järvinen
2023-10-09 15:10 ` Shyam Sundar S K
2023-10-09 15:13 ` Ilpo Järvinen
2023-10-09 15:12 ` [PATCH v7 1/3] platform/x86/amd/pmc: Use flex array when calling amd_pmc_stb_debugfs_open_v2() Ilpo Järvinen
2023-10-09 16:06 ` Shyam Sundar S K [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=cc3369d1-0953-4cd3-8218-8e77637cbef0@amd.com \
--to=shyam-sundar.s-k@amd.com \
--cc=Sanket.Goswami@amd.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=mario.limonciello@amd.com \
--cc=markgross@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