Foxboron / go-uefi

Linux UEFI library written in pure Go.
MIT License
138 stars 13 forks source link

Handle pe.OptionalHeader32 to avoid panic #10

Closed ml- closed 3 years ago

ml- commented 3 years ago

sbctl verify panics if ESP path contains a PE32 executable (e.g. BIOS update). Same for sbctl sign.

view panic ```shell $ sbctl verify Verifying file database and EFI images in /efi... ✔ /efi/EFI/BOOT/BOOTX64.EFI is signed ✔ /efi/EFI/Linux/linux-linux.efi is signed ✔ /efi/EFI/Linux/linux-lts.efi is signed ✔ /efi/EFI/systemd/systemd-bootx64.efi is signed panic: interface conversion: interface {} is *pe.OptionalHeader32, not *pe.OptionalHeader64 goroutine 1 [running]: github.com/foxboron/go-uefi/efi/pecoff.GetSignatureDataDirectory(0xc000300000, 0x1813f30, 0x1813f31, 0x0, 0x0, 0x0) github.com/foxboron/go-uefi@v0.0.0-20210611230104-7a6a29e36155/efi/pecoff/signature.go:92 +0x1c5 github.com/foxboron/go-uefi/efi/pecoff.GetSignatureBytesFromFile(0xc000300000, 0x1813f30, 0x1813f31, 0xc0000b2b00, 0x0, 0x0, 0x1, 0xc0000100f0) github.com/foxboron/go-uefi@v0.0.0-20210611230104-7a6a29e36155/efi/pecoff/signature.go:97 +0x45 github.com/foxboron/go-uefi/efi/pecoff.GetSignatures(0xc000300000, 0x1813f30, 0x1813f31, 0x0, 0x0, 0x0, 0x0, 0xc0000100d8) github.com/foxboron/go-uefi@v0.0.0-20210611230104-7a6a29e36155/efi/pecoff/reader.go:13 +0x5c github.com/foxboron/sbctl.VerifyFile(0xc00001c2a0, 0x24, 0xc00001cf00, 0x2b, 0x0, 0x0, 0x0) github.com/foxboron/sbctl/keys.go:149 +0x21d main.glob..func10.2(0xc00001cf00, 0x2b, 0x557153c64f18, 0xc000171790, 0x0, 0x0, 0x55715391035d, 0xc000171790) github.com/foxboron/sbctl/cmd/sbctl/verify.go:66 +0xfe path/filepath.walk(0xc00001cf00, 0x2b, 0x557153c64f18, 0xc000171790, 0x557153c5b7b0, 0x0, 0x0) path/filepath/path.go:414 +0x457 path/filepath.walk(0xc000016948, 0x4, 0x557153c64f18, 0xc0001708f0, 0x557153c5b7b0, 0x0, 0x0) path/filepath/path.go:438 +0x31b path/filepath.Walk(0xc000016948, 0x4, 0x557153c5b7b0, 0x30, 0xc000167cd8) path/filepath/path.go:501 +0x117 main.glob..func10(0x557153db2320, 0x557153de5670, 0x0, 0x0, 0x0, 0x0) github.com/foxboron/sbctl/cmd/sbctl/verify.go:47 +0xd5 github.com/spf13/cobra.(*Command).execute(0x557153db2320, 0x557153de5670, 0x0, 0x0, 0x557153db2320, 0x557153de5670) github.com/spf13/cobra@v1.1.3/command.go:852 +0x472 github.com/spf13/cobra.(*Command).ExecuteC(0x557153db3220, 0xc000167f60, 0x1, 0x1) github.com/spf13/cobra@v1.1.3/command.go:960 +0x375 github.com/spf13/cobra.(*Command).Execute(...) github.com/spf13/cobra@v1.1.3/command.go:897 main.main() github.com/foxboron/sbctl/cmd/sbctl/main.go:69 +0xfb ```
Foxboron commented 3 years ago

I was actually expecting this at some point! I have been thinking about how to refactor this portion of code into something nicer frankly.