Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap buffer overflow (read) while loading map in CMapLayers::LoadEnvPoints, maplayers.cpp:164 #2975

Open
mmmds opened this issue Oct 23, 2021 · 0 comments · May be fixed by #2931
Open

Heap buffer overflow (read) while loading map in CMapLayers::LoadEnvPoints, maplayers.cpp:164 #2975

mmmds opened this issue Oct 23, 2021 · 0 comments · May be fixed by #2931

Comments

@mmmds
Copy link

mmmds commented Oct 23, 2021

The client crashes when an invalid map (8.map.zip) is loaded. Such a map can be delivered to the client by a malicious server.

Tested on Ubuntu 20.04 x86_64, Teeworlds version: f35da54b6f2c5f9fd4bbd4559f887ccf8f8cc526

Compilation with ASAN:

export CXXFLAGS="-ggdb -O0 -fsanitize=address -fno-omit-frame-pointer"
export CFLAGS="-ggdb -O0 -fsanitize=address -fno-omit-frame-pointer"
cmake ..
make

Run and connect to a server that delivers an invalid map:

./teeworlds "connect 127.0.0.1" "gfx_fullscreen 0" "gfx_screen_height 240" "gfx_screen_width 360"
[...]
=================================================================
==33556==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61f0000df180 at pc 0x5555556faf77 bp 0x7ffffffd8e10 sp 0x7ffffffd8e00
READ of size 88 at 0x61f0000df180 thread T0
    #0 0x5555556faf76 in array<CEnvPoint, allocator_default<CEnvPoint> >::add(CEnvPoint const&) /home/osboxes/teeworlds/teeworlds-asan/src/base/tl/array.h:171
    #1 0x5555556faf76 in CMapLayers::LoadEnvPoints(CLayers const*, array<CEnvPoint, allocator_default<CEnvPoint> >&) /home/osboxes/teeworlds/teeworlds-asan/src/game/client/components/maplayers.cpp:164
    #2 0x5555556fcf3b in CMapLayers::OnMapLoad() /home/osboxes/teeworlds/teeworlds-asan/src/game/client/components/maplayers.cpp:117
    #3 0x555555839981 in CGameClient::OnConnected() /home/osboxes/teeworlds/teeworlds-asan/src/game/client/gameclient.cpp:459
    #4 0x5555555f6755 in CClient::ProcessServerPacket(CNetChunk*) /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:1283
    #5 0x5555555f91ce in CClient::PumpNetwork() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:1596
    #6 0x5555555f9596 in CClient::Update() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:1766
    #7 0x5555555fc1f0 in CClient::Run() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:2108
    #8 0x5555555d24e5 in main /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:2704
    #9 0x7ffff68e10b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #10 0x5555555dc48d in _start (/home/osboxes/teeworlds/teeworlds-asan/build/teeworlds+0x8848d)

0x61f0000df180 is located 0 bytes to the right of 3328-byte region [0x61f0000de480,0x61f0000df180)
allocated by thread T0 here:
    #0 0x7ffff768ebc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x55555597188f in CDataFileReader::Open(IStorage*, char const*, int) /home/osboxes/teeworlds/teeworlds-asan/src/engine/shared/datafile.cpp:151
    #2 0x555555995754 in CMap::Load(char const*, IStorage*) /home/osboxes/teeworlds/teeworlds-asan/src/engine/shared/map.cpp:34
    #3 0x5555555f0c15 in CClient::LoadMap(char const*, char const*, SHA256_DIGEST const*, unsigned int) /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:807
    #4 0x5555555f7c58 in CClient::ProcessServerPacket(CNetChunk*) /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:1251
    #5 0x5555555f91ce in CClient::PumpNetwork() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:1596
    #6 0x5555555f9596 in CClient::Update() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:1766
    #7 0x5555555fc1f0 in CClient::Run() /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:2108
    #8 0x5555555d24e5 in main /home/osboxes/teeworlds/teeworlds-asan/src/engine/client/client.cpp:2704
    #9 0x7ffff68e10b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/osboxes/teeworlds/teeworlds-asan/src/base/tl/array.h:171 in array<CEnvPoint, allocator_default<CEnvPoint> >::add(CEnvPoint const&)
Shadow bytes around the buggy address:
  0x0c3e80013de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3e80013df0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3e80013e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3e80013e10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3e80013e20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c3e80013e30:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3e80013e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3e80013e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3e80013e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3e80013e70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3e80013e80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
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
==33556==ABORTING

Compilation without ASAN:

export CXXFLAGS="-ggdb -O0"
export CFLAGS="-ggdb -O0"
cmake ..
make

Run and connect to a server that delivers an invalid map:

./teeworlds "connect 127.0.0.1" "gfx_fullscreen 0" "gfx_screen_height 240" "gfx_screen_width 360"
[...]
Segmentation fault (core dumped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants