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 7DFAE3B9950; Tue, 21 Jul 2026 21:32:14 +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=1784669535; cv=none; b=IZ4xIGxxWm71zCvb7HVyCQduu4MVvWbc/XPYscWjYwI3I0bUYqTlwF5KnAvS0jxCXKMpsJuJCKWj7XpFEl2SEKm9AwDgJSTwzYrXZIYB8uUFyB+nGtxG1uSGNNGRzKynAtD4Q3ROmuxPCOEwXgNkARxfL3snnRna9Y3PPzi/ZB4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669535; c=relaxed/simple; bh=+9oC5TNepoUinEtWSY4xz6NGyet5FBa+OrTe7Vq7p50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fnyaJDE0+eEoo50EntfWHxnwdvwtTXWMSr6Bec6x0QmytwSQA6wZATUfEjNbtSCwMmRYy+pPpJ1ArpD+xgt0X4g+/F4wsIS6p8QGWEOeJTxxIXZIoRoyU2yBX3HmszsaP97Tu060x/kp4rN511Dbl/YVbrbDlKj88mNcMLM2F2s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1ri8vCEc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1ri8vCEc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E1D21F000E9; Tue, 21 Jul 2026 21:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784669534; bh=+0Y2l/h1CCzJaVTkZzkSPvxHU4PLnXblcgN+O4aywgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1ri8vCEcyTUF7yQ9nYdoVF/ZIfG4IiBemLElXWD2JIWh1LVv/rnwvPRclXI/fNNTQ voWelzIy2qbvyWIu8AkCZTLL7HiToVSPOWSMdLaFErV5QrwDiRH97DWSWDGuGZ25Rw 44d/eMx9PpFwQSgMX46yH+Qo+dAXnVHir+S6Uy3c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Song Liu , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.1 0564/1067] perf bpf: Validate func_info_rec_size and sub_id in synthesize_bpf_prog_name() Date: Tue, 21 Jul 2026 17:19:25 +0200 Message-ID: <20260721152437.219884007@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit 10b3c3d63ecc17c6acb855bac5f40367f1115765 ] 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:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- 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 5a4138cbba89a0..ec65ad4bc8631a 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -198,7 +198,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.53.0