References: CVE-2026-16530
Description: libpcp: fix OOB read in __pmLogLoadLabelSet (CWE-125)
 __pmLogLoadLabelSet() reads timestamp, type, ident, and nsets fields
 from tbuf at sequential offsets without checking that rlen is large
 enough to contain them.  When the pmproxy logger servlet delivers a
 TYPE_LABEL record with hdr.len=13 (minimum accepted by the dispatcher),
 rlen=1 and the function reads 20-24 bytes from a 1-byte buffer.
 .
 Fix: add minimum-length guard at the top of __pmLogLoadLabelSet()
 using LABELSET_V3_MINRLEN / LABELSET_V2_MINRLEN macros derived from
 the on-disk __pmExtLabelSet_v3/v2 struct sizes (minus the len+type
 header that rlen excludes).
 .
 Test coverage will be added in a consolidated pducrash.c extension
 covering vulns 9-13.
 .
 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/ccd1bb167934b5e4a60d39bacf25e12e0a2decb4
Last-Update: 2026-07-25
 Backport-Note:
 Backported to PCP 6.3.8 (applies unchanged). No libpcp3 tree in 6.3.8, so that mirror hunk is dropped.


--- a/src/libpcp/src/e_labels.c
+++ b/src/libpcp/src/e_labels.c
@@ -56,6 +56,10 @@
     				/* will be expanded if nsets > 0 */
 } __pmExtLabelSet_v2;
 
+/* Minimum rlen (record body without len+type header) to read fixed fields */
+#define LABELSET_V3_MINRLEN	(sizeof(__pmExtLabelSet_v3) - 2 * sizeof(__int32_t))
+#define LABELSET_V2_MINRLEN	(sizeof(__pmExtLabelSet_v2) - 2 * sizeof(__int32_t))
+
 /*
  * pack a set of labels into a physical metadata record
  * - lcp required to provide archive version
@@ -215,6 +219,23 @@
     *nsetsp = 0;
     *labelsetsp = NULL;
 
+    if (rtype == TYPE_LABEL_V2) {
+	if (rlen < (int)LABELSET_V2_MINRLEN) {
+	    if (pmDebugOptions.logmeta)
+		fprintf(stderr, "%s: v2 rlen=%d too small (min=%d)\n",
+			__FUNCTION__, rlen, (int)LABELSET_V2_MINRLEN);
+	    return PM_ERR_LOGREC;
+	}
+    }
+    else {
+	if (rlen < (int)LABELSET_V3_MINRLEN) {
+	    if (pmDebugOptions.logmeta)
+		fprintf(stderr, "%s: v3 rlen=%d too small (min=%d)\n",
+			__FUNCTION__, rlen, (int)LABELSET_V3_MINRLEN);
+	    return PM_ERR_LOGREC;
+	}
+    }
+
     k = 0;
     if (rtype == TYPE_LABEL_V2) {
 	__pmLoadTimeval((__int32_t *)&tbuf[k], stamp);
