Skip to content

Commit b9e07ec

Browse files
authored
Use addonx64.efi.stub, not linuxx64.efi.stub, for UKI addons (#704)
UKI addons were being built using linuxx64.efi.stub, the full systemd-stub meant for main UKIs that embed kernel/initrd. This worked by coincidence on current systemd 255 builds, but is incorrect per upstream systemd design, and will fail with later versions of systemd that ship a larger linuxx64.efi.stuf, which leaves no room for the appended .cmdline section data (systemd 258 already triggers this). Since systemd 254, ukify ships a dedicated, minimal addonx64.efi.stub, whose PE header reserves space for appended sections. When --linux is not specified, ukify auto-selects the addon stub by default. Our code overrides this with --stub=, so we need to pass the correct stub explicitly. Using the linux stub for addons produces PE binaries where the appended .cmdline section data may land at or beyond EOF depending on stub size and alignment, causing `objcopy --dump-section .cmdline` to fail with "file truncated". The addon stub avoids this by design. <!-- Description: Please provide a summary of the changes and the motivation behind them. --> --- ### **Checklist** - [ ] Tests added/updated - [ ] Documentation updated (if needed) - [ ] Code conforms to style guidelines
1 parent be27eae commit b9e07ec

2 files changed

Lines changed: 47 additions & 38 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/customizeuki.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,10 @@ func createUkiDirectories(buildDir string, imageChroot *safechroot.Chroot) error
382382
func copyUkiFiles(buildDir string, kernelToInitramfs map[string]string, imageChroot *safechroot.Chroot,
383383
bootConfig BootFilesArchConfig, uki *imagecustomizerapi.Uki,
384384
) error {
385-
// Both create and modify modes need the stub file
385+
// Both create and modify modes need the stub files
386386
filesToCopy := map[string]string{
387-
filepath.Join(imageChroot.RootDir(), bootConfig.ukiEfiStubBinaryPath): filepath.Join(buildDir, UkiBuildDir, bootConfig.ukiEfiStubBinary),
387+
filepath.Join(imageChroot.RootDir(), bootConfig.ukiEfiStubBinaryPath): filepath.Join(buildDir, UkiBuildDir, bootConfig.ukiEfiStubBinary),
388+
filepath.Join(imageChroot.RootDir(), bootConfig.ukiAddonStubBinaryPath): filepath.Join(buildDir, UkiBuildDir, bootConfig.ukiAddonStubBinary),
388389
}
389390

390391
// Create mode needs additional files (os-release, kernels, initramfs)
@@ -505,7 +506,7 @@ func createUkiInModifyMode(ctx context.Context, rc *ResolvedConfig) error {
505506
logger.Log.Debugf("UKI file [%d]: %s", i, ukiFile)
506507
}
507508

508-
stubPath := filepath.Join(rc.BuildDirAbs, UkiBuildDir, bootConfig.ukiEfiStubBinary)
509+
stubPath := filepath.Join(rc.BuildDirAbs, UkiBuildDir, bootConfig.ukiAddonStubBinary)
509510

510511
// Process each UKI file - regenerate its addon with updated cmdline
511512
for _, ukiFile := range ukiFiles {
@@ -628,6 +629,7 @@ func createUki(ctx context.Context, rc *ResolvedConfig) error {
628629
}
629630

630631
stubPath := filepath.Join(rc.BuildDirAbs, UkiBuildDir, bootConfig.ukiEfiStubBinary)
632+
addonStubPath := filepath.Join(rc.BuildDirAbs, UkiBuildDir, bootConfig.ukiAddonStubBinary)
631633
osSubreleaseFullPath := filepath.Join(rc.BuildDirAbs, UkiBuildDir, "os-release")
632634
cmdlineFilePath := filepath.Join(rc.BuildDirAbs, UkiBuildDir, UkiKernelInfoJson)
633635

@@ -638,7 +640,7 @@ func createUki(ctx context.Context, rc *ResolvedConfig) error {
638640
}
639641

640642
for kernel, info := range kernelInfo {
641-
err := buildUki(kernel, info.Initramfs, info.Cmdline, osSubreleaseFullPath, stubPath, rc.BuildDirAbs,
643+
err := buildUki(kernel, info.Initramfs, info.Cmdline, osSubreleaseFullPath, stubPath, addonStubPath, rc.BuildDirAbs,
642644
systemBootPartitionTmpDir,
643645
)
644646
if err != nil {
@@ -724,7 +726,7 @@ func extractKernelToArgsFromGrub(grubCfgPath string) (map[string]string, error)
724726
}
725727

726728
func buildUki(kernel string, initramfs string, kernelArgs string, osSubreleaseFullPath string,
727-
stubPath string, buildDir string, systemBootPartitionTmpDir string,
729+
stubPath string, addonStubPath string, buildDir string, systemBootPartitionTmpDir string,
728730
) error {
729731
kernelVersion, err := getKernelVersion(kernel)
730732
if err != nil {
@@ -738,7 +740,7 @@ func buildUki(kernel string, initramfs string, kernelArgs string, osSubreleaseFu
738740
}
739741

740742
// Build UKI addon
741-
err = buildUkiAddon(kernel, kernelArgs, stubPath, systemBootPartitionTmpDir)
743+
err = buildUkiAddon(kernel, kernelArgs, addonStubPath, systemBootPartitionTmpDir)
742744
if err != nil {
743745
return fmt.Errorf("failed to build UKI addon:\n%w", err)
744746
}

toolkit/tools/pkg/imagecustomizerlib/liveosisoutils.go

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const (
3232
ukiEfiStubx64Binary = "linuxx64.efi.stub"
3333
ukiEfiStubAA64Binary = "linuxaa64.efi.stub"
3434

35+
ukiAddonStubx64Binary = "addonx64.efi.stub"
36+
ukiAddonStubAA64Binary = "addonaa64.efi.stub"
37+
3538
grubCfgDir = "/boot/grub2"
3639
isoGrubCfg = "grub.cfg"
3740
isoGrubCfgPath = grubCfgDir + "/" + isoGrubCfg
@@ -83,40 +86,44 @@ type BootFilesArchConfig struct {
8386
isoGrubBinaryPath string
8487
ukiEfiStubBinary string
8588
ukiEfiStubBinaryPath string
89+
ukiAddonStubBinary string
90+
ukiAddonStubBinaryPath string
8691
}
8792

88-
var (
89-
bootloaderFilesConfig = map[string]BootFilesArchConfig{
90-
"amd64": {
91-
bootBinary: bootx64Binary,
92-
grubBinary: grubx64Binary,
93-
grubNoPrefixBinary: grubx64NoPrefixBinary,
94-
espBootBinaryPath: espBootloaderDir + "/" + bootx64Binary,
95-
espGrubBinaryPath: espBootloaderDir + "/" + grubx64Binary,
96-
osEspBootBinaryPath: osEspBootloaderDir + "/" + bootx64Binary,
97-
osEspGrubBinaryPath: osEspBootloaderDir + "/" + grubx64Binary,
98-
osEspGrubNoPrefixBinaryPath: osEspBootloaderDir + "/" + grubx64NoPrefixBinary,
99-
isoBootBinaryPath: isoBootloaderDir + "/" + bootx64Binary,
100-
isoGrubBinaryPath: isoBootloaderDir + "/" + grubx64Binary,
101-
ukiEfiStubBinary: ukiEfiStubx64Binary,
102-
ukiEfiStubBinaryPath: ukiEfiStubDir + "/" + ukiEfiStubx64Binary,
103-
},
104-
"arm64": {
105-
bootBinary: bootAA64Binary,
106-
grubBinary: grubAA64Binary,
107-
grubNoPrefixBinary: grubAA64NoPrefixBinary,
108-
espBootBinaryPath: espBootloaderDir + "/" + bootAA64Binary,
109-
espGrubBinaryPath: espBootloaderDir + "/" + grubAA64Binary,
110-
osEspBootBinaryPath: osEspBootloaderDir + "/" + bootAA64Binary,
111-
osEspGrubBinaryPath: osEspBootloaderDir + "/" + grubAA64Binary,
112-
osEspGrubNoPrefixBinaryPath: osEspBootloaderDir + "/" + grubAA64NoPrefixBinary,
113-
isoBootBinaryPath: isoBootloaderDir + "/" + bootAA64Binary,
114-
isoGrubBinaryPath: isoBootloaderDir + "/" + grubAA64Binary,
115-
ukiEfiStubBinary: ukiEfiStubAA64Binary,
116-
ukiEfiStubBinaryPath: ukiEfiStubDir + "/" + ukiEfiStubAA64Binary,
117-
},
118-
}
119-
)
93+
var bootloaderFilesConfig = map[string]BootFilesArchConfig{
94+
"amd64": {
95+
bootBinary: bootx64Binary,
96+
grubBinary: grubx64Binary,
97+
grubNoPrefixBinary: grubx64NoPrefixBinary,
98+
espBootBinaryPath: espBootloaderDir + "/" + bootx64Binary,
99+
espGrubBinaryPath: espBootloaderDir + "/" + grubx64Binary,
100+
osEspBootBinaryPath: osEspBootloaderDir + "/" + bootx64Binary,
101+
osEspGrubBinaryPath: osEspBootloaderDir + "/" + grubx64Binary,
102+
osEspGrubNoPrefixBinaryPath: osEspBootloaderDir + "/" + grubx64NoPrefixBinary,
103+
isoBootBinaryPath: isoBootloaderDir + "/" + bootx64Binary,
104+
isoGrubBinaryPath: isoBootloaderDir + "/" + grubx64Binary,
105+
ukiEfiStubBinary: ukiEfiStubx64Binary,
106+
ukiEfiStubBinaryPath: ukiEfiStubDir + "/" + ukiEfiStubx64Binary,
107+
ukiAddonStubBinary: ukiAddonStubx64Binary,
108+
ukiAddonStubBinaryPath: ukiEfiStubDir + "/" + ukiAddonStubx64Binary,
109+
},
110+
"arm64": {
111+
bootBinary: bootAA64Binary,
112+
grubBinary: grubAA64Binary,
113+
grubNoPrefixBinary: grubAA64NoPrefixBinary,
114+
espBootBinaryPath: espBootloaderDir + "/" + bootAA64Binary,
115+
espGrubBinaryPath: espBootloaderDir + "/" + grubAA64Binary,
116+
osEspBootBinaryPath: osEspBootloaderDir + "/" + bootAA64Binary,
117+
osEspGrubBinaryPath: osEspBootloaderDir + "/" + grubAA64Binary,
118+
osEspGrubNoPrefixBinaryPath: osEspBootloaderDir + "/" + grubAA64NoPrefixBinary,
119+
isoBootBinaryPath: isoBootloaderDir + "/" + bootAA64Binary,
120+
isoGrubBinaryPath: isoBootloaderDir + "/" + grubAA64Binary,
121+
ukiEfiStubBinary: ukiEfiStubAA64Binary,
122+
ukiEfiStubBinaryPath: ukiEfiStubDir + "/" + ukiEfiStubAA64Binary,
123+
ukiAddonStubBinary: ukiAddonStubAA64Binary,
124+
ukiAddonStubBinaryPath: ukiEfiStubDir + "/" + ukiAddonStubAA64Binary,
125+
},
126+
}
120127

121128
func getBootArchConfig() (string, BootFilesArchConfig, error) {
122129
arch := runtime.GOARCH

0 commit comments

Comments
 (0)