File perf-cpumap-fix-snprintf-overflow-check.patch of Package perf
87
1
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
2
Date: Tue, 24 Mar 2020 08:03:19 +0100
3
Subject: perf cpumap: Fix snprintf overflow check
4
Git-commit: d74b181a028bb5a468f0c609553eff6a8fdf4887
5
Patch-mainline: v5.7-rc1
6
References: git-fixes
7
8
'snprintf' returns the number of characters which would be generated for
9
the given input.
10
11
If the returned value is *greater than* or equal to the buffer size, it
12
means that the output has been truncated.
13
14
Fix the overflow test accordingly.
15
16
Fixes: 7780c25bae59f ("perf tools: Allow ability to map cpus to nodes easily")
17
Fixes: 92a7e1278005b ("perf cpumap: Add cpu__max_present_cpu()")
18
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
19
Suggested-by: David Laight <David.Laight@ACULAB.COM>
20
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
21
Cc: Don Zickus <dzickus@redhat.com>
22
Cc: He Zhe <zhe.he@windriver.com>
23
Cc: Jan Stancek <jstancek@redhat.com>
24
Cc: Jiri Olsa <jolsa@redhat.com>
25
Cc: Kan Liang <kan.liang@linux.intel.com>
26
Cc: Mark Rutland <mark.rutland@arm.com>
27
Cc: Namhyung Kim <namhyung@kernel.org>
28
Cc: Peter Zijlstra <peterz@infradead.org>
29
Cc: kernel-janitors@vger.kernel.org
30
Link: http://lore.kernel.org/lkml/20200324070319.10901-1-christophe.jaillet@wanadoo.fr
31
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
32
Signed-off-by: Tony Jones <tonyj@suse.de>
33
---
34
tools/perf/util/cpumap.c | 10 +++++-----
35
1 file changed, 5 insertions(+), 5 deletions(-)
36
37
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
38
index 983b7388f22b..dc5c5e6fc502 100644
39
--- a/tools/perf/util/cpumap.c
40
+++ b/tools/perf/util/cpumap.c
41
42
43
/* get the highest possible cpu number for a sparse allocation */
44
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt);
45
- if (ret == PATH_MAX) {
46
+ if (ret >= PATH_MAX) {
47
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
48
goto out;
49
}
50
51
52
/* get the highest present cpu number for a sparse allocation */
53
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt);
54
- if (ret == PATH_MAX) {
55
+ if (ret >= PATH_MAX) {
56
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
57
goto out;
58
}
59
60
61
/* get the highest possible cpu number for a sparse allocation */
62
ret = snprintf(path, PATH_MAX, "%s/devices/system/node/possible", mnt);
63
- if (ret == PATH_MAX) {
64
+ if (ret >= PATH_MAX) {
65
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
66
goto out;
67
}
68
69
return 0;
70
71
n = snprintf(path, PATH_MAX, "%s/devices/system/node", mnt);
72
- if (n == PATH_MAX) {
73
+ if (n >= PATH_MAX) {
74
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
75
return -1;
76
}
77
78
continue;
79
80
n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name);
81
- if (n == PATH_MAX) {
82
+ if (n >= PATH_MAX) {
83
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
84
continue;
85
}
86
87