Commit 9a1d2d2e authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Greg Kroah-Hartman

perf cpumap: Fix snprintf overflow check

[ Upstream commit d74b181a ]

'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: 7780c25b ("perf tools: Allow ability to map cpus to nodes easily")
Fixes: 92a7e127 ("perf cpumap: Add cpu__max_present_cpu()")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Suggested-by: default avatarDavid Laight <David.Laight@ACULAB.COM>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: He Zhe <zhe.he@windriver.com>
Cc: Jan Stancek <jstancek@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: kernel-janitors@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200324070319.10901-1-christophe.jaillet@wanadoo.frSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 69077bd8
...@@ -462,7 +462,7 @@ static void set_max_cpu_num(void) ...@@ -462,7 +462,7 @@ static void set_max_cpu_num(void)
/* get the highest possible cpu number for a sparse allocation */ /* get the highest possible cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt); 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); pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
goto out; goto out;
} }
...@@ -473,7 +473,7 @@ static void set_max_cpu_num(void) ...@@ -473,7 +473,7 @@ static void set_max_cpu_num(void)
/* get the highest present cpu number for a sparse allocation */ /* get the highest present cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); 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); pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
goto out; goto out;
} }
...@@ -501,7 +501,7 @@ static void set_max_node_num(void) ...@@ -501,7 +501,7 @@ static void set_max_node_num(void)
/* get the highest possible cpu number for a sparse allocation */ /* get the highest possible cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/node/possible", mnt); 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); pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
goto out; goto out;
} }
...@@ -586,7 +586,7 @@ int cpu__setup_cpunode_map(void) ...@@ -586,7 +586,7 @@ int cpu__setup_cpunode_map(void)
return 0; return 0;
n = snprintf(path, PATH_MAX, "%s/devices/system/node", mnt); 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); pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
return -1; return -1;
} }
...@@ -601,7 +601,7 @@ int cpu__setup_cpunode_map(void) ...@@ -601,7 +601,7 @@ int cpu__setup_cpunode_map(void)
continue; continue;
n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name); 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); pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
continue; continue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment