0002-Work-around-stuff-Waddress-of-packed-member-finds.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From 7c1d3d8116b78bf096b7b8c6da5486f37efeb75f Mon Sep 17 00:00:00 2001
  2. From: Peter Jones <pjones@redhat.com>
  3. Date: Mon, 13 May 2019 16:34:35 -0400
  4. Subject: [PATCH] Work around stuff -Waddress-of-packed-member finds.
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. In MokManager we get a lot of these:
  9. ../src/MokManager.c:1063:19: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
  10. 1063 | if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
  11. | ^~~~~~~~~~~~~~~
  12. The reason for this is that gnu-efi takes EFI_GUID * as its argument
  13. instead of VOID *, and there's nothing telling the compiler that it
  14. doesn't have alignment constraints on the input, so the compiler wants
  15. it to have 16-byte alignment.
  16. Just use CompareMem() for these, as that's all CompareGuid is calling
  17. anyway.
  18. Signed-off-by: Peter Jones <pjones@redhat.com>
  19. Upstream: 2cbf56b82a5102777b37c4f7f47c8cf058cea027
  20. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  21. ---
  22. MokManager.c | 12 +++++++-----
  23. 1 file changed, 7 insertions(+), 5 deletions(-)
  24. diff --git a/MokManager.c b/MokManager.c
  25. index 7e40a38..5d0a979 100644
  26. --- a/MokManager.c
  27. +++ b/MokManager.c
  28. @@ -22,6 +22,8 @@
  29. #define CERT_STRING L"Select an X509 certificate to enroll:\n\n"
  30. #define HASH_STRING L"Select a file to trust:\n\n"
  31. +#define CompareMemberGuid(x, y) CompareMem(x, y, sizeof(EFI_GUID))
  32. +
  33. typedef struct {
  34. UINT32 MokSize;
  35. UINT8 *Mok;
  36. @@ -1078,7 +1080,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
  37. continue;
  38. DataSize += sizeof(EFI_SIGNATURE_LIST);
  39. - if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
  40. + if (CompareMemberGuid(&(list[i].Type), &X509_GUID) == 0)
  41. DataSize += sizeof(EFI_GUID);
  42. DataSize += list[i].MokSize;
  43. }
  44. @@ -1100,7 +1102,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
  45. CertList->SignatureType = list[i].Type;
  46. CertList->SignatureHeaderSize = 0;
  47. - if (CompareGuid(&(list[i].Type), &X509_GUID) == 0) {
  48. + if (CompareMemberGuid(&(list[i].Type), &X509_GUID) == 0) {
  49. CertList->SignatureListSize = list[i].MokSize +
  50. sizeof(EFI_SIGNATURE_LIST) + sizeof(EFI_GUID);
  51. CertList->SignatureSize =
  52. @@ -1141,7 +1143,7 @@ static void delete_cert(void *key, UINT32 key_size,
  53. int i;
  54. for (i = 0; i < mok_num; i++) {
  55. - if (CompareGuid(&(mok[i].Type), &X509_GUID) != 0)
  56. + if (CompareMemberGuid(&(mok[i].Type), &X509_GUID) != 0)
  57. continue;
  58. if (mok[i].MokSize == key_size &&
  59. @@ -1192,7 +1194,7 @@ static void delete_hash_in_list(EFI_GUID Type, UINT8 * hash, UINT32 hash_size,
  60. sig_size = hash_size + sizeof(EFI_GUID);
  61. for (i = 0; i < mok_num; i++) {
  62. - if ((CompareGuid(&(mok[i].Type), &Type) != 0) ||
  63. + if ((CompareMemberGuid(&(mok[i].Type), &Type) != 0) ||
  64. (mok[i].MokSize < sig_size))
  65. continue;
  66. @@ -1356,7 +1358,7 @@ static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
  67. /* Search and destroy */
  68. for (i = 0; i < del_num; i++) {
  69. - if (CompareGuid(&(del_key[i].Type), &X509_GUID) == 0) {
  70. + if (CompareMemberGuid(&(del_key[i].Type), &X509_GUID) == 0) {
  71. delete_cert(del_key[i].Mok, del_key[i].MokSize,
  72. mok, mok_num);
  73. } else if (is_sha2_hash(del_key[i].Type)) {
  74. --
  75. 2.30.2