]> git.proxmox.com Git - efi-boot-shim.git/blob - debian/patches/Make-sbat_var.S-parse-right-with-buggy-gcc-binutils.patch
Switch to new upstream (15.7)
[efi-boot-shim.git] / debian / patches / Make-sbat_var.S-parse-right-with-buggy-gcc-binutils.patch
1 From 657b2483ca6e9fcf2ad8ac7ee577ff546d24c3aa Mon Sep 17 00:00:00 2001
2 From: Peter Jones <pjones@redhat.com>
3 Date: Mon, 5 Dec 2022 17:57:36 -0500
4 Subject: [PATCH] Make sbat_var.S parse right with buggy gcc/binutils
5
6 In https://github.com/rhboot/shim/issues/533 , iokomin noticed that
7 gas in binutils before 2.36 appears to be incorrectly concatenating
8 string literals in '.asciz' directives, including an extra NUL character
9 in between the strings, and this will cause us to incorrectly parse the
10 .sbatlevel section in shim binaries.
11
12 This patch adds test cases that will cause the build to fail if this has
13 happened, as well as changing sbat_var.S to to use '.ascii' and '.byte'
14 to construct the data, rather than using '.asciz'.
15
16 Signed-off-by: Peter Jones <pjones@redhat.com>
17 ---
18 include/test.mk | 2 +-
19 sbat_var.S | 6 ++++--
20 test-sbat.c | 32 ++++++++++++++++++++++++++++++++
21 3 files changed, 37 insertions(+), 3 deletions(-)
22
23 diff --git a/include/test.mk b/include/test.mk
24 index c0e24095..c37b8446 100644
25 --- a/include/test.mk
26 +++ b/include/test.mk
27 @@ -92,7 +92,7 @@ test-mock-variables: CFLAGS+=-DHAVE_SHIM_LOCK_GUID
28 test-mok-mirror_FILES = mok.c globals.c tpm.c lib/guid.c lib/variables.c mock-variables.c
29 test-mok-mirror: CFLAGS+=-DHAVE_START_IMAGE -DHAVE_SHIM_LOCK_GUID
30
31 -test-sbat_FILES = csv.c lib/variables.c lib/guid.c sbat_var.S
32 +test-sbat_FILES = csv.c lib/variables.c lib/guid.c sbat_var.S mock-variables.c
33 test-sbat :: CFLAGS+=-DHAVE_GET_VARIABLE -DHAVE_GET_VARIABLE_ATTR -DHAVE_SHIM_LOCK_GUID
34
35 test-str_FILES = lib/string.c
36 diff --git a/sbat_var.S b/sbat_var.S
37 index a115077a..2a813a40 100644
38 --- a/sbat_var.S
39 +++ b/sbat_var.S
40 @@ -14,7 +14,9 @@ sbat_var_payload_header:
41 .Lsbat_var_payload_header_end:
42 .balign 1, 0
43 .Lsbat_var_previous:
44 - .asciz SBAT_VAR_PREVIOUS
45 + .ascii SBAT_VAR_PREVIOUS
46 + .byte 0
47 .balign 1, 0
48 .Lsbat_var_latest:
49 - .asciz SBAT_VAR_LATEST
50 + .ascii SBAT_VAR_LATEST
51 + .byte 0
52 diff --git a/test-sbat.c b/test-sbat.c
53 index 72bebe7a..65bc6a84 100644
54 --- a/test-sbat.c
55 +++ b/test-sbat.c
56 @@ -1107,6 +1107,36 @@ test_preserve_sbat_uefi_variable_bad_short(void)
57 return 0;
58 }
59
60 +static int
61 +test_sbat_var_asciz(void)
62 +{
63 + EFI_STATUS status;
64 + char buf[1024] = "";
65 + UINT32 attrs = 0;
66 + UINTN size = sizeof(buf);
67 + char expected[] = SBAT_VAR_PREVIOUS;
68 +
69 + status = set_sbat_uefi_variable();
70 + if (status != EFI_SUCCESS)
71 + return -1;
72 +
73 + status = RT->GetVariable(SBAT_VAR_NAME, &SHIM_LOCK_GUID, &attrs, &size, buf);
74 + if (status != EFI_SUCCESS)
75 + return -1;
76 +
77 + /*
78 + * this should be enough to get past "sbat,", which handles the
79 + * first error.
80 + */
81 + if (size < (strlen(SBAT_VAR_SIG) + 2) || size != strlen(expected))
82 + return -1;
83 +
84 + if (strncmp(expected, buf, size) != 0)
85 + return -1;
86 +
87 + return 0;
88 +}
89 +
90 int
91 main(void)
92 {
93 @@ -1155,6 +1185,8 @@ main(void)
94 test(test_preserve_sbat_uefi_variable_version_older);
95 test(test_preserve_sbat_uefi_variable_version_olderlonger);
96
97 + test(test_sbat_var_asciz);
98 +
99 return 0;
100 }
101
102 --
103 2.30.2
104