References: CVE-2026-16530
Description: libpcp: fix OOB read in __pmDecodeInstance (CWE-125/195)
 The __pmDecodeInstance() loop advances ip by the PDU alignment-padded
 entry size after each instance.  When namelen % 4 != 0, the padding
 advance can push ip past pdu_end.  The existing bounds check casts the
 pointer difference to size_t: (size_t)(pdu_end - (char *)ip).  When ip
 is past pdu_end, this produces a negative ptrdiff_t that wraps to a
 very large size_t, causing both bounds checks to silently pass.
 Execution falls through to memcpy reading past the PDU buffer.
 .
 Fix: add an explicit signed pointer guard at the top of each loop
 iteration — if ((char *)ip >= pdu_end) — before the size_t cast.
 This ensures the subsequent unsigned comparison is always valid.
 .
 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/b743fc58795bd3667b78e3b0759251fef27a983b
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/p_instance.c
+++ b/src/libpcp/src/p_instance.c
@@ -290,6 +290,13 @@
     pdu_used = (char *)&pp->rest[0];
     for (i = j = 0; i < res->numinst; i++) {
 	ip = (instlist_t *)&pp->rest[j/sizeof(__pmPDU)];
+	if ((char *)ip >= pdu_end) {
+	    if (pmDebugOptions.pdu)
+		fprintf(stderr, "%s: PM_ERR_IPC: inst[%d] ip past pdu_end\n",
+		    __FUNCTION__, i);
+	    sts = PM_ERR_IPC;
+	    goto badsts;
+	}
 	if (sizeof(instlist_t) - sizeof(ip->name) > (size_t)(pdu_end - (char *)ip)) {
 	    if (pmDebugOptions.pdu) {
 		fprintf(stderr, "__pmDecodeInstance: PM_ERR_IPC: sizeof(instlist_t) %d - sizeof(name) %d > remainder %d\n",
