Skip to content

Commit 79f60d5

Browse files
tititiou36gregkh
authored andcommitted
perf cpumap: Fix snprintf overflow check
[ Upstream commit d74b181 ] '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 accordingly. Fixes: 7780c25 ("perf tools: Allow ability to map cpus to nodes easily") Fixes: 92a7e12 ("perf cpumap: Add cpu__max_present_cpu()") Signed-off-by: Christophe JAILLET <[email protected]> Suggested-by: David Laight <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Don Zickus <[email protected]> Cc: He Zhe <[email protected]> Cc: Jan Stancek <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 47e276e commit 79f60d5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tools/perf/util/cpumap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static void set_max_cpu_num(void)
299299

300300
/* get the highest possible cpu number for a sparse allocation */
301301
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
302-
if (ret == PATH_MAX) {
302+
if (ret >= PATH_MAX) {
303303
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
304304
goto out;
305305
}
@@ -310,7 +310,7 @@ static void set_max_cpu_num(void)
310310

311311
/* get the highest present cpu number for a sparse allocation */
312312
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt);
313-
if (ret == PATH_MAX) {
313+
if (ret >= PATH_MAX) {
314314
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
315315
goto out;
316316
}
@@ -338,7 +338,7 @@ static void set_max_node_num(void)
338338

339339
/* get the highest possible cpu number for a sparse allocation */
340340
ret = snprintf(path, PATH_MAX, "%s/devices/system/node/possible", mnt);
341-
if (ret == PATH_MAX) {
341+
if (ret >= PATH_MAX) {
342342
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
343343
goto out;
344344
}
@@ -423,7 +423,7 @@ int cpu__setup_cpunode_map(void)
423423
return 0;
424424

425425
n = snprintf(path, PATH_MAX, "%s/devices/system/node", mnt);
426-
if (n == PATH_MAX) {
426+
if (n >= PATH_MAX) {
427427
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
428428
return -1;
429429
}
@@ -438,7 +438,7 @@ int cpu__setup_cpunode_map(void)
438438
continue;
439439

440440
n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name);
441-
if (n == PATH_MAX) {
441+
if (n >= PATH_MAX) {
442442
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
443443
continue;
444444
}

0 commit comments

Comments
 (0)