A few years ago, CUB3D demonstrated unsigned code execution on the iPod nano 6G and 7G through ipod_sun, a font-based exploit. Whether the same approach would work on the 5G was still an open question.
I wanted to get Rockbox running on the nano 5G, so I set out to adapt the exploit. My motivation was simple: an up-to-date music player without an internet connection. I built a fully untethered boot chain that loads Rockbox from the nano 5G’s own storage, with no computer or button sequence after installation. I also found a way to make the existing exploit fully untethered on the nano 7G, and likely the 6G too.
Existing DFU exploits, including q3k’s wInd3x, provide code execution on the nano 5G, but booting custom code this way requires a computer each time. I used wInd3x to explore the device and develop a convenient, fully untethered exploit. The firmware details below refer to nano 5G firmware 1.0.2 (34A20020).
The catch with ipod_sun
The nano 5G’s NAND flash appears through a flash translation layer (FTL) as a logical disk with 4 KiB sectors. Its partition table separates a small private area for persistent device state, a firmware partition containing boot programs and resources, and a data volume for user files. The firmware partition has a directory of named images; the fonts live inside rsrc, a resource volume formatted as FAT16.
The original ipod_sun chain combines a resource-validation bypass with a font-parser vulnerability. Apple’s firmware directory identifies the normal operating system as osos, the disk-mode program as disk, and the resource image containing fonts as rsrc. The disk-mode boot path does not request the resource signature check used by normal OS boot.
Swapping the disk and osos directory entries exploits that difference: selecting disk mode now launches Apple’s regular OS under the disk-mode policy. The OS still reads its fonts, but the bootloader has not required a valid signature for the modified resource image.
// Resource-validation decision only; other image checks are omitted.
if (selected_target == OSOS) {
status = check_resource_policy(rsrc);
if (failed(status))
return status;
}
// The DISK path does not request this rsrc check.
return boot_image(firmware_directory[selected_target]);
// With swapped entries, the DISK entry points to Apple's normal OS.The font then triggers CVE-2010-1797, the FreeType CFF stack-overflow vulnerability also known through the star exploit. A malformed font program corrupts the parser’s stack and redirects execution. My 5G port adapts that technique to the device’s font and execution context.
The swapped images remain on disk, but each restart still requires choosing disk mode with the device’s buttons. A normal boot selects the other entry. I wanted a better experience, with the modified font loading through the normal OS path.
Finding a bypass in the normal boot path
The bootloader is organized into EFI-style modules stored as Portable Executable (PE) images. The module that passes execution to the next boot stage decides whether to validate rsrc. It first asks the PrivateData module for FirmwareStatus, which comes from an authenticated record in the private NAND partition.
The decisive branch is below. This is reconstructed C from the reverse-engineered routine, with unrelated fuse handling and protocol setup omitted.
status = private_data->get_variable(
private_data, U16("FirmwareStatus"), &word);
if (status != 0)
return status;
if (word & 0x1)
return UINT32_C(0x8000000a); // Reject the boot attempt.
if (word & 0x2)
return 0; // Skip rsrc signature validation.
uint32_t size = sizeof(validation);
// Check the rsrc signature and reject an invalid result.
status = resource->get_info(
resource, BDS_GUID(BDS_VALIDATION), &size, validation);
if (!BDS_ERROR(status) && validation[0] == 0)
return UINT32_C(0x8000001a);
return status;A value of 2 returns success before the resource-validation query. Bit 0 must remain clear: it is checked first, so 3 would reject the boot attempt. Tracing the restore OS shows that it sets the status to 1 during firmware transfer and clears it to 0 at the end. This suggests an update-in-progress guard that prevents booting an incomplete installation.
This is the second bypass. Instead of disguising the normal OS as disk mode, I can leave the firmware directory alone and supply a valid private record with bit 1 set. The normal boot path then accepts the modified resource image, and its font delivers code execution automatically.
The record lives in the private partition, identified by MBR type 0x3e. On the 5G layout I examined, the partition begins at logical block 1, with 4 KiB blocks. The bootloader reads a 512-byte header from its start. The status-bearing format begins with the little-endian magic PRVD and has this layout:
| Offset | Value or purpose |
|---|---|
0x00 | 0x44565250 — PRVD |
0x04–0x0c | Three 32-bit words: 2, 0, 4 |
0x40 | 32-bit FirmwareStatus; use 2 |
0x80 | 16-byte device-bound integrity tag |
The integrity tag is device-specific, so creating and saving a valid PRVD record requires code execution on that iPod.
*firmware_status = 0;
read_private_header(header); // Read-error handling omitted here.
if (is_plain_header(header))
return PD_SUCCESS;
if (!is_prvd_v2(header))
return PD_UNSUPPORTED;
// SHA-1 covers the first 0x80 bytes, including FirmwareStatus.
sha1(header, 0x80, digest);
aes_encrypt_uid(digest, 16, expected_tag);
if (!equal16(header + 0x80, expected_tag))
return PD_SECURITY_VIOLATION;
*firmware_status = read_u32_le(header + 0x40);
return PD_SUCCESS;The tag is the first 16 bytes of the SHA-1 digest, encrypted with the device’s hardware AES UID key, selected through key slot 2. It authenticates the private header, including its status, but not the contents of rsrc. The modified font can therefore still load.
Apple’s own resource-mount path also writes status 2. My hypothesis is that this avoids repeating signature verification to shorten boot time or reduce energy use.
Using emCORE to make it persistent
To inspect and update the private partition, I adapted emCORE, an older framework from freemyipod’s earlier iPod exploitation and boot work. It provided an existing USB-controlled environment to extend for the 5G.
I wrote the nano 5G NAND driver and integrated it into emCORE alongside the flash translation layer (FTL) and hardware AES access. I’ll cover the flash memory sequencer subsystem (FMSS), which enables NAND writes, in a future post. The FTL presents logical sectors over physical flash; it is the layer through which I read and write the private record and install the modified font.
The private-status tool verifies the existing header and tag, constructs the updated record, and obtains its new tag from the device. It rechecks the partition table and header before writing, then flushes the write and reads it back. The tool writes a complete 4 KiB logical sector even though the bootloader only consumes the smaller header. I tested this work on nano 5G hardware.
Once the private record and modified font are installed, they remain in NAND across restarts. emCORE and the host computer are needed for the installation workflow, not for each subsequent boot.
A bootloader in less than 28 KB
Reaching the font parser automatically solved persistence. The next constraint was fitting something useful inside the font. I wanted it to load Rockbox from storage, so the payload needed a NAND driver, a flash translation layer, a filesystem reader, and enough startup code to hand off reliably.
The font slot is 165,416 bytes, but most of that space is not available for machine code. The font container uses 78,312 bytes, the exploit has fixed encoding overhead, and each payload byte costs three bytes in the font’s Type 2 program. The documented main-payload ceiling is 27,874 bytes.
| Component | Size |
|---|---|
| Combined cleanup stub + bootloader budget | 28,682 bytes |
| Cleanup stub — prepares the environment and passes execution to the bootloader | 808 bytes |
| Space left for the bootloader | 27,874 bytes |
The combined code budget is the 808-byte cleanup stub plus the 27,874-byte main-payload allowance; the font container and encoding overhead are accounted for separately. To keep the bootloader within that allowance, I built only the read paths of the storage and filesystem code, maximally optimized the compiled code, and made a few other technical changes to reduce its footprint. The Rockbox kernel is stored on the device’s FAT32 partition and can be easily updated.
Taking control from the font parser
Code execution initially arrives in a damaged FreeType call frame. The stack has been corrupted, and Apple’s OS has left interrupts, DMA controllers, timers, caches, and address translation configured for its own use. Jumping straight into a large C program would carry that state into storage initialization.
I split the bootstrap into two images. The first is the 808-byte assembly stub at 0x22050000. Its job is to leave the parser context: mask IRQs and FIQs, switch to a private stack, stop inherited timer activity, quiesce DMA and clock domains, and clean up caches and the MMU before entering the main payload. It replaces the damaged stack and then jumps to the Rockbox kernel loader.
The second image is the main loader at 0x22060000. Its entry code disables the watchdog before starting the NAND scan, installs its own stack, and clears the uninitialized-data area before calling C. The watchdog matters because reconstructing the logical flash mapping can take several seconds; a reset in the middle would stop the boot before it ever found Rockbox.
This separation keeps the most fragile stage small. The assembly stub establishes a controlled execution environment; the main payload can then do the more substantial storage work in freestanding C.
Reading NAND and starting Rockbox
At the hardware level, the NAND driver uses FMSS, a programmable microcontroller, to communicate with the NAND chips. lemonjesus’s earlier work on the S5L8702 sequencer, published as S5L8702-FMISS-Tools, documents its instruction set and provides tools for inspecting and building bytecode. That research is important prior work for understanding this part of the storage hardware; my work here uses the sequencer to read NAND as part of the nano 5G boot path.
The loader first checks that the microsecond timer used for driver timeouts is running. It then initializes the read-only NAND and FTL stack, mounts the FAT filesystem, and opens /.rockbox/rockbox.ipod. The core sequence follows the Rockbox bootloader’s own file-loading path:
rc = storage_init();
if (rc)
return fail(NB_NAND_INIT, rc);
filesystem_init();
if (disk_mount_all() <= 0)
return fail(NB_FAT_MOUNT, -1);
rc = load_firmware((unsigned char *)NB_LOAD_ADDR,
BOOTDIR "/" BOOTFILE, (int)NB_LOAD_LIMIT);
if (rc <= EFILE_EMPTY)
return fail(NB_LOAD, rc);
// The full program reaches this handoff after nb_prepare() succeeds.
nb_jump(NB_LOAD_ADDR);The file loader checks the Rockbox model identifier and checksum, then leaves the executable image at 0x08000000. The final handoff keeps interrupts masked, cleans and invalidates caches, drains pending writes, and branches to that address. Rockbox’s startup code takes over from there. If storage, mounting, or image loading fails, the payload shows the failing stage on the LCD and stops.
- Normal power-onThe bootloader reads the authenticated PRVD status and skips the resource-signature check.
- Font-triggered executionApple’s OS parses the modified font, which writes the two bootstrap images to SRAM and transfers control.
- A clean execution environmentThe entry stub takes control of the CPU and inherited hardware state; the main payload prepares storage.
- Rockbox from NANDThe loader finds the Rockbox image, copies it into DRAM, checks it, and jumps to its entry point.
Result and limits
On my nano 5G, the result is a cold, battery-powered boot straight into Rockbox, with no USB connection and no disk-mode button sequence. The PRVD bypass skips resource validation, not every firmware signature check. The loader and hardware demonstration here are specific to the nano 5G. The main payload inside the font is limited to 27,874 bytes.
Installation and restoration procedures, along with the reverse-engineering notes and build details, are in the nano5g_bootstub and nano5g_emCORE repositories below.
I have confirmed that the private-data partition works the same way on the nano 7G, which suggests the method will likely work on the 6G too. I plan to get the nano 4G and 5G Rockbox ports into good shape before applying this method to the 6G and 7G.
References
- nano5g_bootstub: the font exploit, PRVD analysis, two-stage Rockbox loader, and exact size budget.
- nano5g_emCORE: the emCORE port, NAND read/write tools, authenticated private-record updates, and installation procedure.
- CUB3D’s ipod_sun: the earlier nano 6G/7G chain combining the disk-mode swap with a modified font.
- q3k, “wInd3x, the iPod Bootrom exploit 10 years too late”: the USB/DFU entry point used to run unsigned code during setup, with background on the iPod boot chain.
- CVE-2010-1797: the existing FreeType CFF vulnerability used by the font exploit.
- freemyipod’s emCORE source: the original framework and earlier device targets on which the nano 5G adaptation builds.
- lemonjesus’s S5L8702-FMISS-Tools: earlier reverse engineering of the flash-controller sequencer, with instruction-set documentation and bytecode tools.
- n3g_fmss: my documentation of the nano 3G flash memory sequencer.
- n4g_fmss: my documentation of the nano 4G flash memory sequencer.
- Rockbox source: upstream firmware, storage, filesystem, and image-loading code reused in this work.