From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796476296; b=RkZQokrHDovGof/26taUyx/up0dQQXDJBO9GARN+LkZVv6sxY8H+XF1VfBE1L2fVcYed IqC5SLRv9wvr+n/BogdnfA4jL8vG2SG4ZcRm3yDgflVLwD1EGLNW9o11B+stGsizWtXx/ zxTev8T0azHmWCTwShZMPiVy4cncdExYUFHIj2e2YNKVcM1Mg1yLGd8IfzQFxHaoJ275o jalUT0mVsuT45/NHtJQcyQLI909EEjCTKm3ro+5ubmM/ormYsF8yPnLUrv7tzkAebTHPX uIOrvxsH3wHmv5hILALWCgenSjXAoeIl+AKjwcuVdqa4+p9S5Ceb+pC3PpWDP6Fwucw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796476296; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-Developer-Signature:X-Developer-Key: Content-Transfer-Encoding; bh=hpDxUJWKtnLCTgm7uqcqRwlfmr5QxHrsayGNRrXXxEY=; b=4i0DItQM3HKBEMTyCDxTs3V63lUTQhj2roBLfKr6XjGi7tAnkr4Og7UKVQquxpnu5nMe ZPQvqFB15m07IgiiZo5/4jB4kusWNDHI06J7j54v3MT1tNaumrrI9wF89P/A98EsZLe69 gwaCVc8Yf9nqS6fem05Fb4yJSDJErywX8Gdq4QnO+i2tqxNarmeVs5SdakBhzbsUpcUhi MljJsHzFQR2oz9aQ2/dazhdLw13Q04MwZeSv/8cxyOUj5Qj5SDhVY6/iuU9HQoTfhJgOD IRmOQamZrIuXDdFhuVRBE2Umv0wPaxR+Rldu23ADF7eOdBDzDDxEBMyCU+NjZi70IOQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="km/CToB9"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 500B6606A322; Sat, 5 Dec 2026 13:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=km/CToB9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0A971F00936; Sat, 5 Dec 2026 13:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796476296; bh=hpDxUJWKtnLCTgm7uqcqRwlfmr5QxHrsayGNRrXXxEY=; h=From:To:Cc:Subject:Date; b=km/CToB9Tdymcu2/f93K/CcuTmRz909qc5XFIlTEjENKNsYKYVH+UnpOLigYuIuyU hGPPS2ZrogWkpDpJAWkURgLmSyQIYWw7niLnOfv4yIJqaTspnmg7tfqeaBSC85adwQ 2fh9I07h6ymR+jGF0rIsB+PL90O6zZAVbgqjrJsRfyScBZX2cyvVJ+OvSsav3nrDCz qEIhY+affroR4qvjf+yqk8L+duSdvHvcpcE0MrXD9IdImgAzBsoQzhfPtJRi8dCbKO N5gWDaJXYPRJtg1WdL8ANLaTGlS14YigbHB8BHxQgEoZ3y2RjgWpcJEHWEsYGrA8OF H2gv3wccgAv9Q== From: Thorsten Blum To: Andrew Morton , Song Liu , Jiri Olsa , Ihor Solodrai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Yonghong Song , Emil Tsalapatis Cc: Thorsten Blum , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes Date: Sat, 5 Dec 2026 14:11:20 +0100 Message-ID: <20261205131119.105160-2-blum@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1092; i=blum@kernel.org; h=from:subject; bh=DDEVipeqTqMP8aZUy0OofzJG38Bnplia8hdgGELQ2m4=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDNkivOVcNyKTzd9NbFLycmyW0TtSXvlAZbP2VIHSgNuhi 81DE4o7SlkYxLgYZMUUWR7M+jHDt7SmcpNJxE6YOaxMIEMYuDgFYCKx/YwMa6+v2avOa7ZksXvG 93N//mUI+C2d4dR169UdrcWbi8RvpjP8L/YSLn95sSrmwJbp371VS1h2Zz19v/m0z+c7rN8/8lY XsAMA X-Developer-Key: i=blum@kernel.org; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit For u32 note sizes, ALIGN() wraps the values 0xfffffffd through 0xffffffff to 0 before check_add_overflow() runs. Parsing can then continue as if the affected size were 0. Use u64 for name_sz and desc_sz to avoid alignment wraparound, allowing check_add_overflow() to reject these malformed notes early. Signed-off-by: Thorsten Blum --- Changes in v2: - Reframe the change as hardening and drop the Fixes: tag (Alexei) - v1: https://lore.kernel.org/r/20261123142510.51241-2-blum@kernel.org/ lib/buildid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/buildid.c b/lib/buildid.c index 995a327f46ae..767243f424d6 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -161,7 +161,8 @@ static int parse_build_id(struct freader *r, unsigned char *build_id, __u32 *siz { const char note_name[] = "GNU"; const size_t note_name_sz = sizeof(note_name); - u32 build_id_off, new_off, note_end, name_sz, desc_sz; + u32 build_id_off, new_off, note_end; + u64 name_sz, desc_sz; const Elf32_Nhdr *nhdr; const char *data;