bugPSPP - Bugs: bug #58595, Use after free in fh_get_referent

 
 

bug #58595: Use after free in fh_get_referent

Submitter:  Andrea Fioraldi <andreafioraldi>
Submitted:  Wed 17 Jun 2020 08:17:22 AM UTC
   
 
Category:  Syntax Parser Severity:  5 - Average
Status:  Fixed Assigned to:  None
Open/Closed:  Closed Release:  None
Effort:  0.00
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 20 Jun 2020 05:37:44 AM UTC, comment #7: 

I believe this bug has been fixed in commit 4e92ae17ea68adfe8d703b740e20c7f368138fb

John Darrington <jmd>
Group administrator
Thu 18 Jun 2020 08:31:23 AM UTC, comment #6: 

With fuzzing. I'm a maintainer of AFL++ (https://aflplus.plus/) and I'm fuzzing random OSS projects this week.
If you are interested in continuous fuzzing, ping the Google OSS-Fuzz crew (feel free to use my name as reference), they will fuzz for you on Google servers for free.

Andrea Fioraldi <andreafioraldi>
Wed 17 Jun 2020 01:44:39 PM UTC, comment #5: 

Hey Andrea, thank you very much for your torture of  pspp! How do you do this?

Friedrich

Friedrich Beckmann <beckmanf>
Group Member
Wed 17 Jun 2020 10:28:55 AM UTC, comment #4: 

Thanks! I just did not compile with -fsanitize=address. Now I see


uaf2:48: Fehler: Unbekannter Befehl `ATfKATA'.
=================================================================
==72749==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000003138 at pc 0x0001047cc50c bp 0x7ffeebc46410 sp 0x7ffeebc46408
READ of size 4 at 0x60b000003138 thread T0
    #0 0x1047cc50b in fh_get_referent file-handle-def.c:323
    #1 0x1047cd46e in make_key file-handle-def.c:629
    #2 0x1047ce714 in fh_is_locked file-handle-def.c:604
    #3 0x10414fb4e in cmd_begin_data data-reader.c:731
    #4 0x103fd05ed in do_parse_command command.c:233
    #5 0x103fcff9f in cmd_parse_in_state command.c:147
    #6 0x103fd081d in cmd_parse command.c:162
    #7 0x103fbb4dd in main main.c:136
    #8 0x7fff587a9014 in start (libdyld.dylib:x86_64+0x1014)

0x60b000003138 is located 40 bytes inside of 104-byte region [0x60b000003110,0x60b000003178)
freed by thread T0 here:
    #0 0x1053f010d in wrap_free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x5710d)
    #1 0x1047cbaf9 in free_handle file-handle-def.c:134
    #2 0x1047cb939 in fh_unref file-handle-def.c:170
    #3 0x10414dbe1 in dfm_close_reader data-reader.c:110
    #4 0x10414fc96 in cmd_begin_data data-reader.c:747
    #5 0x103fd05ed in do_parse_command command.c:233
    #6 0x103fcff9f in cmd_parse_in_state command.c:147
    #7 0x103fd081d in cmd_parse command.c:162
    #8 0x103fbb4dd in main main.c:136
    #9 0x7fff587a9014 in start (libdyld.dylib:x86_64+0x1014)

previously allocated by thread T0 here:
    #0 0x1053f0497 in wrap_calloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x57497)
    #1 0x104950298 in xcalloc xmalloc.c:112
    #2 0x10495024b in xzalloc xmalloc.c:97
    #3 0x1047cb1c9 in create_handle file-handle-def.c:215
    #4 0x1047cb10e in fh_init file-handle-def.c:103
    #5 0x103fbb02b in main main.c:92
    #6 0x7fff587a9014 in start (libdyld.dylib:x86_64+0x1014)

SUMMARY: AddressSanitizer: heap-use-after-free file-handle-def.c:323 in fh_get_referent
Shadow bytes around the buggy address:
  0x1c16000005d0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
  0x1c16000005e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
  0x1c16000005f0: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
  0x1c1600000600: fd fd fd fd fa fa fa fa fa fa fa fa 00 00 00 00
  0x1c1600000610: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa
=>0x1c1600000620: fa fa fd fd fd fd fd[fd]fd fd fd fd fd fd fd fa
  0x1c1600000630: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x1c1600000640: 00 00 00 00 00 fa fa fa fa fa fa fa fa fa 00 00
  0x1c1600000650: 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fa
  0x1c1600000660: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c1600000670: 00 fa fa fa fa fa fa fa fa fa fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==72749==ABORTING
******************************************************
You have discovered a bug in PSPP.  Please report this
to bug-gnu-pspp@gnu.org.  Please include this entire
message, *plus* several lines of output just above it.
For the best chance at having the bug fixed, also
include the syntax file that triggered it and a sample
of any data file used for input.
proximate cause:     Assertion Failure/Abort
version:             GNU pspp 1.3.0
host_system:         x86_64-apple-darwin17.7.0
build_system:        x86_64-apple-darwin17.7.0
locale_dir:          /Users/fritz/pspp/osxbundler/install/share/locale
compiler version:    4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)
******************************************************
Abort trap: 6
Fredo:Downloads fritz$


Friedrich Beckmann <beckmanf>
Group Member
Wed 17 Jun 2020 09:07:38 AM UTC, comment #3: 

Usually, ASan is more powerful than Valgrind, but for UAF bugs they should be the same. Maybe just try Valgrind.

Andrea Fioraldi <andreafioraldi>
Wed 17 Jun 2020 09:06:10 AM UTC, comment #2: 

This is strange, I can trigger the bug with ./pspp -O format=txt -o /dev/null -b uaf2

I double checked that the uploaded file is correct, it is.
The SHA1 of uaf2 is 84eeb2a75ba4c49c74225cf999a16c7f8192261b.

I'm at commit 53d339111a9f51561cfccc65764874cdf54e501a.

Are you sure that are you using AddressSanitizer?

If you are using GCC maybe the sanitizer is behind the implementation in LLVM and has more false negatives.

Try to update GCC or use Clang (you need to manually edit math.h and remove __builtin_isnan* uses).

Andrea Fioraldi <andreafioraldi>
Wed 17 Jun 2020 08:24:10 AM UTC, comment #1: 

Hi Andrea,

for the stupid: How can I reproduce the problem? I run pspp like this:


Fredo:Downloads fritz$ pspp -O format=txt -o /dev/null -b uaf2
uaf2:1: Fehler: Unbekannter Befehl `dnl'.

