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 BC6D046AA69; Tue, 21 Jul 2026 18:07:35 +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=1784657256; cv=none; b=jZJenXnDg6eKiNISGlH10m6Orvzt3cUEKFC14kDwBZsrH557t8idyH2DMqigLC9Npq3dygFqOhwMs4VOQJ5Yuo0K6Tw2eHhSHEqTqoA46nJk37mfqWiDpH85N0JmYYto26PRPkoRQC11CKXqL2pwhGqoF7DOK/A00pcAhnXDkQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784657256; c=relaxed/simple; bh=keulhSR+j8y2v8FOkRTgImvLcDYNje8nhkcJE1RlJiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r1S3rQQ+2n3RXCGlO9J8o787Lr5pjtHwYgQ+y6448AHbrCDNB9eUNO+YJKuqFCvZ1zHMo07FEk4ldBoUSVXf2lKchDGw/UbRrM+fUsM5Y4Qh/6pwFMqaKkv612lGKYt4oXInh7AT8KFmuFjcDkyNKgLLRegQe6LWnYrO+m77AyI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=EfnPURTl; 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="EfnPURTl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EDEB1F000E9; Tue, 21 Jul 2026 18:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784657255; bh=oJRBELXRv2/GHk9nL6d4+fCzOPiMCRMCq882jsW52ME=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EfnPURTlrMaNiu5v6metYk27dD5gFGUOudA8R6o75ks6lxvMbrviXWYLGtOTl0Mex H4DfVhdMMn90GkqVQKiMlCD5nzCkVr2QdwtnhPx1GcGI42TGfXtL3LXfURYgpP/V6k PoZutiHghY6h0w/RlUgs5HhtjuuSULZ4MMo8mhkk= 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 6.18 0694/1611] perf bpf: Use scnprintf() in snprintf_hex() and synthesize_bpf_prog_name() Date: Tue, 21 Jul 2026 17:13:30 +0200 Message-ID: <20260721152530.991373098@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152514.750365251@linuxfoundation.org> References: <20260721152514.750365251@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.18-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 2298cd396c4235..9b0638e5f4afb7 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -36,7 +36,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; } @@ -140,7 +140,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) { @@ -153,9 +153,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