| Message ID | 20261102225947.1725-12-oleg.tolmatcev@gmail.com |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3BFDF4BA23FD for <patchwork@sourceware.org>; Mon, 2 Nov 2026 23:04:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BFDF4BA23FD Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UWkgwR6s X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 41C0C4BA23F4 for <binutils@sourceware.org>; Mon, 2 Nov 2026 23:01:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41C0C4BA23F4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 41C0C4BA23F4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793660489; cv=none; b=B7CT/rqyUbpqmpdirDdSkxzx+JOlSsYwrO1hI5rMZkPsmDhrG9pcVX0m1yVd5co68zN1+i2RVXTCk01rBcGO7knooGswhcT6GIazus9p+8pfE2UNwoGVWSIYzUrVlUwGpZM+2i2UbDh5k+KtAaRGnMztVPQYMRRZCZEfj2UeXeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793660489; c=relaxed/simple; bh=qqXaEIHEySPBGEMZFTbJaGpuKtTE8KaZ7PE96r2Wjno=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QOKkCcj9O/D7bf7sfEKOXJMfgdjMm1hXeaoT1lgQtDrKclPZUlDK0kxnfy3+S0kuHeRSDuZtOgNVnYwXYsyHuLTizvtwlZRfpEvPoKB2RH6KBXhc5wKtuMaQ9gy19EI5lS8V05xR1L9O0qgU2A2S3UGiUgsUitVWhsR1EjdtDME= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UWkgwR6s DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41C0C4BA23F4 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-48dfdd0678dso2473298f8f.0 for <binutils@sourceware.org>; Mon, 02 Nov 2026 15:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793660488; x=1794265288; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SmIlPC3qf4JgobtUnF5Ru5nNYFyGMA4WaYabpDFwV3I=; b=UWkgwR6sdLu/lIHzjjKmxp00qnlOfS060FAsxDsUhZRScwAcR9aiABgN72EXRdbtNz MSUaSds35ZwZGorXazE6ISpNVii2bnpJZuSwbuI1ldCnGdV+WNsHPGKAivUJEdm9iuWa FK/thpJdNm+Cb2ixYHgqAGuACxwBbLTXbO3x8dAlkw8R3wgYc96TRV1O3PHMnqJg4JRY 6uG9a0jQZwm+/qdneI+uikIApfM7phlVO9BmwMyxUCJhQMnb4h/emhQks4+WTtui4oBV lqHr/BkI24qKC8kaBOt8y6WgyZ8QN6AhDpYvGsYTajCYon9DH5c4Hxb6ZJWQncRP1D9c UdcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793660488; x=1794265288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SmIlPC3qf4JgobtUnF5Ru5nNYFyGMA4WaYabpDFwV3I=; b=tdWvurv8dPhDiQ9EEt9iLAc4yKuMwfmsz5UbZi4TOmcX9swydeL1lYLieEXBxro6jB 0NxDR0rRGVVDF71Ti0pO4Rf0omcO8+pxRD8JX0IZEVKnoGsC0lMB+I5tHQ3IMMcK0WNG gH+bnmdlshECRkOkxMGKp0EL491IUycKSJUhjkNh9MuJf/o/vLOrng7JTpFQzd5CVOGs fKB0ZK/nD0AnIHD2VFb0j5wh83i4Ye0pNLoHD4jFRTYNgWw5amjNNBf4hQ+ss8+6EyFx cja3coDVTinTBZLNTyPoa4qgZERK5u8RBWGirk/dH8DYFE1iXSI+ksHF6DBgBi1NKESM boJw== X-Gm-Message-State: APuU4Z/Imj9dJBRiGQymjh1RMTDQs7JfZ8cULCyLfNoFoaWp72Douw0C /YEnhzExBqbv/LwmbN5ES9mEgqeVwjoewn6NazRWtN9rtpuRXlZy4F2rNo+z4Q== X-Gm-Gg: AYBFou309rdLUy9+k63jCKzlVGkF+ff7py59zTHyVZ6pUjSIw6wfPwV9mOX6aEb/X3v 3gDUBVA+GdhtKmYnFN5dyB2c8aByQPZrMnaIwOA8OnI4+I8OLns0/AXsovy/jBMIDn0Y0Z2SI4Z On2Y+ioD8y/ReeCkOZzvk8HYtZH6+tarY+loIwIBIpYXAPSkZoxoaT7AjLVnZmHkuugnSHsi1U8 JaG7uRRL0M+90unZnQk4iu9g/uS0AP5TcHAnmPAczNOV1SBOVgUnd+vydGEuO3+jYKNJpx3vW9C 2RUrSm8dpswldH52Btvhii49kNVSfQ4g2ld0B0UkXnEeYTnuIO/ahV4fCSsm2mIaV99y9v8bFW3 jVhj0kwqd4/9jSHF6oc0umVK3lQV1QWxUqPpJsTlKDbDBfgtfe//+HW9PI8eJQoDXUq44Ht96UN ubfoBOJFtOyVNt1SkbDr6W9+xiKx0w0hyt/oeHBi/7Q9+yXKYh0At/TkJkExV+9sNYiu2/rrbgL hHy3rRsWRYEQrvgBGh77fOCW/Onv+ra54EriHTbtbgZCMwpourkycSuej1XipRPsr9gFL+5P/jh 2UpkSYaAAT9xk7RcfnD2CzKVP5goNBPTNCGTXJ84Kp/1RO2rskJ1UhhdWVy3WL+FzERQI9gYAVR 0QzurEINueoS0OV1Wl/qrjg== X-Received: by 2002:adf:f707:0:b0:48e:517b:cf21 with SMTP id ffacd0b85a97d-48e6e4f5017mr19962709f8f.26.1793660488030; Mon, 02 Nov 2026 15:01:28 -0800 (PST) Received: from Mein-PC (p200300ed8f274c00edef5ac00064aca9.dip0.t-ipconnect.de. [2003:ed:8f27:4c00:edef:5ac0:64:aca9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71ba24f6sm22626729f8f.51.2026.11.02.15.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 15:01:27 -0800 (PST) From: Oleg Tolmatcev <oleg.tolmatcev@gmail.com> To: binutils@sourceware.org Cc: Oleg Tolmatcev <oleg.tolmatcev@gmail.com> Subject: [PATCH] ld/pdb: Zero-initialize symbol arrays in handle_debugs_section Date: Mon, 2 Nov 2026 23:59:52 +0100 Message-ID: <20261102225947.1725-12-oleg.tolmatcev@gmail.com> X-Mailer: git-send-email 2.56.0.windows.1 In-Reply-To: <20261102225947.1725-2-oleg.tolmatcev@gmail.com> References: <20261102225947.1725-2-oleg.tolmatcev@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_GMAIL_RCVD, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
ld/pdb: Zero-initialize symbol arrays in handle_debugs_section
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_binutils_build--master-arm | fail | Patch failed to apply |
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 | fail | Patch failed to apply |
Commit Message
Oleg Tolmatcev
Nov. 2, 2026, 10:59 p.m. UTC
handle_debugs_section only fills in symbols and sectlist for primary
symbols with a positive section number, so a relocation in a malformed
object referring to any other symbol read uninitialized memory.
Allocate both arrays with xcalloc; the relocate_section routines skip
relocations against a NULL section.
ld/
* pdb.c (handle_debugs_section): Allocate symbols and sectlist
with xcalloc.
Signed-off-by: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>
---
ld/pdb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On 02.11.2026 23:59, Oleg Tolmatcev wrote: > handle_debugs_section only fills in symbols and sectlist for primary > symbols with a positive section number, so a relocation in a malformed > object referring to any other symbol read uninitialized memory. > Allocate both arrays with xcalloc; the relocate_section routines skip > relocations against a NULL section. This primarily explains why sectlist wants clearing up front. And indeed for that you address a pre-existing issue. For symbols[], otoh, prior to "ld/pdb: Skip auxiliary symbol entries in handle_debugs_section" all elements of the array are initialized. Hence that clearing (to play safe) imo wants moving to that patch. > --- a/ld/pdb.c > +++ b/ld/pdb.c > @@ -1948,8 +1948,8 @@ handle_debugs_section (asection *s, bfd *mod, struct string_table *strings, > > relocs = bfd_coff_read_internal_relocs (mod, s, false, NULL, true, NULL); > > - symbols = xmalloc (sizeof (struct internal_syment) * syment_count); > - sectlist = xmalloc (sizeof (asection *) * syment_count); > + symbols = xcalloc (syment_count, sizeof (struct internal_syment)); > + sectlist = xcalloc (syment_count, sizeof (asection *)); While making these changes it would be nice if the sizeof(<type>) were also changed to the more robust sizeof(<expr>) (making sure a type change of the variables stored into is also reflected in a size change). I can make these changes ahead of committing, provided you agree. Jan
пт, 6 нояб. 2026 г. в 11:35, Jan Beulich <jbeulich@suse.com>: > > On 02.11.2026 23:59, Oleg Tolmatcev wrote: > > handle_debugs_section only fills in symbols and sectlist for primary > > symbols with a positive section number, so a relocation in a malformed > > object referring to any other symbol read uninitialized memory. > > Allocate both arrays with xcalloc; the relocate_section routines skip > > relocations against a NULL section. > > This primarily explains why sectlist wants clearing up front. And indeed > for that you address a pre-existing issue. For symbols[], otoh, prior to > "ld/pdb: Skip auxiliary symbol entries in handle_debugs_section" all > elements of the array are initialized. Hence that clearing (to play safe) > imo wants moving to that patch. > > > --- a/ld/pdb.c > > +++ b/ld/pdb.c > > @@ -1948,8 +1948,8 @@ handle_debugs_section (asection *s, bfd *mod, struct string_table *strings, > > > > relocs = bfd_coff_read_internal_relocs (mod, s, false, NULL, true, NULL); > > > > - symbols = xmalloc (sizeof (struct internal_syment) * syment_count); > > - sectlist = xmalloc (sizeof (asection *) * syment_count); > > + symbols = xcalloc (syment_count, sizeof (struct internal_syment)); > > + sectlist = xcalloc (syment_count, sizeof (asection *)); > > While making these changes it would be nice if the sizeof(<type>) were > also changed to the more robust sizeof(<expr>) (making sure a type change > of the variables stored into is also reflected in a size change). > > I can make these changes ahead of committing, provided you agree. > > Jan I do agree of course, thanks. Oleg
diff --git a/ld/pdb.c b/ld/pdb.c index c36efeede19..2b9e8d313c7 100644 --- a/ld/pdb.c +++ b/ld/pdb.c @@ -1948,8 +1948,8 @@ handle_debugs_section (asection *s, bfd *mod, struct string_table *strings, relocs = bfd_coff_read_internal_relocs (mod, s, false, NULL, true, NULL); - symbols = xmalloc (sizeof (struct internal_syment) * syment_count); - sectlist = xmalloc (sizeof (asection *) * syment_count); + symbols = xcalloc (syment_count, sizeof (struct internal_syment)); + sectlist = xcalloc (syment_count, sizeof (asection *)); ext = (bfd_byte *) coff_data (mod)->external_syms;