Skip to content
Memory corruption Disclosed report Advanced

[Switch, PIA/MK8DX] Stack buffer overflow and potential RCE in PIA (LAN/LDN, possibly NEX) room info deserialization

jitlua Follow

Originally disclosed on HackerOne

Medium 4.3 View original
  • Triaged in 13 days
  • Fixed in 2 months
  • Paid in 56 days
  • Disclosed after 2 months

Summary by the program

Summary by the researcher

Background Information

A vulnerability was discovered in Mario Kart 8 Deluxe's incorrect usage of the Pia P2P networking library, in which implementations of "CopyAppData" (See pseudocode below) are sometimes called with an outBufSize larger than the out buffer itself. This can potentially lead to user-mode remote code execution (RCE) on peers' consoles if chained with an info leak.

As of 2024/09/11, Nintendo has deployed a fix for this vulnerability alongside v3.0.3 for all regions, excluding China. As of 2024/09/27, v3.0.3 has now also been released for China.

A complete write-up is included here: https://github.com/latte-soft/kartlanpwn

Report Timeline

Date Info
2024/07/18 Report submitted to Nintendo via HackerOne
2024/07/31 Report triaged internally
2024/09/11 Fix released alongside Mario Kart 8 Deluxe v3.0.3 for all regions, excluding China
2024/09/12 Bounty paid out by Nintendo
2024/09/12 Other researchers quite quickly found out about the fix for "a security flaw in the game's netcode" in the bindiff for v3.0.3
2024/09/27 Mario Kart 8 Deluxe v3.0.3 released for the Chinese region
2024/09/29 Disclosure granted by Nintendo

LAN Protocol (Browse-Reply Packet)

At least in the case of the Pia version MK8DX is using, for what we're focusing on, browse-reply packets for LAN are constructed as follows:

(All int types are encoded as big-endian)

Index Pseudo-Type Description
0 u8 Packet type (0x1)
1 u32 Size of session info body (1266 in our case)
5 (42 bytes) Misc session info fields, irrelevant to us
47 (0x180 bytes) Start of space for application data
431 u32 Length of application data

The rest of session info follows, though unimportant for crafting a packet for this vulnerability

"LAN_CopyAppData" Pseudocode

For the sake of demonstration, below is rough pseudocode from the LAN implementation of "CopyAppData". While nothing is inherently wrong with this function alone, incorrect usage (in MK8DX's case) can allow for the stack frame to be overwritten by our input application data in packet.

(function located @ +0xA0F8C0 in main for MK8DX v3.0.1)

C
void LAN_CopyAppData(int* r0, int packet, int out, uint outBufSize) {
    int u1 = 68612;

    if (out != NULL) {
        // The actual length to read from the `packet` buffer at the start of our
        // application data (which our 'server' controls)
        uint appDataLength = *(uint *)(packet + 432);

        // In some cases, outBufSize is input as a larger number than the bounds of the
        // `out` buffer, which allows a stack buffer overflow (in our specific case, `*out`
        // is 128 bytes long, and outBufSize is 150!)
        if (appDataLength <= outBufSize) {
            memcpy(out, packet + 48, outBufSize); // packet[47], start of application data

            u1 = 0;
        }

        *r0 = u1;
        return;
    }

    *r0 = 68615;
    return;
}

The original report as published on HackerOne, by jitlua. 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.

What is known

A medium-severity memory corruption bug in Nintendo Switch applications for which Nintendo is the publisher worldwide, rated CVSS 4.3. HackerOne made it public on 30 September 2024.

About Memory corruption

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

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

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Nintendo

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.