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 B6411471246; Tue, 21 Jul 2026 19:04:36 +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=1784660677; cv=none; b=h379up+SmLl+Hk4nLbDbXTq3ydMv/Gs7roxiwEGqLEicLKxlO2grWMUWUyLJY0XY3ajj3N8C+qa2U6QUuofMhMpbjx7DED1Fs6H+zueH4zASFc3TYHAMJnVJTaAmmi0zgh3S5CroAGmfVR5iqYNrIs5f8qVpr5H8u6DteJHe+hI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784660677; c=relaxed/simple; bh=vgZRE1KvN5XXdppzL/7BSNgvZecwtaWjotZ/eTi8uFE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cS5qZh1iCpGb3uSDYorUaoOJ1p3g19vGo6m3fhTUDoHuOgIbel1B1bFTX3OqW9LEhGsz1c+wVBdxD8kVs9wbsDsj1ttWgZm3njzDLIdOS5GgXLBten9NKCitydsbrRpRIEb7qxlUct8gcufPScX+I9+NiuK+Ln+H2QaE9dMKh0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N+jMoFWq; 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="N+jMoFWq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26DE01F000E9; Tue, 21 Jul 2026 19:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784660676; bh=uAUeDYylbCW3Zuv24fy4YI58X7Bn6v4+6+DRuwyJDLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N+jMoFWqbTt4BIkAfZSfs0JCK9YexYnYJbvYqCN6315Y99kEWdPM7I2GRrw+6pUZb iXUCeNSsnwDjyKR4OXqbdmrmX+THpIA7c4Qm6Jx2MIHEKpZsHlKPWqr+hlO3zpD7fx 5+55KEkDOQLmD01s8+Yv7Ts+pN0MWXb5B2dyQbIg= 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 7.1 1071/2077] perf symbols: Break infinite loop on zero-filled notes in sysfs__read_build_id() Date: Tue, 21 Jul 2026 17:12:24 +0200 Message-ID: <20260721152618.083037824@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@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 7.1-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 41ef08b490183b..2007f8f003e3b3 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -994,6 +994,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