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 4B85634DCE3; Tue, 21 Jul 2026 21:30:06 +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=1784669408; cv=none; b=UEh2qLxMeXnPzKNW0wlRDhw/JQo3HDlW8qtaR63G2UT4Rx5HCMqtszRR61amz8V6U34J0pYLKC2VIMqnXhJOG3Yi0qw9fmb8GaqQ+QoOt+Xcz/krkwYMPNyhFK6kHNCI8h4LP96s34Ni/pcuynChXkzmTHwSpd+BPm3d2NXE5JY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669408; c=relaxed/simple; bh=AWAsZoX7mivFy7O3a5hk33Kg5rPwbgf0ly07L0qfEh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ef0qgicaqOusrAR7KVam0RiqqMNuc/PKSmXN+sCZtwj99zBhRvF5koOG5erAFcuJfWTIrjl0pe8mkC34q84NOO/e8VeIat0dy8aOVN5zlDYQ47ymx9qAsxBZagvNOndochmNxGdy8ewAcP9+c1q5sdwW6klPbWMwvJd39J188zc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=v+LHYMzJ; 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="v+LHYMzJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 602EF1F000E9; Tue, 21 Jul 2026 21:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784669406; bh=lcrRmLEvIPRt+FPm8ZxH7DEvKqw+w3UXQvxkgOGJjo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=v+LHYMzJCj3+HI2a2gGeIRFUt6ZJQ9bnyIugCfY0Ke1j5XJpnoLungjYOFcqFOO2L nGS0sNbQdABfli42x7o6T9Xl1l+rLUmNhsMYCA66ghR5Aq9GDDe5hHCg0k1KqNsYRT CRBKC7T9AR5WHdtVRlRoiSCe75cBqgXV9gnjYigA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.1 0543/1067] perf symbols: Bounds-check descsz in sysfs__read_build_id() GNU fallback Date: Tue, 21 Jul 2026 17:19:04 +0200 Message-ID: <20260721152436.758354985@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-Type: text/plain; charset=UTF-8 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 1b4e9fbdeabc549965e70ac0cd8095d57ff6df06 ] When sysfs__read_build_id() matches NT_GNU_BUILD_ID with the right namesz but the name content is not "GNU", it falls back to reading descsz bytes into the stack buffer bf[BUFSIZ]: } else if (read(fd, bf, descsz) != (ssize_t)descsz) Unlike the else branch which validates namesz + descsz against sizeof(bf), this path passes descsz directly to read() without any bounds check. A crafted sysfs file with a large n_descsz overflows the 8192-byte stack buffer. Add a descsz > sizeof(bf) check before the read, breaking out of the loop on oversized values. Fixes: e5a1845fc0aeca85 ("perf symbols: Split out util/symbol-elf.c") Reported-by: sashiko-bot Cc: Namhyung Kim Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/symbol-elf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 5203902b417daa..0db4959dbd22bd 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -691,8 +691,13 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid) err = 0; break; } - } else if (read(fd, bf, descsz) != (ssize_t)descsz) - break; + } else { + /* descsz from untrusted file — clamp to buffer */ + if (descsz > sizeof(bf)) + break; + if (read(fd, bf, descsz) != (ssize_t)descsz) + break; + } } else { size_t n; -- 2.53.0