Skip to content

Conversation

@codesmith25103
Copy link
Contributor

Previously, urunc hardcoded MirageOS network interfaces to 'service'
and block devices to 'storage'. This caused failures for unikernels
that defined different interface names in their Solo5 manifest.

This commit introduces dynamic device discovery and mapping:

  • Parsed .note.solo5.manifest from ELF binary for auto-detection.
  • Added support for urunc.dev/mirage-net-map annotations.
  • Updated UnikernelParams to pass binary path and annotations.

This ensures compatibility with diverse MirageOS unikernels.
Fixes: #315

@netlify
Copy link

netlify bot commented Dec 23, 2025

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 44f2f95
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/69719a3c8bdc560008c6d9b4

@sonarqubecloud
Copy link

Comment on lines 183 to 194
var manifest Solo5Manifest
// Attempt to find the start of the JSON object '{'
jsonStart := strings.Index(string(data), "{")
if jsonStart == -1 {
return nil, fmt.Errorf("invalid manifest format")
}

if err := json.Unmarshal(data[jsonStart:], &manifest); err != nil {
return nil, err
}

return &manifest, nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note doesn't contain json. See https://github.com/Solo5/solo5/blob/dabc69fd89b8119449ec4088c54b458d4ccc851b/include/mft_abi.h for the format, or https://git.robur.coop/robur/ocaml-solo5-elftool/src/branch/main/lib/solo5_elftool.ml#L73-L146 for code that parses the format.

If you want json you can use solo5-elftool query-manifest $executable assuming solo5-elftool is in $PATH. This adds an external dependency though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reynir Thanks for catching this! You are absolutely right
I was incorrectly assuming the manifest section contained JSON, but it is indeed raw binary data as defined in the ABI.

To avoid introducing an external dependency on solo5-elftool, I have rewritten the implementation to parse the binary data natively in Go. The updated parser now:

Follows the layout defined in mft_abi.h.

Correctly handles the C-struct alignment and padding (specifically the 8-byte alignment for the version and device types).

Includes logic to skip the ELF Note header if present.

Comment on lines +78 to +130
mirageID := m.getMirageDeviceName(ifName, "NET_BASIC", "service")

netOption := fmt.Sprintf("--net:%s=%s", mirageID, ifName)
netOption += fmt.Sprintf(" --net-mac:%s=%s", mirageID, mac)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the security model is, but you may consider enforcing the constraint that device names are alphanumerical (and at most a fixed length which I don't remember). Otherwise you can inject arbitrary strings here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated getMirageDeviceName to enforce strict validation:

Alphanumeric Check: The resolved name is validated against a regex (^[a-zA-Z0-9_]+$).

Fallback: If the name contains invalid characters, it safely falls back to the default name (e.g., storage or service) rather than passing the raw string.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it doesn't make sense to add a fallback. If the name is invalid then solo5-hvt/solo5-spt will error out parsing the ELF. Even if the ELF was not invalid solo5-hvt/solo5-spt will error out because you just made up a device name that doesn't match the manifest.

@codesmith25103 codesmith25103 force-pushed the Issue315 branch 2 times, most recently from fd0bf6f to 3844f3c Compare January 21, 2026 18:00
Previously, urunc hardcoded MirageOS network interfaces to 'service' and
block devices to 'storage'. This caused failures for unikernels that
defined different interface names in their Solo5 manifest.

This commit introduces dynamic device discovery and mapping:
- Parsed .note.solo5.manifest from ELF binary for auto-detection.
- Added support for urunc.dev/mirage-net-map annotations.
- Updated UnikernelParams to pass binary path and annotations.

This ensures compatibility with diverse MirageOS unikernels.
Fixes: urunc-dev#315
Signed-off-by: Sankalp <sankalp25103@gmail.com>
Comment on lines +224 to +237
// Heuristic to skip ELF Note Header
if len(data) > 12 {
var namesz uint32
// FIX: Checked error return value (errcheck warning)
if err := binary.Read(bytes.NewReader(data[0:4]), binary.LittleEndian, &namesz); err != nil {
// If we can't even read 4 bytes, just ignore this check and use offset 0
} else {
// If namesz is 6 ("Solo5\0"), skip header.
// Header = 12 + aligned(namesz)
if namesz == 6 {
offset = int64(12 + ((namesz + 3) &^ 3))
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. Does the ELF library do this or not? It doesn't make sense to maybe do this to me. What is the heuristic exactly?

}

// MftHeader matches the 12-byte header found in the binary.
// 0x00: Pad/Reserved (4)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The padding is <4 and depends on the note owner and such. I don't think this is right.

Comment on lines +249 to +252
// Sanity Check
if header.Version != 1 {
return nil, fmt.Errorf("invalid manifest version: %d (expected 1)", header.Version)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check that the number of entries is at least 1 as there is always the RESERVED_FIRST entry.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check entries is less than or equal to MFT_MAX_ENTRIES.

Comment on lines +275 to +283
switch entry.Type {

case mftDevNetBasic:
devType = "NET_BASIC"
case mftDevBlockBasic:
devType = "BLOCK_BASIC"
default:
devType = fmt.Sprintf("UNKNOWN_%d", entry.Type)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot the RESERVED_FIRST entry which is always present and the first entry.

const (
mftDevBlockBasic = 0
mftDevNetBasic = 1
mftNameMax = 64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where you got the number 64. It's not right.

Name [mftNameMax + 1]byte
Pad [7]byte // Exported to avoid panic in binary.Read
Type uint64
Flags uint64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is Flags?

Pad [7]byte // Exported to avoid panic in binary.Read
Type uint64
Flags uint64
Pad2 [16]byte // Exported to avoid panic in binary.Read
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Comment on lines +78 to +130
mirageID := m.getMirageDeviceName(ifName, "NET_BASIC", "service")

netOption := fmt.Sprintf("--net:%s=%s", mirageID, ifName)
netOption += fmt.Sprintf(" --net-mac:%s=%s", mirageID, mac)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it doesn't make sense to add a fallback. If the name is invalid then solo5-hvt/solo5-spt will error out parsing the ELF. Even if the ELF was not invalid solo5-hvt/solo5-spt will error out because you just made up a device name that doesn't match the manifest.

}
cleanName := string(entry.Name[:nameLen])

// Skip empty names (often internal devices)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no such thing as internal devices. Empty names are disallowed.

Comment on lines +46 to +47
monitorRootfsDirName = "monRootfs"
containerRootfsMountPath = "/cntrRootfs"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated. It would be helpful to me if unrelated changes were kept out of this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple block and network devices over Solo5/MirageOS

3 participants