Stop exposing the raw eMMC partition as USB mass storage - #851
Open
yuzi-co wants to merge 1 commit into
Open
Conversation
yuzi-co
force-pushed
the
security/usb-mass-storage-default
branch
2 times, most recently
from
August 3, 2026 06:07
3e149ca to
570e6e5
Compare
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".
yuzi-co
force-pushed
the
security/usb-mass-storage-default
branch
from
August 13, 2026 17:47
570e6e5 to
eb49ed6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
S03usbdevwrites that device into the gadget backing file whenever/boot/usb.disk0is empty, which is the default:On unmount.
MountImagewrote 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
0x55AAsignature 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
normalizeMountedImagekeeps 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.gocovers both directions ofwriteMountTargetand both directions ofnormalizeMountedImage.The init script was checked with
busybox sh -n. Go changes verified withgo build,go vet,go test, andGOOS=linux GOARCH=riscv64 go build.Updated: this was previously based on #849 and carried its commit. It has been rebased onto
mainand 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.goitself 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.