uaf2:2: Fehler: Unbekannter Befehl `dnl'.

uaf2:2.40: Fehler: Syntax Fehler bei `': Ungültiges Zeichen U+007F in der Eingabe.

uaf2:3: Fehler: Unbekannter Befehl `dnl'.

uaf2:4: Fehler: Unbekannter Befehl `dnl'.

uaf2:4.34: Fehler: Syntax Fehler bei `:': Ungültiges Zeichen `:' in der Eingabe.

uaf2:5: Fehler: Unbekannter Befehl `dnl'.

uaf2:6: Fehler: Unbekannter Befehl `dnl'.

uaf2:7: Fehler: Unbekannter Befehl `ion'.

uaf2:8: Fehler: Unbekannter Befehl `dnl'.

uaf2:9: Fehler: Unbekannter Befehl `dnl'.

uaf2:10: Fehler: Unbekannter Befehl `dnl'.

uaf2:11: Fehler: Unbekannter Befehl `dnl'.

uaf2:12: Fehler: Unbekannter Befehl `dnl'.

uaf2:12.29: Fehler: Syntax Fehler bei `;': Ungültiges Zeichen `;' in der Eingabe.

uaf2:13: Fehler: Unbekannter Befehl `dnl'.

uaf2:14: Fehler: Unbekannter Befehl `ic'.

uaf2:15: Fehler: Unbekannter Befehl `dnl'.

uaf2:16: Fehler: Unbekannter Befehl `dnl'.

uaf2:16.43: Fehler: Syntax Fehler bei `': Ungültiges Zeichen U+0019 in der Eingabe.

uaf2:17: Fehler: Unbekannter Befehl `dnl'.

