|
| 1 | +From 7e5d2180c09429955004f3dfd960293a39aaf731 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Harry Youd < [email protected]> |
| 3 | +Date: Wed, 31 Jul 2019 19:44:53 +0100 |
| 4 | +Subject: [PATCH] Avoid taking pointer to packed struct |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | + |
| 9 | +Fixes: |
| 10 | +error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member] |
| 11 | +(cherry picked from commit 19e8c9071b3d9306ca7b7329b313b31f86c2936d) |
| 12 | +--- |
| 13 | + src/mokutil.c | 38 ++++++++++++++++++++++---------------- |
| 14 | + 1 file changed, 22 insertions(+), 16 deletions(-) |
| 15 | + |
| 16 | +diff --git a/src/mokutil.c b/src/mokutil.c |
| 17 | +index e2d567d..8892613 100644 |
| 18 | +--- a/src/mokutil.c |
| 19 | ++++ b/src/mokutil.c |
| 20 | +@@ -270,20 +270,22 @@ build_mok_list (void *data, unsigned long data_size, uint32_t *mok_num) |
| 21 | + return NULL; |
| 22 | + } |
| 23 | + |
| 24 | +- if ((efi_guid_cmp (&CertList->SignatureType, &efi_guid_x509_cert) != 0) && |
| 25 | +- (efi_guid_cmp (&CertList->SignatureType, &efi_guid_sha1) != 0) && |
| 26 | +- (efi_guid_cmp (&CertList->SignatureType, &efi_guid_sha224) != 0) && |
| 27 | +- (efi_guid_cmp (&CertList->SignatureType, &efi_guid_sha256) != 0) && |
| 28 | +- (efi_guid_cmp (&CertList->SignatureType, &efi_guid_sha384) != 0) && |
| 29 | +- (efi_guid_cmp (&CertList->SignatureType, &efi_guid_sha512) != 0)) { |
| 30 | ++ efi_guid_t sigtype = CertList->SignatureType; |
| 31 | ++ |
| 32 | ++ if ((efi_guid_cmp (&sigtype, &efi_guid_x509_cert) != 0) && |
| 33 | ++ (efi_guid_cmp (&sigtype, &efi_guid_sha1) != 0) && |
| 34 | ++ (efi_guid_cmp (&sigtype, &efi_guid_sha224) != 0) && |
| 35 | ++ (efi_guid_cmp (&sigtype, &efi_guid_sha256) != 0) && |
| 36 | ++ (efi_guid_cmp (&sigtype, &efi_guid_sha384) != 0) && |
| 37 | ++ (efi_guid_cmp (&sigtype, &efi_guid_sha512) != 0)) { |
| 38 | + dbsize -= CertList->SignatureListSize; |
| 39 | + CertList = (EFI_SIGNATURE_LIST *)((uint8_t *) CertList + |
| 40 | + CertList->SignatureListSize); |
| 41 | + continue; |
| 42 | + } |
| 43 | + |
| 44 | +- if ((efi_guid_cmp (&CertList->SignatureType, &efi_guid_x509_cert) != 0) && |
| 45 | +- (CertList->SignatureSize != signature_size (&CertList->SignatureType))) { |
| 46 | ++ if ((efi_guid_cmp (&sigtype, &efi_guid_x509_cert) != 0) && |
| 47 | ++ (CertList->SignatureSize != signature_size (&sigtype))) { |
| 48 | + dbsize -= CertList->SignatureListSize; |
| 49 | + CertList = (EFI_SIGNATURE_LIST *)((uint8_t *) CertList + |
| 50 | + CertList->SignatureListSize); |
| 51 | +@@ -312,7 +314,7 @@ build_mok_list (void *data, unsigned long data_size, uint32_t *mok_num) |
| 52 | + } |
| 53 | + |
| 54 | + list[count].header = CertList; |
| 55 | +- if (efi_guid_cmp (&CertList->SignatureType, &efi_guid_x509_cert) == 0) { |
| 56 | ++ if (efi_guid_cmp (&sigtype, &efi_guid_x509_cert) == 0) { |
| 57 | + /* X509 certificate */ |
| 58 | + list[count].mok_size = CertList->SignatureSize - |
| 59 | + sizeof(efi_guid_t); |
| 60 | +@@ -442,10 +444,11 @@ list_keys (uint8_t *data, size_t data_size) |
| 61 | + |
| 62 | + for (unsigned int i = 0; i < mok_num; i++) { |
| 63 | + printf ("[key %d]\n", i+1); |
| 64 | +- if (efi_guid_cmp (&list[i].header->SignatureType, &efi_guid_x509_cert) == 0) { |
| 65 | ++ efi_guid_t sigtype = list[i].header->SignatureType; |
| 66 | ++ if (efi_guid_cmp (&sigtype, &efi_guid_x509_cert) == 0) { |
| 67 | + print_x509 ((char *)list[i].mok, list[i].mok_size); |
| 68 | + } else { |
| 69 | +- print_hash_array (&list[i].header->SignatureType, |
| 70 | ++ print_hash_array (&sigtype, |
| 71 | + list[i].mok, list[i].mok_size); |
| 72 | + } |
| 73 | + if (i < mok_num - 1) |
| 74 | +@@ -523,7 +526,8 @@ delete_data_from_list (const efi_guid_t *var_guid, const char *var_name, |
| 75 | + remain = total; |
| 76 | + for (unsigned int i = 0; i < mok_num; i++) { |
| 77 | + remain -= list[i].header->SignatureListSize; |
| 78 | +- if (efi_guid_cmp (&list[i].header->SignatureType, type) != 0) |
| 79 | ++ efi_guid_t sigtype = list[i].header->SignatureType; |
| 80 | ++ if (efi_guid_cmp (&sigtype, type) != 0) |
| 81 | + continue; |
| 82 | + |
| 83 | + sig_list_size = list[i].header->SignatureListSize; |
| 84 | +@@ -1057,7 +1061,8 @@ is_duplicate (const efi_guid_t *type, const void *data, const uint32_t data_size |
| 85 | + } |
| 86 | + |
| 87 | + for (unsigned int i = 0; i < node_num; i++) { |
| 88 | +- if (efi_guid_cmp (&list[i].header->SignatureType, type) != 0) |
| 89 | ++ efi_guid_t sigtype = list[i].header->SignatureType; |
| 90 | ++ if (efi_guid_cmp (&sigtype, type) != 0) |
| 91 | + continue; |
| 92 | + |
| 93 | + if (efi_guid_cmp (type, &efi_guid_x509_cert) == 0) { |
| 94 | +@@ -1510,8 +1515,8 @@ issue_hash_request (const char *hash_str, MokRequest req, |
| 95 | + goto error; |
| 96 | + /* Check if there is a signature list with the same type */ |
| 97 | + for (unsigned int i = 0; i < mok_num; i++) { |
| 98 | +- if (efi_guid_cmp (&mok_list[i].header->SignatureType, |
| 99 | +- &hash_type) == 0) { |
| 100 | ++ efi_guid_t sigtype = mok_list[i].header->SignatureType; |
| 101 | ++ if (efi_guid_cmp (&sigtype, &hash_type) == 0) { |
| 102 | + merge_ind = i; |
| 103 | + list_size -= sizeof(EFI_SIGNATURE_LIST); |
| 104 | + break; |
| 105 | +@@ -1678,8 +1683,9 @@ export_db_keys (const DBName db_name) |
| 106 | + for (unsigned i = 0; i < mok_num; i++) { |
| 107 | + off_t offset = 0; |
| 108 | + ssize_t write_size; |
| 109 | ++ efi_guid_t sigtype = list[i].header->SignatureType; |
| 110 | + |
| 111 | +- if (efi_guid_cmp (&list[i].header->SignatureType, &efi_guid_x509_cert) != 0) |
| 112 | ++ if (efi_guid_cmp (&sigtype, &efi_guid_x509_cert) != 0) |
| 113 | + continue; |
| 114 | + |
| 115 | + /* Dump X509 certificate to files */ |
0 commit comments