Blame SOURCES/0317-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Javier Martinez Canillas <javierm@redhat.com>
80913e
Date: Mon, 24 Aug 2020 14:46:27 +0200
80913e
Subject: [PATCH] tftp: roll over block counter to prevent timeouts with data
80913e
 packets
80913e
80913e
The block number is a 16-bit counter which only allows to fetch
80913e
files no bigger than 65535 * blksize. To avoid this limit, the
80913e
counter is rolled over. This behavior isn't defined in RFC 1350
80913e
but is handled by many TFTP servers and it's what GRUB was doing
80913e
before implicitly due an overflow.
80913e
80913e
Fixing that bug led to TFTP timeouts, since GRUB wasn't acking
80913e
data packets anymore for files with size bigger than the maximum
80913e
mentioned above. Restore the old behavior to prevent this issue.
80913e
80913e
Resolves: rhbz#1871034
80913e
80913e
Suggested-by: Peter Jones <pjones@redhat.com>
80913e
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
80913e
---
80913e
 grub-core/net/tftp.c | 16 ++++++++++++++--
80913e
 1 file changed, 14 insertions(+), 2 deletions(-)
80913e
80913e
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
b32e65
index 79c16f9b0..b9a4b607a 100644
80913e
--- a/grub-core/net/tftp.c
80913e
+++ b/grub-core/net/tftp.c
80913e
@@ -183,8 +183,20 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
80913e
 	  return GRUB_ERR_NONE;
80913e
 	}
80913e
 
80913e
-      /* Ack old/retransmitted block. */
80913e
-      if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1)
80913e
+      /*
80913e
+       * Ack old/retransmitted block.
80913e
+       *
80913e
+       * The block number is a 16-bit counter which only allows to fetch
80913e
+       * files no bigger than 65535 * blksize. To avoid this limit, the
80913e
+       * counter is rolled over. This behavior isn't defined in RFC 1350
80913e
+       * but is handled by many TFTP servers and it's what GRUB was doing
80913e
+       * before implicitly due an overflow.
80913e
+       *
80913e
+       * Fixing that bug led to TFTP timeouts, since GRUB wasn't acking
80913e
+       * data packets anymore for files with size bigger than the maximum
80913e
+       * mentioned above. Restore the old behavior to prevent this issue.
80913e
+       */
80913e
+      if (grub_be_to_cpu16 (tftph->u.data.block) < ((data->block + 1) & 0xffffu))
80913e
 	ack (data, grub_be_to_cpu16 (tftph->u.data.block));
80913e
       /* Ignore unexpected block. */
80913e
       else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1)