me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Check Vinix load segments and required ABI versions in signed roots

diviocity committed 5 days ago · 2cd700865e6974cba51c90747b7a4159faa658b2 View patch
Unverified signature 2 files changed +75 -6
tests/FEED.md +2 -0

@@ -152,3 +152,5 @@ The tool audits the package-owned root, makes a separate copy, and seeds the ver

152152On both targets, the worker installed musl and the public key package, then assembled a three-package offline repository. Using the build-box vpac with its paths directed into each resulting image, it installed the third package, `netbase`, from the embedded repository and recorded its ownership in that image. The logs are in `foundation/offline-stage-01` with receipt manifest SHA-256 `98bfcbdaed3aa81690bcdac5a8b0edbdfd91f5ab6ae8a7cc9f3fdd50e6252fb1`.

153153

154154Changing the netbase archive after signing caused assembly to fail its signed index checksum check before exposing the output root. The rejection log in `foundation/offline-stage-rejection-01` has receipt manifest SHA-256 `e15be9b8ba76c5c115a622e7fa57997c1bcb9ca99a3319e18b3daf489ecc3c8d`.

155+

156+The installed-root auditor checks each nonempty ELF load segment against the released kernel page size, 4 KiB on x86_64 and 16 KiB on aarch64. It also checks required symbol-version namespaces against the actual resolved package-owned provider using GNU readelf and objdump. The 106-package x86_64 root and the corrected arm64 loader passed. An old arm64 BusyBox failed its segment congruence check. An x86_64 libcrypto with its original SONAME and a changed version tag failed the OpenSSL consumer check. See `foundation/load-and-versions-02`, receipt SHA-256 `fd32f6b69db215ff6b79ec1f58c8457cf7f514dd162fbde410d9f6882072b979`. Use `tests/exec-linkage.py` as well to exercise actual dynamic symbol resolution.

tests/installed-root.v +73 -6

@@ -2,12 +2,21 @@

22module main

33

44import os

5+import strconv

6+

7+struct VersionUse {

8+ consumer string

9+ provider string

10+ version string

11+}

512

613struct Client {

714 root string

815 arch string

916mut:

1017 owners map[string]string

18+ exports map[string][]string

19+ imports []VersionUse

1120 files int

1221 elfs int

1322}

@@ -79,12 +88,45 @@ fn (mut client Client) load_owners(database string) !int {

7988 return packages

8089}

8190

82-fn (client &Client) library(name string, search []string) bool {

91+fn (client &Client) library(name string, search []string) string {

8392 for dir in search {

8493 path := client.resolve(dir + '/' + name) or { continue }

85- if path in client.owners && os.is_file(client.root + '/' + path) { return true }

94+ if path in client.owners && os.is_file(client.root + '/' + path) { return path }

95+ }

96+ return ''

97+}

98+

99+fn (mut client Client) symbol_versions(path string, providers map[string]string) ! {

100+ // objdump -p prints the version tables without dumping a line per symbol.

101+ result := os.exec(['objdump', '-p', client.root + '/' + path])

102+ if result.exit_code != 0 { return error('objdump ${path}: ${result.output}') }

103+ mut section := ''

104+ mut provider := ''

105+ for line in result.output.split_into_lines() {

106+ entry := line.trim_space()

107+ if entry in ['Version definitions:', 'Version References:'] {

108+ section = entry

109+ } else if entry == '' {

110+ section = ''

111+ } else if section == 'Version definitions:' {

112+ words := entry.fields()

113+ // A single indented name is an inherited version.

114+ if words.len == 4 { client.exports[path] << words[3] }

115+ } else if section == 'Version References:' {

116+ if entry.starts_with('required from ') {

117+ lib := entry.all_after('required from ').trim_right(':')

118+ provider = providers[lib] or { return error('${path} names unknown version provider ${lib}') }

119+ } else {

120+ words := entry.fields()

121+ if provider == '' || words.len != 4 { return error('unexpected version reference in ${path}: ${entry}') }

122+ // VER_FLG_WEAK lets the requested version be absent.

123+ flags := strconv.parse_uint(words[1], 0, 16)!

124+ if (flags & 2) == 0 {

125+ client.imports << VersionUse{consumer: path, provider: provider, version: words[3]}

126+ }

127+ }

128+ }

86129 }

87- return false

88130}

89131

90132fn (mut client Client) inspect(path string, defaults []string) ! {

@@ -107,11 +149,24 @@ fn (mut client Client) inspect(path string, defaults []string) ! {

107149 if result.exit_code != 0 { return error('readelf ${path}: ${result.output}') }

108150 mut needed := []string{}

109151 mut search := []string{}

152+ page := if client.arch == 'aarch64' { u64(16384) } else { u64(4096) }

153+ mut loads := 0

110154 for line in result.output.split_into_lines() {

111- if line.contains('Requesting program interpreter: ') {

155+ if line.trim_space().starts_with('LOAD ') {

156+ words := line.fields()

157+ if words.len < 8 { return error('malformed LOAD header in ${path}') }

158+ offset := strconv.parse_uint(words[1], 0, 64)!

159+ address := strconv.parse_uint(words[2], 0, 64)!

160+ memsz := strconv.parse_uint(words[5], 0, 64)!

161+ if memsz == 0 { continue }

162+ if address % page != offset % page {

163+ return error('${path}: PT_LOAD offset 0x${offset:x} and virtual address 0x${address:x} disagree on ${page}-byte Vinix pages')

164+ }

165+ loads++

166+ } else if line.contains('Requesting program interpreter: ') {

112167 interp := line.all_after('Requesting program interpreter: ').all_before(']')

113168 if interp != '/lib/ld-musl-' + client.arch + '.so.1'

114- || !client.library(os.base(interp), ['/lib']) {

169+ || client.library(os.base(interp), ['/lib']) == '' {

115170 return error('wrong or unowned interpreter ${interp} in ${path}')

116171 }

117172 } else if line.contains('(NEEDED)') {

@@ -127,11 +182,18 @@ fn (mut client Client) inspect(path string, defaults []string) ! {

127182 }

128183 }

129184 }

185+ if header[16] in [u8(2), 3] && loads == 0 { return error('no loadable segments in ${path}') }

130186 search << defaults

187+ mut providers := map[string]string{}

131188 for lib in needed {

132- if lib.contains('/') || !client.library(lib, search) {

189+ provider := client.library(lib, search)

190+ if lib.contains('/') || provider == '' {

133191 return error('${path} (${client.owners[path]}) needs missing or unowned library ${lib}')

134192 }

193+ providers[lib] = provider

194+ }

195+ if result.output.contains('(VERNEED)') || result.output.contains('(VERDEF)') {

196+ client.symbol_versions(path, providers)!

135197 }

136198}

137199

@@ -168,6 +230,11 @@ fn audit(arch string, sdk string) ! {

168230 }

169231 mut seen := map[string]bool{}

170232 client.walk('', defaults, mut seen)!

233+ for requirement in client.imports {

234+ if requirement.version !in client.exports[requirement.provider] {

235+ return error('${requirement.consumer} requires ABI version ${requirement.version} from ${requirement.provider}')

236+ }

237+ }

171238 for path, pkg in client.owners {

172239 if path !in seen { return error('absent package file: ${pkg} ${path}') }

173240 }