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 58CFF3AEF58; Tue, 21 Jul 2026 22:45:59 +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=1784673960; cv=none; b=TJkhM5JNW7rWpGeSt69VkkI1A7nDRVbowh6/M93FkYPq4QlIMpCDUPAOdoJMmcrhBiHXYYwU5rXWSSKflwpVKg+76AcjvZ6C4KC0mpmTWd35/5fawrwXgF1cvyz1UFu3kkqJrjXcCxUwAItcLByY5BXsNDdbPLgLm+3UPNg9NS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784673960; c=relaxed/simple; bh=6iVKY5wPhgVa7pJxnDxPyGnvCkMQHSeRNvo/U4S9dM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IRwec2/Ewh6+D/UTVyIr5amQ3M0D+9U1oHAeJn9RTz6ydT6KlXAthyeE4/1RO+fmgD6bs2e0DqPIR8i/HNmm7gNjxqdwSBZMwCA+v4Pc3445vBojDn3mt7hcpsg/96W1d1VZDp0hBs/ayTLwmQwBeiPwYdU2DnpIdkopspTObbY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ghfJokl3; 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="ghfJokl3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD2681F000E9; Tue, 21 Jul 2026 22:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784673959; bh=7YBqGYG6eGWfgoevcCg/1YLBSBtH2gc90si1hPoKyGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ghfJokl3NWlxG1kWHonTcoJ4OSUSo6X3/+RACAbDVkPeYrcwupNupHEwPMH5R22Jk bqaMnAvGPPEPiT+uSF2IQ8Ag5lU1FYRb3iNXTFactjCkoHABMQ7q6UvoRYp0CONzVl 1l0O1K3lUHRMPTkH0GW4Kyx0ff8TJz/ZCDFITYsA= 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 5.10 317/699] perf symbols: Bounds-check descsz in sysfs__read_build_id() GNU fallback Date: Tue, 21 Jul 2026 17:21:16 +0200 Message-ID: <20260721152402.843687069@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152355.667394603@linuxfoundation.org> References: <20260721152355.667394603@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 5.10-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 2ebceeff87c6f4..bf11448eb4177d 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -653,8 +653,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