From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 791862EBB84; Fri, 12 Jun 2026 00:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781224530; cv=none; b=DYhUd38RCPgw5wxQfuFnE1PWNQNFY7E1SGp3CPNOb695KZcRytj6b6D3k9y2oqv45xEqakgGRZRSrP5aNC3pnUcz2l9dmdanCw95KIyEC1dfiASAW0eFu3JWTE5RAUazmrkiYxHOoGzXD0o8YxsvlZnUIyWefrzu5O8Mhh+Wr+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781224530; c=relaxed/simple; bh=ykNVuErbfJQg0B4bTh0qHB4ICh11BpKkRWG3Npn99Vc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I/HW+cyxEnTGeVFVeuL34tGKjEhzVl0Nx+BswKhbZKhKSL8AifYWpJB3SsS+Z15zS78UsmbgXKxGMNMa7D3XlcoMrt83joDHdvH/OaVShpa5YZwAi+ujuu1soAdPdvnj/V64TGdecekqHhFvuycAaGx41dYX3pNRHyQGGjcQPG4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cJpeZX6w; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cJpeZX6w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A59771F000E9; Fri, 12 Jun 2026 00:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781224529; bh=N+pSTo/Skue1syM+k/apN2oz+c3vwd5HAXXw71qySlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cJpeZX6wahj0qOes+0bidL0Ze2onWniyTrCBDQ31gdHNwiuADZqJS06VbX+mCXmAh MrslnxU07H2zknIBCe2fV+ENpzdROHJ+E297LknjgYpVLWKSdI32iPidpPYEOnD0b7 HCqPLiPiiYmFC/rSK7LgPzsLF/bimV7EJ0bVeGg0I0JMG2tRC24mLaRLvpk1/a7v3c iokiwJuaoP32zanzvuAcOkVjKlB7XkSC3Q6HyS+P87+R6sNUZppaq3bnCqiMSU/1Yw KAujlDu4uzpsNWRngr1L74fQ8Blr7Xiz8M5q+5v9PenV3mPMIXRHUT734SXnDPt7uh lmDpGqSNCW7xQ== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , sashiko-bot , Song Liu , "Claude Opus 4.6" Subject: [PATCH 10/15] perf bpf: Validate func_info_rec_size and sub_id in synthesize_bpf_prog_name() Date: Thu, 11 Jun 2026 21:34:38 -0300 Message-ID: <20260612003444.50723-11-acme@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260612003444.50723-1-acme@kernel.org> References: <20260612003444.50723-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnaldo Carvalho de Melo synthesize_bpf_prog_name() computes a pointer into the func_info array using sub_id * info->func_info_rec_size without validating either value. Both come from perf.data and are untrusted: - A func_info_rec_size smaller than sizeof(struct bpf_func_info) means the finfo pointer would reference a truncated entry, reading past it into adjacent data. - A sub_id >= nr_func_info computes an offset past the func_info buffer, causing an out-of-bounds read. Add bounds checks for both values before computing the pointer offset. When validation fails, fall through to the non-BTF name path instead of reading garbage. Reported-by: sashiko-bot Fixes: 7b612e291a5affb1 ("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs") Cc: Song Liu Assisted-by: Claude Opus 4.6 Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/bpf-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index c4594969d7677238..fe6fbca508c5135c 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -143,7 +143,9 @@ static int synthesize_bpf_prog_name(char *buf, int size, name_len = scnprintf(buf, size, "bpf_prog_"); name_len += snprintf_hex(buf + name_len, size - name_len, prog_tags[sub_id], BPF_TAG_SIZE); - if (btf) { + if (btf && + info->func_info_rec_size >= sizeof(*finfo) && + sub_id < info->nr_func_info) { finfo = func_infos + sub_id * info->func_info_rec_size; t = btf__type_by_id(btf, finfo->type_id); if (t) -- 2.54.0