| Message ID | 20251129114527.973538-1-code@rkapl.cz |
|---|---|
| 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 2326F48FD3AA for <patchwork@sourceware.org>; Sat, 29 Nov 2025 11:46:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2326F48FD3AA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=rkapl.cz header.i=@rkapl.cz header.a=rsa-sha256 header.s=mx_main header.b=dMX9E3El X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from droplet.rkapl.cz (droplet.rkapl.cz [46.101.253.207]) by sourceware.org (Postfix) with ESMTPS id BB01C48FDCB7 for <binutils@sourceware.org>; Sat, 29 Nov 2025 11:45:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB01C48FDCB7 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=rkapl.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rkapl.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BB01C48FDCB7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=46.101.253.207 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764416735; cv=none; b=eO8b9W3owOwHLJQFFvgf8QQW7wE2OI2gDzWTb/X7qKN8x67cEAMJRB0Ez2ixumaJzsAyltAxmtSxFPGM4BazXBuDpiCVyqJrsZ8IMWfji8B1pc7k1GxNTIgDWHZKyQpBPBFSuYiif3paNhk1E2sfyQF+z0RzpOUbklMvvu0qx4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764416735; c=relaxed/simple; bh=BJno4BOFtX3MqAwycsr6KisffBkwPU41AFSafrK90ZI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vcqI+fFMXKcn+rN1wrL1BiKA1+MyUUC3gr1BO40PBmzHTwrzr5aaGVZO6HhEyIj8x/+xH8PuwZz5ugWj67Cbxx5As6ySaTwSxpw4r8a/UXr4wpbq3fo/Vz/QP+ZBp59WDrLpwKBf8RrWA7UsDHKCxhpRXCteO9NceeVsOcnlBes= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB01C48FDCB7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rkapl.cz; s=mx_main; t=1764416698; bh=BJno4BOFtX3MqAwycsr6KisffBkwPU41AFSafrK90ZI=; h=From:To:Cc:Subject:Date:From; b=dMX9E3ElG+pHibirGcHuK501XmxwnY0WBWKWA+XBMkUT/HUdr+fBhoSiKWQR7EipC p22qT+XB99YqH5WtYrXJs8nxCG/wPa7Sr1XfDnyfcNnCLFnHpeMAyy/MX5eSN/QpfZ ZYcsNfDYbCyQDXoYmb3m8bl7U5HJOZfwUct7TVpvvc+mdg42B5TZngi/48ofxMyowd 0/LOYNXugkY2UjEULg2oi4Nzbfu5RzGrFtImdJ5CsHLMUOiTy2OpNgJXMfDYm+mlaf VMp1zkuFs5zNK1SYz2feiAbS/GdlWji5E6AZKa/1AnrkeIhbx9+icDN6pEVOjR7L8q nCgQur+HHpdIA== Received: from rntb (unknown [IPv6:2a02:8308:91:8900::bdb1]) by droplet.rkapl.cz (Postfix) with ESMTPSA id B486E60DEA; Sat, 29 Nov 2025 12:44:58 +0100 (CET) From: Roman Kapl <code@rkapl.cz> To: binutils@sourceware.org Cc: Roman Kapl <code@rkapl.cz> Subject: [PATCH 1/1] bfd: fix potential missing seek Date: Sat, 29 Nov 2025 12:45:27 +0100 Message-ID: <20251129114527.973538-1-code@rkapl.cz> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS 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 |
[1/1] bfd: fix potential missing seek
|
|
Commit Message
Roman Kapl
Nov. 29, 2025, 11:45 a.m. UTC
If a file was closed by cache and then bfd_open_file was called followed
by e.g. bfd_seek to the original position, the seek would be optimized out
while the real file position was still zero (as fopened). I added
`bfd_io_force` to force the seek at next IO occasion.
This could led e.g. to appearence of a corrupted object in ld:
symbol number 0 uses unsupported binding of 6
or invalid string offset #X >= #Y for section
To reproduce in a real scenario, both large number of input archives and
certain object layout is needed, so it seemed to be rare. To reproduce
this better, 1) make sure to hit the cache limit (e.g lower it in code)
2) use some plugin (they do bfd_open_file) 3) from main pull in archives
that have symbols like this:
5: 0000000000000000 0 NOTYPE LOCAL DEFAULT 1 C<int>::C()
6: 0000000000000000 0 NOTYPE LOCAL DEFAULT 2 C<float>::C()
7: 0000000000000000 39 FUNC GLOBAL DEFAULT 3 export1()
The last read before cache close will be #6, after re-open it will try
to read export symbols and fail.
Signed-off-by: Roman Kapl <code@rkapl.cz>
---
bfd/cache.c | 1 +
1 file changed, 1 insertion(+)
Comments
On Sat, Nov 29, 2025 at 12:45:27PM +0100, Roman Kapl wrote: > If a file was closed by cache and then bfd_open_file was called followed > by e.g. bfd_seek to the original position, the seek would be optimized out > while the real file position was still zero (as fopened). I added > `bfd_io_force` to force the seek at next IO occasion. > > This could led e.g. to appearence of a corrupted object in ld: > symbol number 0 uses unsupported binding of 6 > or invalid string offset #X >= #Y for section > > To reproduce in a real scenario, both large number of input archives and > certain object layout is needed, so it seemed to be rare. To reproduce > this better, 1) make sure to hit the cache limit (e.g lower it in code) > 2) use some plugin (they do bfd_open_file) 3) from main pull in archives > that have symbols like this: > 5: 0000000000000000 0 NOTYPE LOCAL DEFAULT 1 C<int>::C() > 6: 0000000000000000 0 NOTYPE LOCAL DEFAULT 2 C<float>::C() > 7: 0000000000000000 39 FUNC GLOBAL DEFAULT 3 export1() > > The last read before cache close will be #6, after re-open it will try > to read export symbols and fail. > > Signed-off-by: Roman Kapl <code@rkapl.cz> Thanks! Applied. > --- > bfd/cache.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/bfd/cache.c b/bfd/cache.c > index 3bf9c944..3342e2d5 100644 > --- a/bfd/cache.c > +++ b/bfd/cache.c > @@ -177,6 +177,7 @@ bfd_cache_delete (bfd *abfd) > BFD_ASSERT (open_files > 0); > --open_files; > abfd->flags |= BFD_CLOSED_BY_CACHE; > + abfd->last_io = bfd_io_force; > > return ret; > } > -- > 2.52.0
diff --git a/bfd/cache.c b/bfd/cache.c index 3bf9c944..3342e2d5 100644 --- a/bfd/cache.c +++ b/bfd/cache.c @@ -177,6 +177,7 @@ bfd_cache_delete (bfd *abfd) BFD_ASSERT (open_files > 0); --open_files; abfd->flags |= BFD_CLOSED_BY_CACHE; + abfd->last_io = bfd_io_force; return ret; }