* [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished
@ 2025-07-16 20:15 Ian Rogers
2025-07-16 20:15 ` [PATCH v1 2/3] perf pmu: Switch FILENAME_MAX to NAME_MAX Ian Rogers
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ian Rogers @ 2025-07-16 20:15 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, James Clark, linux-kernel,
linux-perf-users
FILENAME_MAX is often PATH_MAX (4kb), far more than needed for the
/proc path. Make the buffer size sufficient for the maximum integer
plus "/proc/" and "/status" with a '\0' terminator.
Fixes: 5ce42b5de461 ("tools subcmd: Add non-waitpid check_if_command_finished()")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/lib/subcmd/run-command.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/lib/subcmd/run-command.c b/tools/lib/subcmd/run-command.c
index 0a764c25c384..dda7cbd298eb 100644
--- a/tools/lib/subcmd/run-command.c
+++ b/tools/lib/subcmd/run-command.c
@@ -5,6 +5,7 @@
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
+#include <linux/compiler.h>
#include <linux/string.h>
#include <errno.h>
#include <sys/wait.h>
@@ -216,10 +217,20 @@ static int wait_or_whine(struct child_process *cmd, bool block)
return result;
}
+/*
+ * Conservative estimate of number of characaters needed to hold an a decoded
+ * integer, assume each 3 bits needs a character byte and plus a possible sign
+ * character.
+ */
+#ifndef is_signed_type
+#define is_signed_type(type) (((type)(-1)) < (type)1)
+#endif
+#define MAX_STRLEN_TYPE(type) (sizeof(type) * 8 / 3 + is_signed_type(type) ? 1 : 0)
+
int check_if_command_finished(struct child_process *cmd)
{
#ifdef __linux__
- char filename[FILENAME_MAX + 12];
+ char filename[6 + MAX_STRLEN_TYPE(typeof(cmd->pid)) + 7 + 1];
char status_line[256];
FILE *status_file;
@@ -227,7 +238,7 @@ int check_if_command_finished(struct child_process *cmd)
* Check by reading /proc/<pid>/status as calling waitpid causes
* stdout/stderr to be closed and data lost.
*/
- sprintf(filename, "/proc/%d/status", cmd->pid);
+ sprintf(filename, "/proc/%u/status", cmd->pid);
status_file = fopen(filename, "r");
if (status_file == NULL) {
/* Open failed assume finish_command was called. */
--
2.50.0.727.gbf7dc18ff4-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 2/3] perf pmu: Switch FILENAME_MAX to NAME_MAX
2025-07-16 20:15 [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished Ian Rogers
@ 2025-07-16 20:15 ` Ian Rogers
2025-07-16 20:15 ` [PATCH v1 3/3] perf ui scripts: " Ian Rogers
2025-07-17 9:46 ` [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2025-07-16 20:15 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, James Clark, linux-kernel,
linux-perf-users
FILENAME_MAX is the same as PATH_MAX (4kb) in glibc rather than
NAME_MAX's 255. Switch to using NAME_MAX and ensure the '\0' is
accounted for in the path's buffer size.
Fixes: 754baf426e09 ("perf pmu: Change aliases from list to hashmap")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/pmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b09b2ea2407a..f3da6e27bfcb 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -453,7 +453,7 @@ static struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu,
{
struct perf_pmu_alias *alias;
bool has_sysfs_event;
- char event_file_name[FILENAME_MAX + 8];
+ char event_file_name[NAME_MAX + 8];
if (hashmap__find(pmu->aliases, name, &alias))
return alias;
@@ -752,7 +752,7 @@ static int pmu_aliases_parse(struct perf_pmu *pmu)
static int pmu_aliases_parse_eager(struct perf_pmu *pmu, int sysfs_fd)
{
- char path[FILENAME_MAX + 7];
+ char path[NAME_MAX + 8];
int ret, events_dir_fd;
scnprintf(path, sizeof(path), "%s/events", pmu->name);
--
2.50.0.727.gbf7dc18ff4-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 3/3] perf ui scripts: Switch FILENAME_MAX to NAME_MAX
2025-07-16 20:15 [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished Ian Rogers
2025-07-16 20:15 ` [PATCH v1 2/3] perf pmu: Switch FILENAME_MAX to NAME_MAX Ian Rogers
@ 2025-07-16 20:15 ` Ian Rogers
2025-07-17 9:46 ` [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2025-07-16 20:15 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, James Clark, linux-kernel,
linux-perf-users
FILENAME_MAX is the same as PATH_MAX (4kb) in glibc rather than
NAME_MAX's 255. Switch to using NAME_MAX and ensure the '\0' is
accounted for in the path's buffer size.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/ui/browsers/scripts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 2d04ece833aa..1e8c2c2f952d 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -94,7 +94,7 @@ static int check_ev_match(int dir_fd, const char *scriptname, struct perf_sessio
FILE *fp;
{
- char filename[FILENAME_MAX + 5];
+ char filename[NAME_MAX + 5];
int fd;
scnprintf(filename, sizeof(filename), "bin/%s-record", scriptname);
--
2.50.0.727.gbf7dc18ff4-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished
2025-07-16 20:15 [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished Ian Rogers
2025-07-16 20:15 ` [PATCH v1 2/3] perf pmu: Switch FILENAME_MAX to NAME_MAX Ian Rogers
2025-07-16 20:15 ` [PATCH v1 3/3] perf ui scripts: " Ian Rogers
@ 2025-07-17 9:46 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-07-17 9:46 UTC (permalink / raw)
To: Ian Rogers, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Adrian Hunter, Kan Liang, James Clark, linux-kernel,
linux-perf-users
Cc: llvm, oe-kbuild-all
Hi Ian,
kernel test robot noticed the following build errors:
[auto build test ERROR on perf-tools-next/perf-tools-next]
[also build test ERROR on tip/perf/core perf-tools/perf-tools linus/master v6.16-rc6 next-20250716]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ian-Rogers/perf-pmu-Switch-FILENAME_MAX-to-NAME_MAX/20250717-042514
base: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
patch link: https://lore.kernel.org/r/20250716201512.792052-1-irogers%40google.com
patch subject: [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished
config: arm-randconfig-001-20250717 (https://download.01.org/0day-ci/archive/20250717/202507171729.UkGLqJBw-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 16534d19bf50bde879a83f0ae62875e2c5120e64)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250717/202507171729.UkGLqJBw-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507171729.UkGLqJBw-lkp@intel.com/
All errors (new ones prefixed by >>):
>> run-command.c:233:20: error: operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Werror,-Wparentheses]
233 | char filename[6 + MAX_STRLEN_TYPE(typeof(cmd->pid)) + 7 + 1];
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
run-command.c:228:76: note: expanded from macro 'MAX_STRLEN_TYPE'
228 | #define MAX_STRLEN_TYPE(type) (sizeof(type) * 8 / 3 + is_signed_type(type) ? 1 : 0)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
run-command.c:233:20: note: place parentheses around the '+' expression to silence this warning
233 | char filename[6 + MAX_STRLEN_TYPE(typeof(cmd->pid)) + 7 + 1];
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
run-command.c:228:76: note: expanded from macro 'MAX_STRLEN_TYPE'
228 | #define MAX_STRLEN_TYPE(type) (sizeof(type) * 8 / 3 + is_signed_type(type) ? 1 : 0)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
run-command.c:233:20: note: place parentheses around the '?:' expression to evaluate it first
233 | char filename[6 + MAX_STRLEN_TYPE(typeof(cmd->pid)) + 7 + 1];
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
run-command.c:228:76: note: expanded from macro 'MAX_STRLEN_TYPE'
228 | #define MAX_STRLEN_TYPE(type) (sizeof(type) * 8 / 3 + is_signed_type(type) ? 1 : 0)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
1 error generated.
make[6]: *** [tools/build/Makefile.build:85: tools/bpf/resolve_btfids/libsubcmd/run-command.o] Error 1 shuffle=467312727
make[6]: Target '__build' not remade because of errors.
make[5]: *** [Makefile:78: tools/bpf/resolve_btfids/libsubcmd/libsubcmd-in.o] Error 2 shuffle=467312727
make[5]: Target 'tools/bpf/resolve_btfids/libsubcmd/libsubcmd.a' not remade because of errors.
make[4]: *** [Makefile:56: tools/bpf/resolve_btfids//libsubcmd/libsubcmd.a] Error 2 shuffle=467312727
make[4]: Target 'all' not remade because of errors.
make[3]: *** [Makefile:76: bpf/resolve_btfids] Error 2 shuffle=467312727
make[2]: *** [Makefile:1443: tools/bpf/resolve_btfids] Error 2 shuffle=467312727
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=467312727
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2 shuffle=467312727
make: Target 'prepare' not remade because of errors.
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-17 9:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 20:15 [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished Ian Rogers
2025-07-16 20:15 ` [PATCH v1 2/3] perf pmu: Switch FILENAME_MAX to NAME_MAX Ian Rogers
2025-07-16 20:15 ` [PATCH v1 3/3] perf ui scripts: " Ian Rogers
2025-07-17 9:46 ` [PATCH v1 1/3] tools subcmd: Tighten the filename size in check_if_command_finished kernel test robot
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).