[PATCH] shim_lock: Disable GRUB_VERIFY_FLAGS_DEFER_AUTH if secure boot off

2020-09-10 Thread Michael Chang
The GRUB_VERIFY_FLAGS_DEFER_AUTH is enabled regardless secure boot
status that will cause error [1] on loading external grub modules if
secure boot turned off in which shim protocol itself did not verify
images so should not request verification for external modules either.

This patch fixed the problem by adding the secure boot status check
before requesting other verifiers to verify external module, therefore
external module loading can work after shim_lock module loaded and
secure boot turned off.

[1] error: verification requested but nobody cares:
(hd0,gpt10)/boot/grub2/x86_64-efi/linux.mod.

Signed-off-by: Michael Chang 
---
 grub-core/commands/efi/shim_lock.c | 31 +-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/grub-core/commands/efi/shim_lock.c 
b/grub-core/commands/efi/shim_lock.c
index 764098cfc..e0da81ce5 100644
--- a/grub-core/commands/efi/shim_lock.c
+++ b/grub-core/commands/efi/shim_lock.c
@@ -45,6 +45,34 @@ static grub_efi_shim_lock_protocol_t *sl;
 /* List of modules which cannot be loaded if UEFI secure boot mode is enabled. 
*/
 static const char * const disabled_mods[] = {"iorw", "memrw", "wrmsr", NULL};
 
+static grub_efi_boolean_t
+grub_efi_secure_boot (void)
+{
+  grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  grub_size_t datasize;
+  char *secure_boot = NULL;
+  char *setup_mode = NULL;
+  grub_efi_boolean_t ret = 0;
+
+  secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize);
+
+  if (datasize != 1 || !secure_boot)
+goto out;
+
+  setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize);
+
+  if (datasize != 1 || !setup_mode)
+goto out;
+
+  if (*secure_boot && !*setup_mode)
+ret = 1;
+
+ out:
+  grub_free (secure_boot);
+  grub_free (setup_mode);
+  return ret;
+}
+
 static grub_err_t
 shim_lock_init (grub_file_t io, enum grub_file_type type,
void **context __attribute__ ((unused)),
@@ -82,7 +110,8 @@ shim_lock_init (grub_file_t io, enum grub_file_type type,
 
 case GRUB_FILE_TYPE_ACPI_TABLE:
 case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE:
-  *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH;
+  if (grub_efi_secure_boot())
+   *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH;
 
   return GRUB_ERR_NONE;
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] tftp: roll-over block counter to prevent data packets timeouts

2020-09-10 Thread Javier Martinez Canillas
On 9/10/20 12:00 AM, Alexey Makhalov wrote:

[snip]

> Fixes: 781b3e5efc3 ("tftp: Do not use priority queue")

 Please drop this line.

>>>
>>> Same question here. I think is important information, specially for
>>> downstream since they could allow people to decide whether they need
>>> to backport this patch or not.
>>
>> You duplicate the information which is above. Additionally, IMO "Fixes:"
>> should contain bug number, CVE number, link to the bug, etc. not the
>> commit id.
> 
> I think “Fixes: commit id” should remain in place. It provides direct 
> information
> from what commit the bug existed in case of regression.
>

Yes, I think the same. For example I usually do git log --grep="Fixes:", but
don't have a strong opinion and I'm OK with dropping it if Daniel prefer that.

Best regards,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] tftp: roll-over block counter to prevent data packets timeouts

2020-09-10 Thread Daniel Kiper
On Thu, Sep 10, 2020 at 12:07:42PM +0200, Javier Martinez Canillas wrote:
> On 9/10/20 12:00 AM, Alexey Makhalov wrote:
>
> [snip]
>
> > Fixes: 781b3e5efc3 ("tftp: Do not use priority queue")
> 
>  Please drop this line.
> 
> >>>
> >>> Same question here. I think is important information, specially for
> >>> downstream since they could allow people to decide whether they need
> >>> to backport this patch or not.
> >>
> >> You duplicate the information which is above. Additionally, IMO "Fixes:"
> >> should contain bug number, CVE number, link to the bug, etc. not the
> >> commit id.
> >
> > I think “Fixes: commit id” should remain in place. It provides direct 
> > information
> > from what commit the bug existed in case of regression.
> >
>
> Yes, I think the same. For example I usually do git log --grep="Fixes:", but
> don't have a strong opinion and I'm OK with dropping it if Daniel prefer that.

If more people like it I am not going to object so strongly...

Daniel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2] tftp: roll-over block counter to prevent data packets timeouts

