From 2b485a272e2b8b8f21d301c694f0b6a168ccbad1 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Fri, 8 Dec 2023 12:12:43 +0000 Subject: [PATCH] efi: add some documentation and increase test coverage --- efi/grub_test.go | 12 +++ efi/pe.go | 1 + efi/shim_test.go | 2 +- efi/testdata/386/mockgrub.efi | Bin 0 -> 3761 bytes .../amd64/mockgrub1.efi.signed.shim.1 | Bin 5568 -> 0 bytes efi/testdata/amd64/mockshim.efi.signed.1.1.1 | Bin 7304 -> 7304 bytes .../amd64/mockshim.efi.signed.1.2.1+1.1.1 | Bin 9096 -> 9096 bytes .../mockshim_initial_sbat.efi.signed.1.1.1 | Bin 6744 -> 6744 bytes .../amd64/mockshim_no_sbat.efi.signed.1.1.1 | Bin 6176 -> 6176 bytes .../mockshim_no_vendor_cert.efi.signed.1.1.1 | Bin 6800 -> 6800 bytes .../amd64/mockshim_vendor_db.efi.signed.1.1.1 | Bin 7304 -> 7304 bytes efi/testdata/buildenv.yaml | 12 +-- efi/testdata/src/grub/Makefile | 2 +- efi/testdata/src/grub/elf_ia32_efi.lds | 86 ++++++++++++++++++ efi/testdata/src/grub/main_ia32.S | 13 +++ .../src/grub/{main_x86_64.s => main_x86_64.S} | 0 efi/testdata/src/grub/mods.S | 14 ++- tools/make-efi-testdata/apps.go | 38 +++++++- 18 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 efi/testdata/386/mockgrub.efi delete mode 100644 efi/testdata/amd64/mockgrub1.efi.signed.shim.1 create mode 100644 efi/testdata/src/grub/elf_ia32_efi.lds create mode 100644 efi/testdata/src/grub/main_ia32.S rename efi/testdata/src/grub/{main_x86_64.s => main_x86_64.S} (100%) diff --git a/efi/grub_test.go b/efi/grub_test.go index 4b76f741..91f1989a 100644 --- a/efi/grub_test.go +++ b/efi/grub_test.go @@ -53,6 +53,18 @@ func (s *grubSuite) TestGrubImageHandlePrefix2(c *C) { c.Check(prefix, Equals, "/EFI/debian") } +func (s *grubSuite) TestGrubImageHandlePrefix3(c *C) { + image, err := OpenPeImage(NewFileImage("testdata/386/mockgrub.efi")) + c.Assert(err, IsNil) + defer image.Close() + + grubImage := NewGrubImageHandle(image) + + prefix, err := grubImage.Prefix() + c.Check(err, IsNil) + c.Check(prefix, Equals, "/EFI/ubuntu") +} + func (s *grubSuite) TestGrubImageHandlePrefixNone(c *C) { image, err := OpenPeImage(NewFileImage("testdata/amd64/mockgrub_no_prefix.efi")) c.Assert(err, IsNil) diff --git a/efi/pe.go b/efi/pe.go index 057947dc..6091bc45 100644 --- a/efi/pe.go +++ b/efi/pe.go @@ -51,6 +51,7 @@ type peImageHandle interface { // Source returns the image source Source() Image + // Machine is the target machine Machine() uint16 // OpenSection returns a new io.SectionReader for the section with diff --git a/efi/shim_test.go b/efi/shim_test.go index 02a73433..2b140462 100644 --- a/efi/shim_test.go +++ b/efi/shim_test.go @@ -320,7 +320,7 @@ func (s *shimSuite) TestShimImageHandleReadVendorDBEmpty(c *C) { func (s *shimSuite) TestShimImageHandleReadVendorDBNoVendorCert(c *C) { err := s.testShimImageHandleReadVendorDB(c, &testShimImageHandleReadVendorDBData{ - path: "testdata/amd64/mockgrub1.efi.signed.shim.1"}) + path: "testdata/amd64/mockgrub.efi"}) c.Check(err, ErrorMatches, "no .vendor_cert section") } diff --git a/efi/testdata/386/mockgrub.efi b/efi/testdata/386/mockgrub.efi new file mode 100644 index 0000000000000000000000000000000000000000..2e2bdd8bb415c60ad861de8ececf59a748801ae5 GIT binary patch literal 3761 zcmeHK!EO^V5S=towSfi>+;Jri93q==;J|5H+DJ%6Af@8KCGlq6jYYhUyk1f`@d=gq z6%G|AB+fl^?H|A&EHj%82@#;sThLB4w&!`~tvyM+o@cMlpbh}nQ1cw%9D9KBIq zN44uys|m1;qf6MV->7ZehYd8gO2^ySld=Vy=9eTIBY>Ov05xbV&CN`rSy=-3BhShl zzj5SVoqEKJwNOKQp)X-U7(ky#(o4i{5{^LOw@Joa0)WrlsgWI&YenFf+?B2f?_>T` zG8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lkR)+h14e$LZAKx}|;hj#`c$Rzo&cL4z@%MPi!9F&oxu-cp$JZw-MX=z s_LCAMl50@c=;HCr6D7XvcRE?iJMQL;pU!3#MY_iQ))jqOE`|c_>1yMUk^lez delta 294 zcmV+>0oneDIfyxs*aaw|000V;K>;VT1OdAl2{AG_F*7qVH8hjR8o+;vb=nf^lOdRl zX&O5_T0S3vYJDg!O>aF+2y@&`FMR?yILOdisIb&6H?O~VfkO(0BSFXA0MnT)(*z>~ z){VwyS4=lyR~bb7!+S`wC@D6acgf(pXF$%$Ddgh^Cf?u|l?tBTj8Fvq=1vJKCuUFNELj!y6caVC zgNLgP s4%uimn>h(3Et6bg4KzbsnG!~<)w}Riq2QwIgsPQ55Vw_C`;!7#{%~!C2mk;8 diff --git a/efi/testdata/amd64/mockshim.efi.signed.1.2.1+1.1.1 b/efi/testdata/amd64/mockshim.efi.signed.1.2.1+1.1.1 index 11603a720f3e4843ee0fcc883af795bc97388517..ae95cf40efc52db73276f3e49211bb2be8a98299 100644 GIT binary patch delta 572 zcmV-C0>k}?M~Fv|*ab=;0RRe;VT1OdAl2{JJ;GBYzaGBA_K8o+;4V}>%ZaiGIz z_fRTWG!rKz{&@9>$OMVG;tb}Xee1l|Uae61_BwaEWr*qY;*?(kS>-J&9K^H@i-WX8 z5qw||rDD1*AT59&{DXK;S~cA)m=;O?r@W!OC2>l_ysUWKk|4|f0#>hgo1KzTT(7B0 zm8{e8oNVx;n8^>!PCS3+ZSp?Py%jAK;63_e=N>9#doplNwX;mgN$|auINWE~SVVRR zSC-LvLZJ(;>G$a4n*{%7%PGYu5As$IQsr@^Uc5_yf^7AOsN(WeTCN7-7eY<;;W|}m4WCdeo1}RwRoOIBcjPk& zLzPs7^fG|>0&k}?M~Fv|*aaps000V;K>;VT1OdAl2{AG_F*7qVH8hjR8o+-`*K)e{E~dld zBFbS!^cGNuIPt0xQ+!M{>eP4Os~-mD_P;AReEAt#>KiJ!JCk#4fVSxN>y8lnwy)mM ztf-C132l#p)sKJ=v&>eU8*IS))sXtjLZ_~OfA@eE1T)PA4(L$b-Rpt>fG6AEwpMN6 zrjT~mu|zOvjIf%Smui2PMl{2dc+E{|OE%Q2Uc}l7*}-KuCd|x0y#p+meCowqu3VTR z&OuQeYhBcSXC)tlp|awT?VAQn8-Xf>NT2_-F)Tw)D0LtL2>My%Dl@KmATqU?mKl|T@; Km0A0f0$BbcWD-aK diff --git a/efi/testdata/amd64/mockshim_initial_sbat.efi.signed.1.1.1 b/efi/testdata/amd64/mockshim_initial_sbat.efi.signed.1.1.1 index 22e4e1424909fef7a4a194f812f06e2278a6ebda..1d5dbc2435efbd01b02eb474e6decccfe7516501 100644 GIT binary patch delta 293 zcmV+=0owl9G}ttd*#rmy01A^q0VlHr0gD$2GBGhSGcz_aFq4=Vz<-#AC$Q>X{uVIX zefD=icX9w8i}u9^>`tNeXJD)hE>8;bAzg#?%sbuckoXfAZC8lN5uNOjv-{ny6Vv;S zvf%&OhgE+HH#H+{ZS}nG_pj%`C@a=FrL<0j5W9so^@ z?Y&kKc!83ek(J+gK^bB#u--=naTwi$w8}CXLot%v43fY4}gkrPn_wP r-7j*XckXe+&e(PCteE&hLU%;7(y?S=_18dlhR{3@><3+z3OR)2PLXSSy;2M4l)Wj*vn(G}i8tCe zdNmt;Iq0onebFrYAy*aeYA000V;K>;VT1OZbO2{JJ;GBYzaGBA^17QlZ#r!1g)E@^Pu zVd=&h6t#HAd!^5u)JS_#CAAy}QQARTs0!JtwzuNlEpB|kCn>`MmV4k~e(Avm2XnVr#Lw4*!^j_mfh2tS)jW-K|5lhd46fBzTh=a{;k;PTuB1m{06I;g`3Ia50CF zl33vskQeuMNc2hTbp?N@8$y1W8Sh6Bz3$Sp_r&C;qS#_YXv`u`7%oR^DmOB+*w{!5 zC0L&1_=WA*<7nhiSA0~idhp}9Gq!2cv_=a`yoy$C1FuJba4ItQFN}-g?&8OBp&T?H sr9~*$E@1Xx=Fl!1WI+hPY9}JiO;J|?Fb-it1|#17;9#}*MhgO+P?}zcdH?_b delta 294 zcmV+>0onebFrYAy*agn4000V;K>;VT1OZbO2{AG_F*7qVH8hi87QlaKYdn#O&`0gmarL)@1nCR4@}XpB9BkNMq#QsgCKThPbW}~7O`k)U!1h8aQs2i z`J!>5p1IQ&czFIHvj535eQ9K?XhX2=^{;k!V@_};&>Ln`830nV>P{yrZ&n-Hd4G-ZEtNL0a{qvhQd9DcgTJy#7gR#h2S19I{KO7kDj6_b`wS|itE zyP@8Aj_m|gC=EW|amt3Yr#8>xHkD>?JM=pgsvJ{Ne%D=s-VA_Apq8zTf7}`n!q4(_ s4&dX_93cRz!+-Qy?IuaX;2{JU0o9hI*l4DNd_-Axr#Ufv3q1m4Fob@E#Q*>R diff --git a/efi/testdata/amd64/mockshim_no_vendor_cert.efi.signed.1.1.1 b/efi/testdata/amd64/mockshim_no_vendor_cert.efi.signed.1.1.1 index 50295a97de659e65b21346ba81bc17069361431f..1baf8610ebe1b1969feb0e09ef13f1a572a16649 100644 GIT binary patch delta 294 zcmV+>0oneLHIOxs*ahD!000V;K>;VT1OdYr2{JJ;GBYzaGBA_S7{GrPem6pOx-KrQ z`_a1hdX$cOOKnuC_19^!oM!-D9DK}vLv9Khmn$=xE&!)>C8fh8k!Y>a;-Q)=3!<9mlM@U|K?$+_Yv=R5AunQ>795{>i7>nauj;=nmU zL$77XV_l{}SpX%@eIVGM#x1DxWnwJ)=i*-#YBV7yGCDR6nZC<&VC_bsN7VgC7;#QX s5@i-xn$YGZI9(T!eyZcFSvNwg4Xi&_7{p@(tRpZmJAi?w@ZSPOEMv8XX#fBK delta 294 zcmV+>0oneLHIOxs*acTn000V;K>;VT1OdYr2{AG_F*7qVH8hjZ7{GsU3Fyfk{H^vj z(|SI3k+iU<9N-`X{K;Mv$yBcJJ;;3carsdjnA*XZsJyOMX0hu#Fm{i{-w^qWX9 zYpyVN6#t~pxL6Pu64HNDsjWHG$6#aDj4Rg@6f~Ri)<86L?-tE;4UmI~tiXk;t_g sB{{^oM4cx=;cm8f@pDv2jHgkB{BN?+^ck10;L8XZ9;$?;D;@%ts`V3&oB#j- diff --git a/efi/testdata/amd64/mockshim_vendor_db.efi.signed.1.1.1 b/efi/testdata/amd64/mockshim_vendor_db.efi.signed.1.1.1 index 6a4e06a96187c5e32aba4a054f3531fe9527f62b..cf597039c6193323a4ccd0e7fd76618870740c9d 100644 GIT binary patch delta 294 zcmV+>0oneDIfyxs*ahiO000V;K>;VT1OdAl2{JJ;GBYzaGBA_K8o+;0^amjq*WXPq z6YcGVfmYOvouNw7!>3Jxtp+ZnbZ2Ej=4MUx9+4h^+oUO6CRBb}gS>kWa^LMyu`@b#Nr< z?Jp#??}w|Zw>7mTRKfIEv^&DplEZf$%$$+;Vu+L4f%Hp}z!YfjoGjMwZzW}w*3_cP s&A$(unP(LV$`1q1vnr3}-f<>)N>f={DdZ1z8|wlo!)KX}VgLXD delta 294 zcmV+>0oneDIfyxs*afSo000V;K>;VT1OdAl2{AG_F*7qVH8hjR8o+;AVz!95v9)b^ zyN7VpyV$={O5DhNM6&d`O`dnxYr9smXk+v`=iuTT#g@Mq(M>I=3x3!j#}WI4&=r