uaf2:17.48: Fehler: Syntax Fehler bei `:': Ungültiges Zeichen `:' in der Eingabe.

uaf2:17.61: Fehler: Syntax Fehler bei `': Ungültiges Zeichen U+0003 in der Eingabe.

uaf2:17.61: Fehler: Syntax Fehler bei `...': Ungültiges Zeichen U+0000 in der Eingabe.

uaf2:17.61: Fehler: Syntax Fehler bei `...': Ungültiges Zeichen U+0000 in der Eingabe.

uaf2:18: Fehler: Unbekannter Befehl `dnl'.

uaf2:19: Fehler: Unbekannter Befehl `AT_BANNER'.

uaf2:21: Fehler: Unbekannter Befehl `dnl'.

uaf2:21.15: Fehler: Syntax Fehler bei `{': Ungültiges Zeichen `{' in der Eingabe.

uaf2:22: Fehler: Unbekannter Befehl `dnl'.

uaf2:23: Fehler: Unbekannter Befehl `dnl'.

uaf2:25: Fehler: Unbekannter Befehl `AT_SETUP'.

uaf2:25.20: Fehler: Syntax Fehler bei `': Ungültiges Zeichen U+007F in der Eingabe.

uaf2:25.20: Fehler: Syntax Fehler bei `...': Ungültiges Zeichen U+0000 in der Eingabe.

uaf2:26: Fehler: Unbekannter Befehl `AT_DATA'.

uaf2:27.8: Fehler: GET DATA: Syntax Fehler bei `�': Ungültiges Zeichen U+FFFD in der Eingabe.

uaf2:30.9-30.12: Warnung: Die Daten für die Variable D sind im Format F ungültig: Zahl gefolgt von Müll.

uaf2:31: Warnung: Fehlender Wert oder Werte für alle Variablen ab C.  Diese werden mit system-fehlenden Werten oder Leerzeichen
aufgefüllt, je nachdem was jeweils angebracht erscheint.

         Data List
╭────┬───────┬─────┬─────╮
│  A │   B   │  C  │  D  │
├────┼───────┼─────┼─────┤
│1,00│  23,00│45,00│    .│
│2,00│2223,00│    .│    .│
│3,00│  34,00│34,00│34,00│
╰────┴───────┴─────┴─────╯

uaf2:36.1: Fehler: Syntax Fehler bei `]': erwarte den Namen eines Befehls.

uaf2:37: Fehler: Unbekannter Befehl `AT_CHECK'.

uaf2:38: Fehler: Unbekannter Befehl `AT_CHECK'.

uaf2:38.20: Fehler: Syntax Fehler bei `...': Ungültiges Zeichen U+0000 in der Eingabe.

uaf2:38.20: Fehler: Syntax Fehler bei `...': Ungültiges Zeichen U+0000 in der Eingabe.

uaf2:38.20: Fehler: Syntax Fehler bei `...': Ungültiges Zeichen U+0000 in der Eingabe.

uaf2:39: Fehler: Unbekannter Befehl `Tas'.

uaf2:39.4: Fehler: Syntax Fehler bei `': Ungültiges Zeichen U+0010 in der Eingabe.

uaf2:39.5: Fehler: Syntax Fehler bei `:': Ungültiges Zeichen `:' in der Eingabe.

uaf2:40: Fehler: Unbekannter Befehl `A'.

uaf2:41: Fehler: Unbekannter Befehl `1'.

uaf2:42: Fehler: Unbekannter Befehl `2'.

uaf2:43: Fehler: Unbekannter Befehl `3'.

uaf2:44.1: Fehler: Syntax Fehler bei `]': erwarte den Namen eines Befehls.

uaf2:45: Fehler: Unbekannter Befehl `AT_CLEANUP'.

uaf2:47: Fehler: Unbekannter Befehl `AT_SETUP'.

uaf2:48: Fehler: Unbekannter Befehl `ATfKATA'.