2020-09-10 Thread Javier Martinez Canillas
Commit 781b3e5efc3 (tftp: Do not use priority queue) caused a regression
when fetching files over TFTP whose size is bigger than 65535 * block size.

  grub> linux /images/pxeboot/vmlinuz
  grub> echo $?
  0
  grub> initrd /images/pxeboot/initrd.img
  error: timeout reading '/images/pxeboot/initrd.img'.
  grub> echo $?
  28

It is caused by the block number counter being a 16-bit field, which leads
to a maximum file size of ((1 << 16) - 1) * block size. Because GRUB sets
the block size to 1024 octets (by using the TFTP Blocksize Option from RFC
2348 [0]), the maximum file size that can be transferred is 67107840 bytes.

The TFTP PROTOCOL (REVISION 2) RFC 1350 [1] does not mention what a client
should do when a file size is bigger than the maximum, but most TFTP hosts
support the block number counter to be rolled over. That is, acking a data
packet with a block number of 0 is taken as if the 65356th block was acked.

It was working before because the block counter roll-over was happening due
an overflow. But that got fixed by the mentioned commit, which led to the
regression when attempting to fetch files larger than the maximum size.

To allow TFTP file transfers of unlimited size again, re-introduce a block
counter roll-over so the data packets are acked preventing the timeouts.

[0]: https://tools.ietf.org/html/rfc2348
[1]: https://tools.ietf.org/html/rfc1350

Fixes: 781b3e5efc3 (tftp: Do not use priority queue)
Suggested-by: Peter Jones 
Signed-off-by: Javier Martinez Canillas 

---

Changes in v2:
- Remove unnecessary quotes when referring to a commit.
- Use type casting instead of a mask to roll-over.

 grub-core/net/tftp.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
index 644135caf46..ec85fce3b1b 100644
--- a/grub-core/net/tftp.c
+++ b/grub-core/net/tftp.c
@@ -183,11 +183,22 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ 
((unused)),
  return GRUB_ERR_NONE;
}
 
-  /* Ack old/retransmitted block. */
-  if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1)
+  /*
+   * Ack old/retransmitted block.
+   *
+   * The block number is a 16-bit counter, thus the maximum file size that
+   * could be transfered is 65535 * block size. Most TFTP hosts support to
+   * roll-over the block counter to allow unlimited transfer file size.
+   *
+   * This behavior is not defined in the RFC 1350 [0] but is implemented by
+   * most TFTP clients and hosts.
+   *
+   * [0]: https://tools.ietf.org/html/rfc1350
+   */
+  if (grub_be_to_cpu16 (tftph->u.data.block) < 
((grub_uint16_t)(data->block + 1)))
ack (data, grub_be_to_cpu16 (tftph->u.data.block));
   /* Ignore unexpected block. */
-  else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1)
+  else if (grub_be_to_cpu16 (tftph->u.data.block) > 
((grub_uint16_t)(data->block + 1)))
grub_dprintf ("tftp", "TFTP unexpected block # %d\n", 
tftph->u.data.block);
   else
{
-- 
2.28.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v2] tftp: roll-over block counter to prevent data packets timeouts

2020-09-10 Thread Daniel Kiper
On Thu, Sep 10, 2020 at 05:17:57PM +0200, Javier Martinez Canillas wrote:
> Commit 781b3e5efc3 (tftp: Do not use priority queue) caused a regression
> when fetching files over TFTP whose size is bigger than 65535 * block size.
>
>   grub> linux /images/pxeboot/vmlinuz
>   grub> echo $?
>   0
>   grub> initrd /images/pxeboot/initrd.img
>   error: timeout reading '/images/pxeboot/initrd.img'.
>   grub> echo $?
>   28
>
> It is caused by the block number counter being a 16-bit field, which leads
> to a maximum file size of ((1 << 16) - 1) * block size. Because GRUB sets
> the block size to 1024 octets (by using the TFTP Blocksize Option from RFC
> 2348 [0]), the maximum file size that can be transferred is 67107840 bytes.
>
> The TFTP PROTOCOL (REVISION 2) RFC 1350 [1] does not mention what a client
> should do when a file size is bigger than the maximum, but most TFTP hosts
> support the block number counter to be rolled over. That is, acking a data
> packet with a block number of 0 is taken as if the 65356th block was acked.
>
> It was working before because the block counter roll-over was happening due
> an overflow. But that got fixed by the mentioned commit, which led to the
> regression when attempting to fetch files larger than the maximum size.
>
> To allow TFTP file transfers of unlimited size again, re-introduce a block
> counter roll-over so the data packets are acked preventing the timeouts.
>
> [0]: https://tools.ietf.org/html/rfc2348
> [1]: https://tools.ietf.org/html/rfc1350
>
> Fixes: 781b3e5efc3 (tftp: Do not use priority queue)
> Suggested-by: Peter Jones 
> Signed-off-by: Javier Martinez Canillas 

Reviewed-by: Daniel Kiper 

Daniel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel