[PATCH] xcoff: Check loader header size before reading

Alhuda Khan alhuda@research.digiscrypt.com
Sat Nov 21 08:24:28 GMT 2026


When objdump -T reads an XCOFF file, xcoff_get_ldhdr() passes the .loader section contents to bfd_xcoff_swap_ldhdr_in() without checking that the section is at least as large as the loader header. A malformed XCOFF whose .loader section is smaller than the header (for example one byte) therefore causes an out-of-bounds read: bfd_getb32() reads past the one-byte allocation, which AddressSanitizer reports as a heap-buffer-overflow.

Reject the section when it is smaller than bfd_xcoff_ldhdrsz (abfd) before swapping in the header. After the change the malformed file is reported as "file truncated" and a valid XCOFF object still parses correctly.

Signed-off-by: Alhuda Khan <alhuda@research.digiscrypt.com>
---
 bfd/xcofflink.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c
index 2287958304b..9248a5f4966 100644
--- a/bfd/xcofflink.c
+++ b/bfd/xcofflink.c
@@ -253,6 +253,9 @@ xcoff_get_ldhdr (bfd *abfd, asection *lsec, struct internal_ldhdr *ldhdr)
   bfd_byte *contents = xcoff_get_section_contents (abfd, lsec);
   if (contents)
     {
+      if (lsec->size < bfd_xcoff_ldhdrsz (abfd))
+	goto fail;
+
       bfd_xcoff_swap_ldhdr_in (abfd, contents, ldhdr);
       if (ldhdr->l_nsyms != 0)
 	{

---
I am submitting a potential memory-safety issue identified in GNU Binutils during security research.

The issue affects XCOFF loader-header parsing in bfd/xcofflink.c, specifically the xcoff_get_ldhdr() function.

A malformed XCOFF file containing a one-byte .loader section triggers a heap-buffer-overflow when processed using:

objdump -T <malformed-file>

I reproduced the issue using an AddressSanitizer-enabled PowerPC AIX cross-Binutils build.

The root cause was that the loader header was parsed without first checking whether the .loader section was large enough to contain it.

I added a size check using bfd_xcoff_ldhdrsz() before parsing the header. After rebuilding, the malformed input was rejected as truncated without triggering an AddressSanitizer error. A valid XCOFF shared object was also tested successfully.

I have attached the following files:

Patch file (git format-patch)

Malformed reproducer input

Before-patch AddressSanitizer log

After-patch execution log

Tested upstream commit:

0c8e39b6b8b80dddb7d85a5e7cf9d25425799c0b

Patch commit:

2d762b94bbd

The full project test suite and duplicate checks have not yet been completed, so I am not claiming that the issue is a confirmed new vulnerability.

As this may be security-related, please handle the report through the private review channel.

Thank you for reviewing my submission.


More information about the Binutils mailing list