From: Reinette Chatre <reinette.chatre@intel.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com,
peternewman@google.com, babu.moger@amd.com,
"Maciej Wieczór-Retman" <maciej.wieczor-retman@intel.com>,
linux-kselftest@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V2 04/13] selftests/resctrl: Protect against array overrun during iMC config parsing
Date: Mon, 30 Sep 2024 09:04:06 -0700 [thread overview]
Message-ID: <cbfc027c-264d-47f4-949a-3216cd79bf0b@intel.com> (raw)
In-Reply-To: <93b9f530-1d2d-dc19-1d48-c15aced32804@linux.intel.com>
Hi Ilpo,
On 9/30/24 6:35 AM, Ilpo Järvinen wrote:
> On Thu, 12 Sep 2024, Reinette Chatre wrote:
>
>> The MBM and MBA tests need to discover the event and umask with which to
>> configure the performance event used to measure read memory bandwidth.
>> This is done by parsing the
>> /sys/bus/event_source/devices/uncore_imc_<imc instance>/events/cas_count_read
>> file for each iMC instance that contains the formatted
>> output: "event=<event>,umask=<umask>"
>>
>> Parsing of cas_count_read contents is done by initializing an array of
>> MAX_TOKENS elements with tokens (deliminated by "=,") from this file.
>> Start by removing the unnecessary append of a delimiter to the string
>
> Start what? (It sounds odd given the lack of any context, my guess is
> you're trying to refer to start/first one of the changes you make in the
> patch but the textual context does not support that conclusion.) I suggest
> you just rephrase it and avoid using "start" word altogether.
Indeed, I'll just drop the "Start by" and have the sentence be:
"Remove the unnecessary append of a delimiter ..."
>
>> needing to be parsed. Per the strtok() man page: "delimiter bytes at
>> the start or end of the string are ignored". This has no impact on
>> the token placement within the array.
>>
>> After initialization, the actual event and umask is determined by
>> parsing the tokens directly following the "event" and "umask" tokens
>> respectively.
>>
>> Iterating through the array up to index "i < MAX_TOKENS" but then
>> accessing index "i + 1" risks array overrun during the final iteration.
>> Avoid array overrun by ensuring that the index used within for
>> loop will always be valid.
>>
>> Fixes: 1d3f08687d76 ("selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system")
>> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
>> ---
>> Changes since V1:
>> - New patch.
>> ---
>> tools/testing/selftests/resctrl/resctrl_val.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
>> index 70e8e31f5d1a..e88d5ca30517 100644
>> --- a/tools/testing/selftests/resctrl/resctrl_val.c
>> +++ b/tools/testing/selftests/resctrl/resctrl_val.c
>> @@ -83,13 +83,12 @@ static void get_event_and_umask(char *cas_count_cfg, int count, bool op)
>> char *token[MAX_TOKENS];
>> int i = 0;
>>
>> - strcat(cas_count_cfg, ",");
>> token[0] = strtok(cas_count_cfg, "=,");
>>
>> for (i = 1; i < MAX_TOKENS; i++)
>> token[i] = strtok(NULL, "=,");
>>
>> - for (i = 0; i < MAX_TOKENS; i++) {
>> + for (i = 0; i < MAX_TOKENS - 1; i++) {
>> if (!token[i])
>> break;
>> if (strcmp(token[i], "event") == 0) {
>>
>
> The code change seems fine so after improving the commit message, please
> add:
>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>
Thank you very much.
Reinette
next prev parent reply other threads:[~2024-09-30 16:04 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 18:13 [PATCH V2 00/13] selftests/resctrl: Support diverse platforms with MBM and MBA tests Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 01/13] selftests/resctrl: Make functions only used in same file static Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 02/13] selftests/resctrl: Print accurate buffer size as part of MBM results Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 03/13] selftests/resctrl: Fix memory overflow due to unhandled wraparound Reinette Chatre
2024-09-30 13:16 ` Ilpo Järvinen
2024-09-12 18:13 ` [PATCH V2 04/13] selftests/resctrl: Protect against array overrun during iMC config parsing Reinette Chatre
2024-09-30 13:35 ` Ilpo Järvinen
2024-09-30 16:04 ` Reinette Chatre [this message]
2024-09-12 18:13 ` [PATCH V2 05/13] selftests/resctrl: Make wraparound handling obvious Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 06/13] selftests/resctrl: Remove "once" parameter required to be false Reinette Chatre
2024-09-30 13:49 ` Ilpo Järvinen
2024-09-30 16:07 ` Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 07/13] selftests/resctrl: Only support measured read operation Reinette Chatre
2024-09-30 13:52 ` Ilpo Järvinen
2024-09-30 16:05 ` Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 08/13] selftests/resctrl: Remove unused measurement code Reinette Chatre
2024-09-30 13:59 ` Ilpo Järvinen
2024-09-12 18:13 ` [PATCH V2 09/13] selftests/resctrl: Make benchmark parameter passing robust Reinette Chatre
2024-10-04 14:05 ` Ilpo Järvinen
2024-10-04 22:21 ` Reinette Chatre
2024-09-12 18:13 ` [PATCH V2 10/13] selftests/resctrl: Ensure measurements skip initialization of default benchmark Reinette Chatre
2024-10-04 14:11 ` Ilpo Järvinen
2024-09-12 18:14 ` [PATCH V2 11/13] selftests/resctrl: Use cache size to determine "fill_buf" buffer size Reinette Chatre
2024-10-04 14:20 ` Ilpo Järvinen
2024-10-04 22:23 ` Reinette Chatre
2024-09-12 18:14 ` [PATCH V2 12/13] selftests/resctrl: Do not compare performance counters and resctrl at low bandwidth Reinette Chatre
2024-10-04 14:23 ` Ilpo Järvinen
2024-09-12 18:14 ` [PATCH V2 13/13] selftests/resctrl: Keep results from first test run Reinette Chatre
2024-10-04 14:29 ` Ilpo Järvinen
2024-10-04 22:24 ` Reinette Chatre
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=cbfc027c-264d-47f4-949a-3216cd79bf0b@intel.com \
--to=reinette.chatre@intel.com \
--cc=babu.moger@amd.com \
--cc=fenghua.yu@intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=peternewman@google.com \
--cc=shuah@kernel.org \
--cc=tony.luck@intel.com \
/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