From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
Cc: peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@redhat.com,
namhyung@kernel.org, kan.liang@linux.intel.com,
zhe.he@windriver.com, dzickus@redhat.com, jstancek@redhat.com,
David Laight <David.Laight@aculab.com>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH V2] perf cpumap: Fix snprintf overflow check
Date: Tue, 24 Mar 2020 15:44:15 +0100 [thread overview]
Message-ID: <75a8e792-dc9e-6169-4dd2-8758967c50e2@wanadoo.fr> (raw)
In-Reply-To: <20200324125001.GA21569@kernel.org>
Le 24/03/2020 à 13:50, Arnaldo Carvalho de Melo a écrit :
> Em Tue, Mar 24, 2020 at 08:03:19AM +0100, Christophe JAILLET escreveu:
>> 'snprintf' returns the number of characters which would be generated for
>> the given input.
>>
>> If the returned value is *greater than* or equal to the buffer size, it
>> means that the output has been truncated.
>>
>> Fix the overflow test accordingling.
> y
>
> You forgot to CC David and add this to your patch, which I did:
>
> Suggested-by: David Laight <David.Laight@ACULAB.COM>
>
> Ok?
No problem for me.
The to: and cc: list are (at least should be :)) the ones given by
get_maintainer, and I was not aware of the 'Suggested-by' tag.
BTW, thanks for fixing the typo in the description.
CJ
> - Arnaldo
>
>> Fixes: 7780c25bae59f ("perf tools: Allow ability to map cpus to nodes easily")
>> Fixes: 92a7e1278005b ("perf cpumap: Add cpu__max_present_cpu()")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> V2: keep snprintf
>> modifiy the tests for truncated output
>> Update subject and description
>> ---
>> tools/perf/util/cpumap.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
>> index 983b7388f22b..dc5c5e6fc502 100644
>> --- a/tools/perf/util/cpumap.c
>> +++ b/tools/perf/util/cpumap.c
>> @@ -317,7 +317,7 @@ static void set_max_cpu_num(void)
>>
>> /* get the highest possible cpu number for a sparse allocation */
>> ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
>> - if (ret == PATH_MAX) {
>> + if (ret >= PATH_MAX) {
>> pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
>> goto out;
>> }
>> @@ -328,7 +328,7 @@ static void set_max_cpu_num(void)
>>
>> /* get the highest present cpu number for a sparse allocation */
>> ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt);
>> - if (ret == PATH_MAX) {
>> + if (ret >= PATH_MAX) {
>> pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
>> goto out;
>> }
>> @@ -356,7 +356,7 @@ static void set_max_node_num(void)
>>
>> /* get the highest possible cpu number for a sparse allocation */
>> ret = snprintf(path, PATH_MAX, "%s/devices/system/node/possible", mnt);
>> - if (ret == PATH_MAX) {
>> + if (ret >= PATH_MAX) {
>> pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
>> goto out;
>> }
>> @@ -441,7 +441,7 @@ int cpu__setup_cpunode_map(void)
>> return 0;
>>
>> n = snprintf(path, PATH_MAX, "%s/devices/system/node", mnt);
>> - if (n == PATH_MAX) {
>> + if (n >= PATH_MAX) {
>> pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
>> return -1;
>> }
>> @@ -456,7 +456,7 @@ int cpu__setup_cpunode_map(void)
>> continue;
>>
>> n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name);
>> - if (n == PATH_MAX) {
>> + if (n >= PATH_MAX) {
>> pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
>> continue;
>> }
>> --
>> 2.20.1
>>
next prev parent reply other threads:[~2020-03-24 14:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 7:03 [PATCH V2] perf cpumap: Fix snprintf overflow check Christophe JAILLET
2020-03-24 12:50 ` Arnaldo Carvalho de Melo
2020-03-24 14:44 ` Christophe JAILLET [this message]
2020-03-25 12:19 ` Arnaldo Carvalho de Melo
2020-04-04 8:41 ` [tip: perf/urgent] " tip-bot2 for Christophe JAILLET
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=75a8e792-dc9e-6169-4dd2-8758967c50e2@wanadoo.fr \
--to=christophe.jaillet@wanadoo.fr \
--cc=David.Laight@aculab.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=arnaldo.melo@gmail.com \
--cc=dzickus@redhat.com \
--cc=jolsa@redhat.com \
--cc=jstancek@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=zhe.he@windriver.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;
as well as URLs for NNTP newsgroup(s).