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 AE58F3B42CB; Tue, 21 Jul 2026 22:13:01 +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=1784671982; cv=none; b=h2/4xpXBGcydlf+HzivoN/g7028rMonZ9iJcOG7D+3A2dlVlvjJdSuVLjD2jImFT6jSsDXXQQsSWLxoJ8hHIXB/wv8raTVxiBVigvQwkjdc40zuZPMrh/WwB1FGPEqyh4DEtaIQLtZCFec81gz46RoCZrsuxNUMF1t9cxmaR4jQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784671982; c=relaxed/simple; bh=nMI9CCLJt+xRwPifzP7i9jHJvEl6AT8B79YbigltXjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m8F0mh1gNIM9VBPMsAcaMw8WebgOekMD3BNPfnbb4WujjXvg7MP4PhiQSB8Xz39D7M+x7/Q2jhc8TVLKv0a7/+TuvWMOy7IBFkH4Fs/0R22mU7TZ47l/xz+OyZCrCJkQ7kVYWETArB0fDp/zPWXdArpicuKzqWY4jpfgwZDG+TY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CpbMMEai; 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="CpbMMEai" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 208CB1F000E9; Tue, 21 Jul 2026 22:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784671981; bh=S4K6O/QJNB7sLyGzbkIo1FXrhNTwB3HneXhOYg7nMz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CpbMMEaixKMJBjuzfBTtZ9Cd6FKQOErrH0QlY/Sj9EFmzw+mX+gXEAiSJh/zL8wNt Eg5jibgzxty6urdnCK94761Ku7hKphCDE0Q7z6DnEmgGwk9cj4LoM2vSSWhx/punwl vas2CYTu/DLfD1z42g88XJsTkusGGvclYG58qRcQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Ian Rogers , Song Liu , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.15 409/843] perf bpf: Use scnprintf() in snprintf_hex() and synthesize_bpf_prog_name() Date: Tue, 21 Jul 2026 17:20:44 +0200 Message-ID: <20260721152415.240528194@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit cab3a9331ed0b3f884dd61c8a25b3cf123705982 ] Both functions accumulate formatted output via ret += snprintf(buf + ret, size - ret, ...). If the buffer is too small and snprintf() returns more than the remaining space, ret exceeds size and the next 'size - ret' underflows, causing snprintf() to write past the buffer end. Switch to scnprintf() which returns the actual number of bytes written, making the accumulation safe. Fixes: 7b612e291a5affb1 ("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs") Reported-by: sashiko-bot Reviewed-by: Ian Rogers 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index e96a7fdfe283b5..56ab0d85931e36 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -42,7 +42,7 @@ static int snprintf_hex(char *buf, size_t size, unsigned char *data, size_t len) size_t i; for (i = 0; i < len; i++) - ret += snprintf(buf + ret, size - ret, "%02x", data[i]); + ret += scnprintf(buf + ret, size - ret, "%02x", data[i]); return ret; } @@ -143,7 +143,7 @@ static int synthesize_bpf_prog_name(char *buf, int size, const struct btf_type *t; int name_len; - name_len = snprintf(buf, size, "bpf_prog_"); + 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) { @@ -156,9 +156,10 @@ static int synthesize_bpf_prog_name(char *buf, int size, short_name = info->name; } else short_name = "F"; - if (short_name) - name_len += snprintf(buf + name_len, size - name_len, - "_%s", short_name); + if (short_name) { + name_len += scnprintf(buf + name_len, size - name_len, + "_%s", short_name); + } return name_len; } -- 2.53.0