References: CVE-2026-16531
Description: libpcp_web: fix path traversal via hostname in logger servlet (CWE-22)
 The pmproxy logger servlet (POST /logger/label) accepts a binary
 __pmLogLabel PDU and uses the hostname field directly in path
 construction without sanitization.  An attacker can supply
 hostname='../../../../tmp/target' causing pmproxy to create .meta
 and .index files at arbitrary paths writable by the pcp user.
 .
 Fix: add check_hostname() allowlist check — only alphanumeric, hyphen,
 dot, and underscore characters are permitted (per RFC 952/1123 plus
 underscore for real-world compatibility).  Leading dots are rejected
 to prevent relative path components.  Invalid hostnames are rejected
 with -EINVAL before any path construction occurs.
 .
 Add qa/2106 verifying that a label with a path-traversal hostname
 is rejected and no files are created outside the log directory.
 .
 Reported-by: Francisco Alisson Bezerra, TIM Security Red Team
 Reported-by: Lucas Gabriel Alves, TIM Security Red Team
 Reported-by: Massimiliano Brolli, TIM Security Red Team
 .
 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
 .
Author: Nathan Scott <nathans@redhat.com>
Origin: upstream, https://github.com/performancecopilot/pcp/commit/dd6ed05f143f97e00198cb4b0180c6375d758cbe https://github.com/performancecopilot/pcp/commit/f86c0f4cdac8df0b6fb05f60872f6f29bbc96429
Last-Update: 2026-07-25
 Backport-Note:
 PARTIAL / hardening-only for PCP 6.3.8. The pmproxy logger servlet (loggroup.c) does
  not exist in 6.3.8 (logpush is a post-6.3.8 feature), so the reported path-traversal
  vector is not present. Only the timezone/zoneinfo validation in pmNewZone() (tz.c) is
  carried, as defence-in-depth.


--- a/src/libpcp/src/tz.c
+++ b/src/libpcp/src/tz.c
@@ -25,6 +25,7 @@
  * lock initialization in pmNewContext().
  */
 
+#include <ctype.h>
 #include "pmapi.h"
 #include "libpcp.h"
 #include "sha256.h"
@@ -573,6 +574,22 @@
     return 0;
 }
 
+static int
+valid_tz(const char *tz)
+{
+    const char	*p;
+
+    if (tz == NULL || tz[0] == '\0' || tz[0] == '/')
+	return 0;
+    for (p = tz; *p; p++) {
+	if (!isalnum((unsigned char)*p) && strchr("/_+-.:,\"'", *p) == NULL)
+	    return 0;
+    }
+    if (strstr(tz, "..") != NULL)
+	return 0;
+    return 1;
+}
+
 int
 pmNewZone(const char *tz)
 {
@@ -580,6 +597,13 @@
     int		hack = 0;
     int		sts;
 
+    if (!valid_tz(tz)) {
+	if (pmDebugOptions.context)
+	    fprintf(stderr, "%s: rejecting unsafe timezone: %s\n",
+		__FUNCTION__, tz ? tz : "(null)");
+	return -EINVAL;
+    }
+
     PM_LOCK(__pmLock_extcall);
 
     len = (int)strlen(tz);
