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 62DCF415F1A; Tue, 21 Jul 2026 19:39:58 +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=1784662799; cv=none; b=VbOYUsLfM3gytM7PRZS/hv60rkTgk1wwG+hh8FV11e1VReWHDWUVJ6HFnrsiLLweGOkPi6xHAnBNpcpC9Zh5dAjPhE+VpnWaKHiTPfwW0whcz2MElAliez5nJhRqmOMqsZAc9sFiLwNrPRJSmM7tC7BigbNY6AglCguIMs4X/I4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662799; c=relaxed/simple; bh=WJSd9kQ0eK7yR3AUTGlsnodg0iEsQvCdmiBGdgAIViQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s5aOrkJISoJ0Rvh7FvT0jQIIz40RhMmTeZid7iMgxOmBe6D6mdabpb17mjv5cqKlD5HKIvaoZxaNZ+lPFFgSTk6kcPVBoI/csVnZop5/whCajg7U4PlMXGfHDJFKBs8/kcRlELOJN2GYE77zw1YN0/nzXZfnWgfOmlv+9apteQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=smGmECPS; 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="smGmECPS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C245E1F000E9; Tue, 21 Jul 2026 19:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784662798; bh=6lucmu2F5WFXoHWYcD0Xz+5oPyTHDk8B+mYozdAUKJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=smGmECPS1ohAhGs5SK3NeE0sj+Okbtf9VpBu/KAmH4Y5cJEsDia9AFz0eeJ506b67 OwLFcHM1iazFX8QiKgkxm9E3CqtgEnXHZcBYGQKbJKouIDqeAcgulHVI1TMPwv6CxQ PCq8sZoqiwCGFdbuYT/1Gqi9BV9saCenJXCb2rQ4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Ian Rogers , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.12 0554/1276] perf symbols: Break infinite loop on zero-filled notes in sysfs__read_build_id() Date: Tue, 21 Jul 2026 17:16:37 +0200 Message-ID: <20260721152458.516499617@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit 063c647b24f640657d6d9e2e90d620ea3ee19ae6 ] sysfs__read_build_id() iterates ELF note headers from sysfs files in a while(1) loop. If the file contains a zero-filled note header (both n_namesz and n_descsz are 0), the code computes n = namesz + descsz = 0 and calls read(fd, bf, 0). read() with count 0 returns 0, which matches the expected (ssize_t)n value, so the error check passes and the loop repeats — reading the same zero bytes and spinning forever. This can happen with corrupted or zero-padded sysfs pseudo-files. Add a check for n == 0 before the read, since no valid ELF note has both name and description of zero length. Reported-by: sashiko-bot Fixes: f1617b40596cb341 ("perf symbols: Record the build_ids of kernel modules too") Reviewed-by: Ian Rogers 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 4ba49975970a9b..bb3c1b68fe3706 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1092,6 +1092,9 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid) } else { n = namesz + descsz; } + /* no valid note has both namesz and descsz zero */ + if (n == 0) + break; if (read(fd, bf, n) != (ssize_t)n) break; } -- 2.53.0