uaf2:50: Fehler: BEGIN DATA: Dieser Befehl ist hier nicht gültig, da das aktuelle Eingabeprogramm keinen Zugriff auf die Inline-Datei
hat.

uaf2:51: Fehler: Die Ausführung der Syntaxdatei wird hier abgebrochen, um zu verhindern, dass eine Kaskade von fehlgeschlagenen
Befehlen entsteht.
Fredo:Downloads fritz$


But this seems to be o.k. ?


Friedrich Beckmann <beckmanf>
Group Member
Wed 17 Jun 2020 08:17:22 AM UTC, original submission:  

This UAF seems a more severe bug than the ones that I previously reported.

./pspp -O format=txt -o /dev/null -b uaf2


=================================================================
==118050==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000000c18 at pc 0x0000009fe5e3 bp 0x7fffffffdcb0 sp 0x7fffffffdca8
READ of size 4 at 0x60b000000c18 thread T0
    #0 0x9fe5e2 in fh_get_referent /home/andreaf/real/pspp/src/data/file-handle-def.c:323:18
    #1 0x9fe5e2 in make_key /home/andreaf/real/pspp/src/data/file-handle-def.c:629:20
    #2 0x9ff137 in fh_is_locked /home/andreaf/real/pspp/src/data/file-handle-def.c:604:3
    #3 0x545b18 in cmd_begin_data /home/andreaf/real/pspp/src/language/data-io/data-reader.c:731:8
    #4 0x4d048b in do_parse_command /home/andreaf/real/pspp/src/language/command.c:233:16
    #5 0x4d048b in cmd_parse_in_state /home/andreaf/real/pspp/src/language/command.c:148:12
    #6 0x4c9df6 in main /home/andreaf/real/pspp/src/ui/terminal/main.c:138:20
    #7 0x7ffff61a5b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #8 0x421499 in _start (/home/andreaf/real/pspp/pspp_afl+0x421499)

0x60b000000c18 is located 40 bytes inside of 104-byte region [0x60b000000bf0,0x60b000000c58)
freed by thread T0 here:
    #0 0x49995d in free (/home/andreaf/real/pspp/pspp_afl+0x49995d)
    #1 0x9f88e5 in free_handle /home/andreaf/real/pspp/src/data/file-handle-def.c:134:3
    #2 0x9f88e5 in fh_unref /home/andreaf/real/pspp/src/data/file-handle-def.c:170:9

previously allocated by thread T0 here:
    #0 0x499bdd in malloc (/home/andreaf/real/pspp/pspp_afl+0x499bdd)
    #1 0xc8427b in xmalloc /home/andreaf/real/pspp/gl/xmalloc.c:41:13
    #2 0xc8427b in xzalloc /home/andreaf/real/pspp/gl/xmalloc.c:86:18
    #3 0x7ffff61a5b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: heap-use-after-free /home/andreaf/real/pspp/src/data/file-handle-def.c:323:18 in fh_get_referent
Shadow bytes around the buggy address:
  0x0c167fff8130: 00 00 00 fa fa fa fa fa fa fa fa fa 00 00 00 00
  0x0c167fff8140: 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa
  0x0c167fff8150: fa fa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c167fff8160: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c167fff8170: 00 00 00 00 00 fa fa fa fa fa fa fa fa fa fd fd
=>0x0c167fff8180: fd fd fd[fd]fd fd fd fd fd fd fd fa fa fa fa fa
  0x0c167fff8190: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c167fff81a0: 00 fa fa fa fa fa fa fa fa fa 00 00 00 00 00 00
  0x0c167fff81b0: 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa
  0x0c167fff81c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa
  0x0c167fff81d0: fa fa fa fa fa fa 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==118050==ABORTING


Andrea Fioraldi <andreafioraldi>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #49289:  uaf2 added by andreafioraldi (4KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jmd (Posted a comment)
  • -email is unavailable- added by beckmanf (Posted a comment)
  • -email is unavailable- added by andreafioraldi (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-06-20 jmd StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2020-06-17 beckmanf StatusNone Confirmed
    2020-06-17 andreafioraldi Attached File- Added uaf2, #49289

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code