Skip to contentSkip to conversation

selftests/bpf: Sanitize traffic monitor log file names

PATCH In review Vineet Gupta 3 participants 5 messages Aug 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: Sanitize traffic monitor log file names

The traffic monitor names its capture logs after the test and subtest being run, replacing '/' and ' ' so the result is usable as a file name. Test names are free form though, and other characters make it through. A subtest called "INET4: bpf timestamping" produces

/tmp/tmon_pcap/packets-125-15-net_timestamping__INET4:_bpf_timestamping-net_timestamping_ns.log

CI systems that collect these logs as artifacts reject such names. GitHub Actions' upload-artifact fails the upload with

Error: The path for one of the files in artifact is not valid:
... Contains the following character: Colon :

Replace the whole set of awkward characters in one pass rather than adding another strchr() loop per character. Note the loop tests *p before calling strchr(), so the terminating NUL is never passed to it.

This came up as a side error/annoyance when trying to re-enable BPF-GCC CI runs [1]. The CI side already has path name normalization and needs some tweaking as well, however fixing it at the source also makes sense.

Fixes f52403b6bfea ("selftests/bpf: Add traffic monitor functions.")
---
 tools/testing/selftests/bpf/network_helpers.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +7 -4
index db935a9d9fc1..3818cec354a0 100644
@@ -1142,10 +1142,13 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
 		snprintf(buf, len, "%s__%s", test_name, subtest_name);
 	else
 		snprintf(buf, len, "%s", test_name);
