efibootmgr-fix-efivar-0.24.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. From cddc48752cbb1c0d74b581f8aa6b2d9e51fd69d9 Mon Sep 17 00:00:00 2001
  2. From: Peter Jones <pjones@redhat.com>
  3. Date: Thu, 25 Feb 2016 10:43:40 -0500
  4. Subject: [PATCH 1/3] efibootmgr: update for efivar 0.24
  5. As of 0.24 efi_loadopt_pathlen() and efi_loadopt_path() require a limit
  6. argument to avoid overruns of the input data.
  7. This patch adds reasonable limits to those calls.
  8. Signed-off-by: Peter Jones <pjones@redhat.com>
  9. ---
  10. src/efibootmgr/efibootmgr.c | 19 ++++++++++---------
  11. 1 file changed, 10 insertions(+), 9 deletions(-)
  12. diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c
  13. index a5b5bf9..09489ab 100644
  14. --- a/src/efibootmgr/efibootmgr.c
  15. +++ b/src/efibootmgr/efibootmgr.c
  16. @@ -219,13 +219,12 @@ warn_duplicate_name(list_t *boot_list)
  17. list_for_each(pos, boot_list) {
  18. boot = list_entry(pos, var_entry_t, list);
  19. - load_option = (efi_load_option *)
  20. - boot->data;
  21. - desc = efi_loadopt_desc(load_option);
  22. + load_option = (efi_load_option *)boot->data;
  23. + desc = efi_loadopt_desc(load_option, boot->data_size);
  24. if (!strcmp((char *)opts.label, (char *)desc)) {
  25. - fprintf(stderr, "** Warning ** : %.8s has same label %s\n",
  26. - boot->name,
  27. - opts.label);
  28. + fprintf(stderr,
  29. + "** Warning ** : %.8s has same label %s\n",
  30. + boot->name, opts.label);
  31. }
  32. }
  33. }
  34. @@ -821,8 +820,7 @@ show_boot_vars()
  35. list_for_each(pos, &boot_entry_list) {
  36. boot = list_entry(pos, var_entry_t, list);
  37. load_option = (efi_load_option *)boot->data;
  38. - description = efi_loadopt_desc(load_option);
  39. - dp = efi_loadopt_path(load_option);
  40. + description = efi_loadopt_desc(load_option, boot->data_size);
  41. if (boot->name)
  42. printf("%.8s", boot->name);
  43. else
  44. @@ -835,9 +833,12 @@ show_boot_vars()
  45. if (opts.verbose) {
  46. char *text_path = NULL;
  47. size_t text_path_len = 0;
  48. - uint16_t pathlen = efi_loadopt_pathlen(load_option);
  49. + uint16_t pathlen;
  50. ssize_t rc;
  51. + pathlen = efi_loadopt_pathlen(load_option,
  52. + boot->data_size);
  53. + dp = efi_loadopt_path(load_option, pathlen);
  54. rc = efidp_format_device_path(text_path, text_path_len,
  55. dp, pathlen);
  56. if (rc < 0)
  57. --
  58. 2.9.0
  59. From 62944db11c87a936368525e4b480d1a0af61fd5e Mon Sep 17 00:00:00 2001
  60. From: Peter Jones <pjones@redhat.com>
  61. Date: Thu, 25 Feb 2016 14:16:38 -0500
  62. Subject: [PATCH 2/3] efibootmgr: fix some types the compiler doesn't like.
  63. Basically uint8_t * vs char *.
  64. Signed-off-by: Peter Jones <pjones@redhat.com>
  65. ---
  66. src/lib/efi.c | 4 ++--
  67. 1 file changed, 2 insertions(+), 2 deletions(-)
  68. diff --git a/src/lib/efi.c b/src/lib/efi.c
  69. index c2b8152..91ed11e 100644
  70. --- a/src/lib/efi.c
  71. +++ b/src/lib/efi.c
  72. @@ -424,7 +424,7 @@ get_extra_args(uint8_t *data, ssize_t data_size)
  73. sz = efi_loadopt_args_as_ucs2(
  74. (uint16_t *)(data+off),
  75. data_size?data_size+off:0,
  76. - opts.argv[i]);
  77. + (uint8_t *)opts.argv[i]);
  78. if (sz < 0)
  79. return -1;
  80. off += sz;
  81. @@ -436,7 +436,7 @@ get_extra_args(uint8_t *data, ssize_t data_size)
  82. } else {
  83. sz = efi_loadopt_args_as_utf8(data+off,
  84. data_size?data_size+off:0,
  85. - opts.argv[i]);
  86. + (uint8_t *)opts.argv[i]);
  87. if (sz < 0)
  88. return -1;
  89. off += sz;
  90. --
  91. 2.9.0
  92. From 3d68945362177a762e6331a02b8896e38b984a12 Mon Sep 17 00:00:00 2001
  93. From: Peter Jones <pjones@redhat.com>
  94. Date: Thu, 3 Mar 2016 09:50:03 -0500
  95. Subject: [PATCH 3/3] Explicitly pass a mode to efi_set_variable() in all
  96. cases.
  97. We'll have to do this for efivar-0.24 .
  98. Signed-off-by: Peter Jones <pjones@redhat.com>
  99. ---
  100. src/efibootmgr/efibootmgr.c | 22 ++++++++++++++--------
  101. 1 file changed, 14 insertions(+), 8 deletions(-)
  102. diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c
  103. index 09489ab..d1d4fe2 100644
  104. --- a/src/efibootmgr/efibootmgr.c
  105. +++ b/src/efibootmgr/efibootmgr.c
  106. @@ -304,7 +304,7 @@ make_boot_var(list_t *boot_list)
  107. EFI_VARIABLE_BOOTSERVICE_ACCESS |
  108. EFI_VARIABLE_RUNTIME_ACCESS;
  109. rc = efi_set_variable(boot->guid, boot->name, boot->data,
  110. - boot->data_size, boot->attributes);
  111. + boot->data_size, boot->attributes, 0644);
  112. if (rc < 0)
  113. goto err;
  114. list_add_tail(&boot->list, boot_list);
  115. @@ -362,7 +362,8 @@ set_boot_u16(const char *name, uint16_t num)
  116. return efi_set_variable(EFI_GLOBAL_GUID, name, (uint8_t *)&num,
  117. sizeof (num), EFI_VARIABLE_NON_VOLATILE |
  118. EFI_VARIABLE_BOOTSERVICE_ACCESS |
  119. - EFI_VARIABLE_RUNTIME_ACCESS);
  120. + EFI_VARIABLE_RUNTIME_ACCESS,
  121. + 0644);
  122. }
  123. static int
  124. @@ -398,7 +399,7 @@ add_to_boot_order(uint16_t num)
  125. boot_order->data_size = new_data_size;
  126. rc = efi_set_variable(EFI_GLOBAL_GUID, "BootOrder", boot_order->data,
  127. - boot_order->data_size, boot_order->attributes);
  128. + boot_order->data_size, boot_order->attributes, 0644);
  129. free(boot_order->data);
  130. free(boot_order);
  131. return rc;
  132. @@ -452,7 +453,8 @@ remove_dupes_from_boot_order(void)
  133. boot_order->data_size = new_data_size;
  134. efi_del_variable(EFI_GLOBAL_GUID, "BootOrder");
  135. rc = efi_set_variable(EFI_GLOBAL_GUID, "BootOrder", boot_order->data,
  136. - boot_order->data_size, boot_order->attributes);
  137. + boot_order->data_size, boot_order->attributes,
  138. + 0644);
  139. free(boot_order->data);
  140. free(boot_order);
  141. return rc;
  142. @@ -501,7 +503,8 @@ remove_from_boot_order(uint16_t num)
  143. boot_order->data_size = sizeof(data[0]) * new_i;
  144. rc = efi_set_variable(EFI_GLOBAL_GUID, "BootOrder", boot_order->data,
  145. - boot_order->data_size, boot_order->attributes);
  146. + boot_order->data_size, boot_order->attributes,
  147. + 0644);
  148. all_done:
  149. free(boot_order->data);
  150. free(boot_order);
  151. @@ -801,7 +804,8 @@ set_boot_order(int keep_old_entries)
  152. rc = efi_set_variable(EFI_GLOBAL_GUID, "BootOrder", data, data_size,
  153. EFI_VARIABLE_NON_VOLATILE |
  154. EFI_VARIABLE_BOOTSERVICE_ACCESS |
  155. - EFI_VARIABLE_RUNTIME_ACCESS);
  156. + EFI_VARIABLE_RUNTIME_ACCESS,
  157. + 0644);
  158. free(data);
  159. return rc;
  160. }
  161. @@ -936,7 +940,8 @@ set_active_state()
  162. boot->name,
  163. boot->data,
  164. boot->data_size,
  165. - boot->attributes);
  166. + boot->attributes,
  167. + 0644);
  168. }
  169. }
  170. else if (opts.active == 0) {
  171. @@ -950,7 +955,8 @@ set_active_state()
  172. boot->name,
  173. boot->data,
  174. boot->data_size,
  175. - boot->attributes);
  176. + boot->attributes,
  177. + 0644);
  178. }
  179. }
  180. }
  181. --
  182. 2.9.0