0004-MokManager-avoid-Werror-address-of-packed-member.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From f17f67fef7ae05cbad8609aacef41a448a2d8d54 Mon Sep 17 00:00:00 2001
  2. From: Jonas Witschel <diabonas@gmx.de>
  3. Date: Thu, 5 Sep 2019 10:39:37 +0200
  4. Subject: [PATCH] MokManager: avoid -Werror=address-of-packed-member
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. When compiling with GCC 9, there are a couple of errors of the form
  9. MokManager.c: In function ‘write_back_mok_list’:
  10. MokManager.c:1056:19: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
  11. 1056 | if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
  12. | ^~~~~~~~~~~~~~~
  13. Copying the member of the packed struct to a temporary variable and
  14. pointing to that variable solves the problem.
  15. Upstream: d57e53f3bddc4bc7299b3d5efd5ba8c547e8dfa5
  16. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  17. ---
  18. MokManager.c | 22 +++++++++++++---------
  19. 1 file changed, 13 insertions(+), 9 deletions(-)
  20. diff --git a/MokManager.c b/MokManager.c
  21. index e13400b..1a8d666 100644
  22. --- a/MokManager.c
  23. +++ b/MokManager.c
  24. @@ -1065,6 +1065,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
  25. EFI_STATUS efi_status;
  26. EFI_SIGNATURE_LIST *CertList;
  27. EFI_SIGNATURE_DATA *CertData;
  28. + EFI_GUID type;
  29. void *Data = NULL, *ptr;
  30. INTN DataSize = 0;
  31. int i;
  32. @@ -1080,8 +1081,8 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
  33. continue;
  34. DataSize += sizeof(EFI_SIGNATURE_LIST);
  35. - if (CompareMem(&(list[i].Type), &X509_GUID,
  36. - sizeof(EFI_GUID)) == 0)
  37. + type = list[i].Type; /* avoid -Werror=address-of-packed-member */
  38. + if (CompareGuid(&type, &X509_GUID) == 0)
  39. DataSize += sizeof(EFI_GUID);
  40. DataSize += list[i].MokSize;
  41. }
  42. @@ -1103,8 +1104,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
  43. CertList->SignatureType = list[i].Type;
  44. CertList->SignatureHeaderSize = 0;
  45. - if (CompareMem(&(list[i].Type), &X509_GUID,
  46. - sizeof(EFI_GUID)) == 0) {
  47. + if (CompareGuid(&(CertList->SignatureType), &X509_GUID) == 0) {
  48. CertList->SignatureListSize = list[i].MokSize +
  49. sizeof(EFI_SIGNATURE_LIST) + sizeof(EFI_GUID);
  50. CertList->SignatureSize =
  51. @@ -1142,11 +1142,12 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
  52. static void delete_cert(void *key, UINT32 key_size,
  53. MokListNode * mok, INTN mok_num)
  54. {
  55. + EFI_GUID type;
  56. int i;
  57. for (i = 0; i < mok_num; i++) {
  58. - if (CompareMem(&(mok[i].Type), &X509_GUID,
  59. - sizeof(EFI_GUID)) != 0)
  60. + type = mok[i].Type; /* avoid -Werror=address-of-packed-member */
  61. + if (CompareGuid(&type, &X509_GUID) != 0)
  62. continue;
  63. if (mok[i].MokSize == key_size &&
  64. @@ -1188,6 +1189,7 @@ static void mem_move(void *dest, void *src, UINTN size)
  65. static void delete_hash_in_list(EFI_GUID Type, UINT8 * hash, UINT32 hash_size,
  66. MokListNode * mok, INTN mok_num)
  67. {
  68. + EFI_GUID type;
  69. UINT32 sig_size;
  70. UINT32 list_num;
  71. int i, del_ind;
  72. @@ -1197,7 +1199,8 @@ static void delete_hash_in_list(EFI_GUID Type, UINT8 * hash, UINT32 hash_size,
  73. sig_size = hash_size + sizeof(EFI_GUID);
  74. for (i = 0; i < mok_num; i++) {
  75. - if ((CompareMem(&(mok[i].Type), &Type, sizeof(EFI_GUID)) != 0) ||
  76. + type = mok[i].Type; /* avoid -Werror=address-of-packed-member */
  77. + if ((CompareGuid(&type, &Type) != 0) ||
  78. (mok[i].MokSize < sig_size))
  79. continue;
  80. @@ -1253,6 +1256,7 @@ static void delete_hash_list(EFI_GUID Type, void *hash_list, UINT32 list_size,
  81. static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
  82. {
  83. EFI_STATUS efi_status;
  84. + EFI_GUID type;
  85. CHAR16 *db_name;
  86. CHAR16 *auth_name;
  87. CHAR16 *err_strs[] = { NULL, NULL, NULL };
  88. @@ -1361,8 +1365,8 @@ static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
  89. /* Search and destroy */
  90. for (i = 0; i < del_num; i++) {
  91. - if (CompareMem(&(del_key[i].Type), &X509_GUID,
  92. - sizeof(EFI_GUID)) == 0) {
  93. + type = del_key[i].Type; /* avoid -Werror=address-of-packed-member */
  94. + if (CompareGuid(&type, &X509_GUID) == 0) {
  95. delete_cert(del_key[i].Mok, del_key[i].MokSize,
  96. mok, mok_num);
  97. } else if (is_sha2_hash(del_key[i].Type)) {
  98. --
  99. 2.30.2