bbc / bmx

Library and utilities to read and write broadcasting media files. Primarily supports the MXF file format
BSD 3-Clause "New" or "Revised" License
62 stars 17 forks source link

AddressSanitizer: global-buffer-overflow in updateAAFLocalKey function of MXFDump.cpp #74

Closed 0xd4n10 closed 4 months ago

0xd4n10 commented 4 months ago

Description: I found a global-buffer-overflow when testing the MXFDump binary within bmx, specifically in the updateAAFLocalKey function.

Affected Software:

Software: bmx
Version: 1.2
Operating System: Debian 11
Kernel: Linux debian 5.10.0-28-amd64 #1 SMP Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux

Impact: A global-buffer-overflow vulnerability can lead to application crashes, data corruption, security vulnerabilities, and system instability.

Steps to Reproduce:

Build the affected software (bmx) with AddressSanitizer enabled.
Execute MXFDump with provided poc that triggers the vulnerable code path.
Observe the AddressSanitizer report indicating a global-buffer-overflow error.

Example Output (AddressSanitizer):

[ K = Header ( 0000000000000000 )
06.0e.2b.34.02.05.01.01.0d.01.02.01.01.02.04.00, L =        120 (78), LL = 4 ]
       Major Version = 0001
       Minor Version = 0002
             KAGSize = 00000001
       ThisPartition = 0000000000000000
   PreviousPartition = 0000000000000000
     FooterPartition = 0000000000022198
     HeaderByteCount = 0000000000003f74
      IndexByteCount = 0000000000000000
            IndexSID = 00000000
          BodyOffset = 0000000000000000
             BodySID = 00000000
 Operational Pattern = 06.0e.2b.34.04.01.01.02.0d.01.02.01.10.00.00.00
                     = [ Atom ]
   EssenceContainers = [ count =          2 ]
                   0 = 06.0e.2b.34.04.01.01.03.0d.01.03.01.02.7f.01.00
                     = [ Not recognized ]
                   1 = 06.0e.2b.34.04.01.01.07.0d.01.03.01.02.0b.01.00
                     = [ Not recognized ]

[ K = Primer ( 000000000000008c )
06.0e.2b.34.02.05.01.01.0d.01.02.01.01.05.01.00, L =       1268 (4f4), LL = 4 ]
  [ Number of entries =         70, Entry size        =         18 ]
  Local Tag      UID
  3c.0a     :    06.0e.2b.34.01.01.01.01.01.01.15.02.00.00.00.00
  3b.02     :    06.0e.2b.34.01.01.01.02.07.02.01.10.02.04.00.00
  3b.05     :    06.0e.2b.34.01.01.01.02.03.01.02.01.05.00.00.00
  3b.07     :    06.0e.2b.34.01.01.01.02.03.01.02.01.04.00.00.00
  3b.08     :    06.0e.2b.34.01.01.01.04.06.01.01.04.01.08.00.00
  3b.06     :    06.0e.2b.34.01.01.01.02.06.01.01.04.06.04.00.00
  3b.03     :    06.0e.2b.34.01.01.01.02.06.01.01.04.02.01.00.00
  3b.09     :    06.0e.2b.34.01.01.01.05.01.02.02.03.00.00.00.00
  3b.0a     :    06.0e.2b.34.01.01.01.05.01.02.02.10.02.01.00.00
  3b.0b     :    06.0e.2b.34.01.01.01.05.01.02.02.10.02.02.00.00
  3c.09     :    06.0e.2b.34.01.01.01.02.05.20.07.01.01.00.00.00
  3c.01     :    06.0e.2b.34.01.01.01.02.05.20.07.01.02.01.00.00
  3c.02     :    06.0e.2b.34.01.01.01.02.05.20.07.01.03.01.00.00
  3c.03     :    06.0e.2b.34.01.01.01.02.05.20.07.01.04.00.00.00
  3c.04     :    06.0e.2b.34.01.01.01.02.05.20.07.01.05.01.00.00
  3c.05     :    06.0e.2b.34.01.01.01.02.05.20.07.01.07.00.00.00
  3c.06     :    06.0e.2b.34.01.01.01.02.07.02.01.10.02.03.00.00
  3c.07     :    06.0e.2b.34.01.01.01.02.05.20.07.01.0a.00.00.00
  3c.08     :    06.0e.2b.34.01.01.01.02.05.20.07.01.06.01.00.00
  19.01     :    06.0e.2b.34.01.01.01.02.06.01.01.04.05.01.00.00
  19.02     :    06.0e.2b.34.01.01.01.02.06.01.01.04.05.02.00.00
  27.01     :    06.0e.2b.34.01.01.01.02.06.01.01.06.01.00.00.00
  3f.06     :    06.0e.2b.34.01.01.01.04.01.03.04.05.00.00.00.00
  3f.07     :    06.0e.2b.34.01.01.01.04.01.03.04.04.00.00.00.00
  44.01     :    06.0e.2b.34.01.01.01.01.01.01.15.10.00.00.00.00
  44.02     :    06.0e.2b.34.01.01.01.01.01.03.03.02.01.00.00.00
  44.05     :    06.0e.2b.34.01.01.01.02.07.02.01.10.01.03.00.00
  44.04     :    06.0e.2b.34.01.01.01.02.07.02.01.10.02.05.00.00
  44.03     :    06.0e.2b.34.01.01.01.02.06.01.01.04.06.05.00.00
  48.01     :    06.0e.2b.34.01.01.01.02.01.07.01.01.00.00.00.00
  48.04     :    06.0e.2b.34.01.01.01.02.01.04.01.03.00.00.00.00
  48.02     :    06.0e.2b.34.01.01.01.02.01.07.01.02.01.00.00.00
  48.03     :    06.0e.2b.34.01.01.01.02.06.01.01.04.02.04.00.00
  4b.01     :    06.0e.2b.34.01.01.01.02.05.30.04.05.00.00.00.00
  4b.02     :    06.0e.2b.34.01.01.01.02.07.02.e1.03.01.03.00.00
  02.01     :    06.0e.2b.34.01.01.01.02.04.07.01.00.00.00.00.00
  02.02     :    06.0e.2b.34.01.01.01.02.07.02.02.01.01.03.00.00
  10.01     :    06.0e.2b.34.01.01.01.02.06.01.01.04.06.09.00.00
  15.02     :    06.0e.2b.34.01.01.01.02.04.04.01.01.02.06.00.00
  15.01     :    06.0e.2b.34.01.01.01.02.07.02.01.03.01.05.00.00
  15.03     :    06.0e.2b.34.01.01.01.01.04.04.01.01.05.00.00.00
  06.01     :    06.0e.2b.34.01.01.01.02.07.02.01.03.03.03.00.00
  61.01     :    06.0e.2b.34.01.01.01.05.06.01.01.04.02.0c.00.00
  47.01     :    06.0e.2b.34.01.01.01.02.06.01.01.04.02.03.00.00
  06.01     :    ea.0e.2b.34.01.01.01.02.05.30.04.04.01.00.00.00
  ff.ff     :    06.0e.2b.34.01.01.01.09.06.01.01.04.02.0d.00.00
