Skip to content
DoS Disclosed report Advanced

[MK8DX] Improper metadata parsing

The game's tournament metadata parser did not validate the length field of each chunk, so an oversized length could overflow a fixed-size temporary buffer with attacker-controlled data and crash the process. Combined with a separate bug that allowed creating official competitions, an attacker could crash any player who opened the Tournament menu.

crazy_man123 Follow

Originally disclosed on HackerOne

Critical 9.3 View original
  • Triaged in 5 days
  • Fixed in 3 months
  • Paid in 3 months
  • Disclosed after 11 months

Summary by the program

Summary by the researcher

Introduction

This vulnerability impacts:

  • Mario Kart 8 Deluxe on the Switch
  • Mario Kart 8 on the WiiU

The vulnerability was fixed for Mario Kart 8 Deluxe the 7 December, 2022 with the release of v2.2 (or v851968 for the internal version) The vulnerability was fixed for Mario Kart 8 the 3 August, 2023 with the release of v4.2 (or v81 for the internal version)


 

The competition/tournaments (SimpleSearchObject) contains a 'metadata' field, it is used by the game to store tournament data such as:

  • Competition name (ID 2)
  • Description (unused but still exists, ID 4)
  • Red/Blue team names (if applicable, ID 7/8 respectively)
  • Icon type (ID 3)
  • etc ...

It's stored with the ChunkData format: (stored in little endian for MK8DX)

ChunkData

Type Description
uint16_t Magic (0x5a5a, 'ZZ' in ASCII)
ChunkDataList[] List of chunk data 'list', goes until end marker
uint8_t End marker ( 0xff)

ChunkDataList

Type Description
uint8_t ID
uint16_t Length
T Any data of size 'length' (previous field)

Then the game would try to extract competition data like this:

C++
void ChunkDataAccessor::reset(uchar* pData, uint dataSize);
bool ChunkDataAccessor::parse();
ChunkDataAccessor::ChunkDataList* ChunkDataAccessor::getDataList(uint id);
void* ChunkDataAccessor::ChunkDataList::getData(uint offset?);

bool CompetitionInfo::extractUniqueAppData_() {
    g_ChunkDataAccessor->reset(this->simpleSearchObject.mMetadata.data(), 0x200);
    g_ChunkDataAccessor->parse();
    // The parsing function verifies the header magic then loops on the structure to extract all ChunkDataList entries, used to not validate the chunk length
   // The chunk length is now limited to 0x400 bytes (even if the maximum size the server/client allows is 0x200 bytes)

    /* ... */
    
    // 2 == Competition name index in the tournament metadata (ChunkData)
    char16_t* compName = (char16_t*)g_ChunkDataAccessor->getDataList(2)->getData(0);
    sead::BufferedSafeStringBase<char16_t> compNameStr(compName);
    this->mCompetitionName = compNameStr; // operator= override, calls sead::BufferedSafeStringBase<T>::copy()

    /* ... */
}

bool ChunkDataAccessor::parse() {
    sead::RamReadStream readStream(this->mBuffer, this->mBufferSize, sead::Stream::Modes::Binary);
    
    // must be a custom type probably
    uint16_t magic;
    readStream.readMemBlock(&magic, sizeof(uint16_t));
    if(magic != 0x5a5a /* gear::ChunkDataAccessor::cStart */) {
        return false;
    }

    uint8_t id;
    uint16_t length;
    readStream.readU8(&id);
    while(id != 0xff) {
        readStream.readU16(&length);
        // Issue, it can overrun the temporary buffer, which is of size 0x400
        // But only with uncontrolled data considering the server enforces a 0x200 bytes limit on the metadata
        // The updated code now checks the length is <= 0x400
        readStream.readMemBlock(this->tmpBuffer, length);
        this->addReadInfo_(id, this->mBuffer + readStream.mOffset, length);
        readStream.readU8(&id);
    }

    return true;
}

The parsing function wasn't validating the chunk size, so a big enough size would overflow some class members (with uncontrolled data) and crash the process


 

Impact

Combined with the bug that allowed to create official competitions, you could crash any players opening the "Tournament" menu

The original report as published on HackerOne, by crazy_man123. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the chunk parser read the length field and copied that many bytes into a fixed 0x400-byte temporary buffer without checking the length against the buffer size or the metadata limit.

Impact

Combined with the bug that allowed creating official competitions, an attacker could crash any player who opened the Tournament menu; the server's 0x200-byte metadata limit meant the overflow data was not fully controlled.

What the attacker needed

Ability to create an official competition; victim opens the Tournament menu

The fix

The parser was changed to check that each chunk length is no larger than 0x400 bytes, and the fix shipped in later game versions.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Tournament data is sent as a list of labelled chunks, each with a length value. The game trusted that length and copied that many bytes into a small fixed buffer, so a huge length spilled past the end of the buffer and crashed the game. A crash like this is called a denial of service: nothing is stolen, but the game stops working for the player.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by crazy_man123

View all

5 more disclosed reports, best first.

More from Nintendo

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.