Skip to content

Stop exposing the raw eMMC partition as USB mass storage - #851

Open
yuzi-co wants to merge 1 commit into
sipeed:mainfrom
yuzi-co:security/usb-mass-storage-default
Open

Stop exposing the raw eMMC partition as USB mass storage#851
yuzi-co wants to merge 1 commit into
sipeed:mainfrom
yuzi-co:security/usb-mass-storage-default

Conversation

@yuzi-co

@yuzi-co yuzi-co commented Aug 1, 2026

Copy link
Copy Markdown

With no image selected, the device presents /dev/mmcblk0p3 — its own raw eMMC partition — to the attached machine as a USB disk. Two paths reach it.

At boot. S03usbdev writes that device into the gadget backing file whenever /boot/usb.disk0 is empty, which is the default:

disk=$(cat /boot/usb.disk0)
if [ -z "${disk}" ]
then
        echo /dev/mmcblk0p3 > functions/mass_storage.disk0/lun.0/file

On unmount. MountImage wrote the same device as its "no image" value, so ejecting an image re-exposed it.

Why that matters

A NanoKVM sitting idle offers the target machine a block device it should never see. Anyone at the attached machine can read it.

There is a second, more visible symptom: the partition has no MBR, so a Legacy BIOS finds no 0x55AA signature and hangs in a HLT loop rather than moving on to the next boot device.

What this does

Both paths leave the backing file unset, which is already what the gadget means by "no media" with removable=1. A BIOS skips it and moves on.

Devices that have not rebooted since still hold the old value in the backing file, so normalizeMountedImage keeps reading it back as "nothing mounted" rather than reporting the eMMC as a mounted image.

Standalone

This is three files and applies directly to main. It has no dependency on my other open PRs and can be merged in any order.

Tests

service/storage/image_test.go covers both directions of writeMountTarget and both directions of normalizeMountedImage.

The init script was checked with busybox sh -n. Go changes verified with go build, go vet, go test, and GOOS=linux GOARCH=riscv64 go build.


Updated: this was previously based on #849 and carried its commit. It has been rebased onto main and is now independent.

Landing order

This branch and #849 both add server/service/storage/image_test.go, which upstream does not have yet, so whichever lands second gets an add/add conflict in that one file. image.go itself merges cleanly — the two changes sit in different parts of it.

This branch is the smaller of the two, so landing it first and rebasing #849 onto the result is the cheaper order.

@yuzi-co
yuzi-co force-pushed the security/usb-mass-storage-default branch 2 times, most recently from 3e149ca to 570e6e5 Compare August 3, 2026 06:07
With no image selected, the device presented /dev/mmcblk0p3 -- its own raw
eMMC partition -- to the attached machine as a USB disk. Two paths reached it.

At boot, S03usbdev wrote that device into the gadget's backing file whenever
/boot/usb.disk0 was empty, which is the default. Unmounting an image did the
same: MountImage wrote the device as its "no image" value.

So a NanoKVM sitting idle offers the host a block device it should never see.
The partition also has no MBR, so a Legacy BIOS finds no 0x55AA signature and
hangs in a HLT loop instead of moving on to the next boot device.

Both paths now leave the backing file unset, which is what the gadget already
means by "no media" with removable=1. Devices that have not rebooted since
still hold the old value, so reading it back still reports "nothing mounted".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant