Skip to content

Several reassembly error cases on Ddisasm #54

@witbring

Description

@witbring

When I tested Ddisasm v1.5.3 (docker image digests a803c9, Apr. 2022) for my research, I found several interesting bug cases. 
 
First, I observe that Ddisasm incorrectly symbolize jump table. As an example, given the jump table entry ‘.long .L4895-.L4896’ found in addr2line.tar.gz of Binutils, Ddisasm recognized the value as a jump table entry but the label value is misidentified.

  • Compiler-generated assembly 
.L3326:                       ; this jump table will be placed at 0x131830
    .long	.L3323-.L3326 ; the entry can be represented as .L_103630 - .L_131830
     #...
  • Binary
 131830: 001efdff
  • Reassembler-generated assembly 
.L_131830:
# data_access(4, 4, 1034ee), data_access(4, 4, 10360e), preferred_data_access(131830)
          131830: .long .L_10360c-.L_13180c
# preferred_data_access(131830)
          131834: .long .L_103660-.L_131830

Second, I found that Ddisasm omits some definitions of labels. For example, given the instruction ‘movl $default_quoting_options, %eax’ found in true.tar.gz (x64 non-pie binary) of Coreutils, Ddisasm reassembled the instruction as ‘mov EAX,OFFSET .L_40b2e0’. However, Ddisasm missed the definition of label ‘. L_40b2e0’ so it causes a compilation error.

  • Reassembler-generated assembly 
  402bb5:   mov EAX,OFFSET .L_40b2e0

Third, I observed that Ddisasm makes wrong symbolic expressions so some recompiled binaries refer to incorrect addresses. As an example, given the disassembly code ‘.long .L1543@GOTOFF’ found in nm_new.tar.gz (x86 pie binary) of binutils, Ddisasm symbolized the pointer as ‘.long .L_e4b5-.L_785f1’

  • Compiler-generated assembly
    .long	.L1543@GOTOFF       ; this entry can be represented as .L_95eb8
  • Reassembler-generated assembly
0xc5fe4 : .long .L_e4b5-.L_785f1

Also, I observed that Ddisasm makes some mistakes when it generates got-relative labels. As an example, given the instruction ‘addl $yydefgoto@GOTOFF, %eax’ found in date.tar.gz (x86 pie binary) of coreutils, ddiasm the immediate value as ‘.L_11eca@GOTOFF’. However, the ‘yydefgoto’ is placed at 0x11ee6 not 0x11eca. Also, I calculated the got relative address and concluded that Ddisasm misidentified the label value.

  • Compiler-generated assembly
      addl $yydefgoto@GOTOFF, %eax     
  • Binary (non-stripped version)
$ readelf -s date | grep yydefgoto
   179: 00011ee6    26 OBJECT  LOCAL  DEFAULT   16 yydefgoto

$ objdump -d -M intel date | grep 6395
    6395:    81 c0 e6 be ff ff        add    eax,0xffffbee6

$ readelf -S date | grep got.plt
  [24] .got.plt          PROGBITS        00016000 015000 000128 04  WA  0   0  4

$ python3 -c 'print(hex(0xffffbee6 + 0x0016000 & 0xffffffff))'
0x11ee6
  • Reassembler-generated assembly
          6395:   add EAX,OFFSET .L_11eca@GOTOFF

Lastly, I observed that Ddisasm fails on symbolization when it handles large size binary. For example, Ddisasm fails on symbolizing rip-relative addressing when it reassembled 416.gamess.tar.gz (delete link) of spec cpu 2006. As a result, it causes tremendous false negative errors. 

  • Reassembler-generated assembly
main:
            sub RSP,8
            call FUN_13f0

            lea RSI,QWORD PTR [RIP+6413305]     ; fails on symbolization

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions