Skip to content
Memory corruption Disclosed report Advanced

[WiiU/Switch] Remote code execution inside the ENL library

The ENL networking library used by several Nintendo games did not check that received data fit within its receive buffers, so an oversized message caused a heap overflow. An attacker could overwrite a nearby buffer pointer and redirect a copy to a chosen address, which the author says could lead to remote code execution or denial of service.

crazy_man123 Follow

Originally disclosed on HackerOne

High 7.4 View original
  • Triaged in 14 days
  • Fixed in 22 days
  • Paid in 22 days
  • Disclosed after 16 months

Summary by the program

Summary by the researcher

Introduction

The vulnerability is fixed on all of the impacted games, the last fix was released for Splatoon 1 and Mario Kart 8 on August 3, 2023

Nintendo uses its own private library called ENL, it can do matchmaking using NEX (networking library for Nintendo game servers) and communication between players is done using PIA (UDP peer-to-peer networking library)

This library is used in many Nintendo games including:

  • Mario Kart 8 / Mario Kart 8 Deluxe
  • Splatoon 1 / 2 / 3
  • Animal Crossing: New Horizons
  • Super Mario Maker 2
  • Nintendo Switch Sports

 

How ENL works

  • ENL only sends packet through a Unreliable Protocol (PIA can also do reliable UDP transmission)
  • Games can register "content transporters" to ENL, each content transporter have a unique ID
  • Each content transporter implements its own data format

A packet can contain one or more ENL messages and each message has the following format:

Type Description
uint8 Content transporter ID
uint16 Data length
bytes Data

There's an End marker marking the end of a packet:

Type Description Value
uint8 Content transporter ID 255
uint16 Data length 0

 

The vulnerability

  • All of the data received and sent is handled by the TransportManager (i won't display any reverse engineered pseudo-code because the summary would be too long), but the logic didn't check the data or its size. (But you can expect a link to a more in-depth explanation to be added here in the future)

  • A "buffer" refers to a enl::Buffer, an object with a data pointer, a size and a capacity, the content is changed using enl::Buffer::set(data, size), a simple memcpy() and it updates the "size" field

  • Prior to the fixes, this method did not check the size was less or equal to the capacity.

Here's two of the main issues of the receive logic:

  • The received data could be bigger than the global receive buffer (0x442 bytes)
  • The received data could be bigger than the content transporter receive buffers (2 per player, size defined per content transporter)

In this last case, it triggers an heap overflow (to your assigned enl::Buffer, let's call it PlayerBuffer).

And thankfully the data right after each of the receive buffers is a pointer to a enl::Buffer (let's call it MagicBuffer), so if you could guess the address or overwrite the bottom bytes of this pointer (Switch is Little Endian, and WiiU has no ASLR :P), you could redirect it to controlled data, and craft a enl::Buffer entry.

Additional logic would then trigger a copy of the data from the PlayerBuffer to the MagicBuffer (so, to an address you control), so if for example it's a stack address, you can do ROP, thus making it a Remote Code Execution vulnerability

NOTE: Remote Code Execution was only demonstrated to Nintendo for Mario Kart 8 on the Wii U


 

Impact

  • Remote code execution and/or denial of service, chained with other vulnerabilities, a malicious actor could gain full access to the device

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 buffer setter performed a memcpy without verifying the incoming size against the buffer's capacity, and the receive path never validated message lengths against the global or per-transporter buffers.

Impact

Remote code execution and/or denial of service; chained with other vulnerabilities, an attacker could gain full access to the device, though remote code execution was only demonstrated for Mario Kart 8 on the Wii U.

What the attacker needed

Network access to the game session; ability to send crafted ENL packets; guess or know a target address

The fix

The vulnerability was fixed on all impacted games, with the last fixes released in August 2023.

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.

Games talk to each other over the network by sending small blocks of data into reserved memory areas called buffers. The library never checked that incoming data was small enough for the buffer, so extra data spilled into neighbouring memory. By carefully choosing what spills over, an attacker can change where the game later copies data, which can crash it or let the attacker run their own code.

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 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.

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.