[Nasm-bugs] [Bug 3392371] New: [FreeBSD 11 64bit] -f elf64 incorrect images

no-reply at bugzilla-nasm.gorcunov.org no-reply at bugzilla-nasm.gorcunov.org
Wed Oct 26 22:47:02 PDT 2016


https://bugzilla.nasm.us/show_bug.cgi?id=3392371

            Bug ID: 3392371
           Summary: [FreeBSD 11 64bit] -f elf64 incorrect images
           Product: NASM
           Version: 2.11.xx
          Hardware: PC
                OS: Other
            Status: OPEN
          Severity: severe
          Priority: Medium
         Component: Assembler
          Assignee: nobody at nasm.us
          Reporter: pprocacci at datapipe.com
                CC: gorcunov at gmail.com, hpa at zytor.com, nasm-bugs at nasm.us

Created attachment 411568
  --> https://bugzilla.nasm.us/attachment.cgi?id=411568&action=edit
Test attachment showing problem.

While messing around with nasm on a machine, I encountered an OS error while
attempting to execute the constructed image.
--------------------------------------------
nasm -f elf64 -o test.o test.s
ld -s -o test test.o
./test
elf_load_section: truncated ELF file
Abort
echo $?
134
--------------------------------------------


Using yasm instead works without error as one would expect:
--------------------------------------------
yasm -f elf64 -o test.o test.s
ld -s -o test test.o
./test
test
echo $?
0
--------------------------------------------

The kernel sources for this check is here:

https://github.com/freebsd/freebsd/blob/master/sys/kern/imgact_elf.c

You'll note lines 515-518.

Duplicating comments here for ease:
--------------------------------------------
        /*
         * It's necessary to fail if the filsz + offset taken from the
         * header is greater than the actual file pager object's size.
         * If we were to allow this, then the vm_map_find() below would
         * walk right off the end of the file object and into the ether.
         *
         * While I'm here, might as well check for something else that
         * is invalid: filsz cannot be greater than memsz.
         */
        if ((off_t)filsz + offset > imgp->attr->va_size || filsz > memsz) {
                uprintf("elf_load_section: truncated ELF file\n");
                return (ENOEXEC);
        }
--------------------------------------------

My familiarity with elf is almost non-existent and am therefore unable to point
to the place where nasm is getting it wrong.  Sorry ;(

Attached you'll find my `mess around` code which duplicates the problem.

Please let me know if additional information is needed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are watching all bug changes.


More information about the Nasm-bugs mailing list