-	while ((p = strchr(buf, '/')))
-		*p = '_';
-	while ((p = strchr(buf, ' ')))
-		*p = '_';
+	/* Test names are free form, so replace anything that is awkward in a
+	 * file name. Besides the path separator, this covers the characters
+	 * rejected by CI systems collecting these logs as artifacts.
+	 */
+	for (p = buf; *p; p++)
+		if (strchr("/ \":<>|*?\r\n", *p))
+			*p = '_';
 }
 
 #define PCAP_DIR "/tmp/tmon_pcap"
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The backslash character `\` is missing from the sanitization string, leaving artifact names…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The backslash character \ is missing from the sanitization string, leaving artifact names vulnerable to rejection by GitHub Actions.
- [Low] The newly introduced multi-line comment violates the BPF subsystem's strict comment style guidelines.
--

--- Patch [1]: [PATCH bpf-next] selftests/bpf: Sanitize traffic monitor log file names --- commit 4eb40c6024aab5f28e7a52af3fba116cbdeff427
Author: Vineet Gupta <[email protected]>

selftests/bpf: Sanitize traffic monitor log file names

The traffic monitor names its capture logs after the test and subtest being run, replacing '/' and ' ' so the result is usable as a file name. This patch replaces the whole set of awkward characters in one pass to fix artifact upload failures in CI systems like GitHub Actions.

Quoted 6 lines
tools/testing/selftests/bpf/network_helpers.c +0 -0
index db935a9d9fc1a..3818cec354a0d 100644
@@ -1142,10 +1142,13 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
 		snprintf(buf, len, "%s__%s", test_name, subtest_name);

tools/testing/selftests/bpf/network_helpers.c static void encode_test_name(char *buf, size_t len, const char *test_name, const · line 1148

Quoted 10 lines
tools/testing/selftests/bpf/network_helpers.c +4 -4
 	else
 		snprintf(buf, len, "%s", test_name);
-	while ((p = strchr(buf, '/')))
-		*p = '_';
-	while ((p = strchr(buf, ' ')))
-		*p = '_';
+	/* Test names are free form, so replace anything that is awkward in a
+	 * file name. Besides the path separator, this covers the characters
+	 * rejected by CI systems collecting these logs as artifacts.
+	 */

[Severity: Low]
This isn't a bug, but does this multi-line comment in encode_test_name() conflict with the BPF subsystem's comment style guidelines? The opening /* is typically expected to be placed on its own line.

tools/testing/selftests/bpf/network_helpers.c static void encode_test_name(char *buf, size_t len, const char *test_name, const · line 1150

Quoted 2 lines
tools/testing/selftests/bpf/network_helpers.c +2 -0
+	for (p = buf; *p; p++)
+		if (strchr("/ \":<>|*?\r\n", *p))

[Severity: Medium]
Since this is meant to cover characters rejected by CI systems like GitHub Actions, should the backslash character '\\' also be included in this sanitization string?

If a test or subtest name contains a backslash, it appears the artifact upload could still fail.

Quoted 2 lines
tools/testing/selftests/bpf/network_helpers.c +1 -0
+			*p = '_';
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 30 lines · On 8/6/26 2:17 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The backslash character \ is missing from the sanitization string, leaving artifact names vulnerable to rejection by GitHub Actions.
- [Low] The newly introduced multi-line comment violates the BPF subsystem's strict comment style guidelines.
--

--- Patch [1]: [PATCH bpf-next] selftests/bpf: Sanitize traffic monitor log file names --- commit 4eb40c6024aab5f28e7a52af3fba116cbdeff427
Author: Vineet Gupta <[email protected]>

selftests/bpf: Sanitize traffic monitor log file names

The traffic monitor names its capture logs after the test and subtest being run, replacing '/' and ' ' so the result is usable as a file name. This patch replaces the whole set of awkward characters in one pass to fix artifact upload failures in CI systems like GitHub Actions.

Quoted 12 lines
tools/testing/selftests/bpf/network_helpers.c +0 -4
index db935a9d9fc1a..3818cec354a0d 100644
@@ -1142,10 +1142,13 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
  		snprintf(buf, len, "%s__%s", test_name, subtest_name);
  	else
  		snprintf(buf, len, "%s", test_name);
-	while ((p = strchr(buf, '/')))
-		*p = '_';
-	while ((p = strchr(buf, ' ')))
-		*p = '_';
Quoted 8 lines

tools/testing/selftests/bpf/network_helpers.c static void encode_test_name(char *buf, size_t len, const char *test_name, const · line 1148

Quoted 4 lines
tools/testing/selftests/bpf/network_helpers.c +4 -0
+	/* Test names are free form, so replace anything that is awkward in a
+	 * file name. Besides the path separator, this covers the characters
+	 * rejected by CI systems collecting these logs as artifacts.
+	 */

[Severity: Low]
This isn't a bug, but does this multi-line comment in encode_test_name() conflict with the BPF subsystem's comment style guidelines? The opening /* is typically expected to be placed on its own line.

It follows the pre-existing convention in this file and for netdev in general. I can fix if maintainers prefer that.

Quoted 9 lines

tools/testing/selftests/bpf/network_helpers.c static void encode_test_name(char *buf, size_t len, const char *test_name, const · line 1150

Quoted 2 lines
tools/testing/selftests/bpf/network_helpers.c +2 -0
+	for (p = buf; *p; p++)
+		if (strchr("/ \":<>|*?\r\n", *p))

[Severity: Medium]
Since this is meant to cover characters rejected by CI systems like GitHub Actions, should the backslash character '\\' also be included in this sanitization string?

If a test or subtest name contains a backslash, it appears the artifact upload could still fail.

The original intention was parity with libbpf-ci: run-vmtest/normalize-paths-for-github.sh but agree adding the backslash makes it more robust.

Thx,
-Vineet

reviewer
#3 lore raw
In reply to Vineet Gupta
Quoted 36 lines · Vineet Gupta

The traffic monitor names its capture logs after the test and subtest being run, replacing '/' and ' ' so the result is usable as a file name. Test names are free form though, and other characters make it through. A subtest called "INET4: bpf timestamping" produces

/tmp/tmon_pcap/packets-125-15-net_timestamping__INET4:_bpf_timestamping-net_timestamping_ns.log

CI systems that collect these logs as artifacts reject such names. GitHub Actions' upload-artifact fails the upload with

Error: The path for one of the files in artifact is not valid:
... Contains the following character: Colon :

Replace the whole set of awkward characters in one pass rather than adding another strchr() loop per character. Note the loop tests *p before calling strchr(), so the terminating NUL is never passed to it.

This came up as a side error/annoyance when trying to re-enable BPF-GCC CI runs [1]. The CI side already has path name normalization and needs some tweaking as well, however fixing it at the source also makes sense.

Fixes f52403b6bfea ("selftests/bpf: Add traffic monitor functions.")
---
 tools/testing/selftests/bpf/network_helpers.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +0 -0
index db935a9d9fc1..3818cec354a0 100644
@@ -1142,10 +1142,13 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
 		snprintf(buf, len, "%s__%s", test_name, subtest_name);
 	else
 		snprintf(buf, len, "%s", test_name);

tools/testing/selftests/bpf/network_helpers.c static void encode_test_name(char *buf, size_t len, const char *test_name, const · line 1150

Quoted 10 lines
tools/testing/selftests/bpf/network_helpers.c +6 -4
-	while ((p = strchr(buf, '/')))
-		*p = '_';
-	while ((p = strchr(buf, ' ')))
-		*p = '_';
+	/* Test names are free form, so replace anything that is awkward in a
+	 * file name. Besides the path separator, this covers the characters
+	 * rejected by CI systems collecting these logs as artifacts.
+	 */
+	for (p = buf; *p; p++)
+		if (strchr("/ \":<>|*?\r\n", *p))

Hi Vineet,

We already do this on the CI side here:
https://github.com/libbpf/ci/blob/main/run-vmtest/normalize-paths-for-github.sh

The problem on the CI side is that the script is not executed in some corner cases, like a VM timeout.

I don't think this change is necessary upstream: the paths are technically valid, it's an issue for CI only due to github quirks.

Quoted 4 lines
tools/testing/selftests/bpf/network_helpers.c +1 -0
+			*p = '_';
 }
 
 #define PCAP_DIR "/tmp/tmon_pcap"
#4 lore raw
Quoted 49 lines · Ihor Solodrai
Quoted 36 lines · Vineet Gupta

The traffic monitor names its capture logs after the test and subtest being run, replacing '/' and ' ' so the result is usable as a file name. Test names are free form though, and other characters make it through. A subtest called "INET4: bpf timestamping" produces

/tmp/tmon_pcap/packets-125-15-net_timestamping__INET4:_bpf_timestamping-net_timestamping_ns.log

CI systems that collect these logs as artifacts reject such names. GitHub Actions' upload-artifact fails the upload with

Error: The path for one of the files in artifact is not valid:
... Contains the following character: Colon :

Replace the whole set of awkward characters in one pass rather than adding another strchr() loop per character. Note the loop tests *p before calling strchr(), so the terminating NUL is never passed to it.

This came up as a side error/annoyance when trying to re-enable BPF-GCC CI runs [1]. The CI side already has path name normalization and needs some tweaking as well, however fixing it at the source also makes sense.

Fixes f52403b6bfea ("selftests/bpf: Add traffic monitor functions.")
---
  tools/testing/selftests/bpf/network_helpers.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +0 -0
index db935a9d9fc1..3818cec354a0 100644
@@ -1142,10 +1142,13 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
  		snprintf(buf, len, "%s__%s", test_name, subtest_name);
  	else
  		snprintf(buf, len, "%s", test_name);

tools/testing/selftests/bpf/network_helpers.c static void encode_test_name(char *buf, size_t len, const char *test_name, const · line 1150

Quoted 10 lines
tools/testing/selftests/bpf/network_helpers.c +6 -4
-	while ((p = strchr(buf, '/')))
-		*p = '_';
-	while ((p = strchr(buf, ' ')))
-		*p = '_';
+	/* Test names are free form, so replace anything that is awkward in a
+	 * file name. Besides the path separator, this covers the characters
+	 * rejected by CI systems collecting these logs as artifacts.
+	 */
+	for (p = buf; *p; p++)
+		if (strchr("/ \":<>|*?\r\n", *p))

Hi Vineet,

Quoted 8 lines

We already do this on the CI side here:
https://github.com/libbpf/ci/blob/main/run-vmtest/normalize-paths-for-github.sh

The problem on the CI side is that the script is not executed in some corner cases, like a VM timeout.

I don't think this change is necessary upstream: the paths are technically valid, it's an issue for CI only due to github quirks.

Yeah I've submitted that separately [1] - this was more of a preventive fix to not generate such file names in the first place.

Thx,
-Vineet

[1] https://github.com/kernel-patches/vmtest/pull/504