MXFDump : Warning : Cannot remap static local key as specified by Primer Pack (property "EditUnitByteCount" has local key 3f05 in the MXF dictionary and 0000 in the Primer)
=================================================================
==1180388==ERROR: AddressSanitizer: global-buffer-overflow on address 0x56355f6e5fe8 at pc 0x56355f6b49be bp 0x7ffeeba4f940 sp 0x7ffeeba4f938
READ of size 2 at 0x56355f6e5fe8 thread T0
    #0 0x56355f6b49bd in updateAAFLocalKey /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:3320
    #1 0x56355f6b49bd in printPrimer /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:6389
    #2 0x56355f6b49bd in mxfDumpKLV /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:6663
    #3 0x56355f68dd19 in mxfDumpKLV /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:3577
    #4 0x56355f68dd19 in mxfDumpFile /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:6746
    #5 0x56355f68dd19 in main /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:7550
    #6 0x7f48e01a6d09 in __libc_start_main ../csu/libc-start.c:308
    #7 0x56355f69a199 in _start (/mnt/fast/DCP/bmx/out/build-asan/_deps/libmxf-build/tools/MXFDump/MXFDump+0x2f199)

Address 0x56355f6e5fe8 is a wild pointer.
SUMMARY: AddressSanitizer: global-buffer-overflow /mnt/fast/DCP/bmx/deps/libMXF/tools/MXFDump/MXFDump.cpp:3320 in updateAAFLocalKey
Shadow bytes around the buggy address:
  0x0ac72bed4ba0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac72bed4bb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac72bed4bc0: 00 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9
  0x0ac72bed4bd0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ac72bed4be0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
=>0x0ac72bed4bf0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9[f9]f9 f9
  0x0ac72bed4c00: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ac72bed4c10: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ac72bed4c20: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ac72bed4c30: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ac72bed4c40: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
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
==1180388==ABORTING

POC: bmx-poc.zip

Disclosure Timeline:

Date of Discovery: 27/05/2024
Date Reported to Vendor: 27/05/2024

Acknowledgments: This vulnerability was discovered and reported by 0xd4n.

philipnbbc commented 4 months ago

Thanks for the report. I have a fix for it in #76 but I didn't manage to replicate your global-buffer-overflow error; I only get a segmentation fault error (SEGV on unknown address). Did you use a different set of compiler options than what I did?

0xd4n10 commented 4 months ago

Thanks for the quick response. The global-buffer-overflow occurs when any optimization flag other than the default (-O0) is used.

philipnbbc commented 4 months ago

The global-buffer-overflow occurs when any optimization flag other than the default (-O0) is used.

Confirmed - changed Debug to Release (-O3) and that showed the buffer overflow error.