grub/grub-core/net
Javier Martinez Canillas a6838bbc67 tftp: Roll-over block counter to prevent data packets timeouts
Commit 781b3e5efc (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: 781b3e5efc (tftp: Do not use priority queue)

Suggested-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-09-11 15:52:07 +02:00
..
drivers ofnet: Fix build regression in grub_ieee1275_parse_bootpath() 2018-11-28 13:48:45 +01:00
arp.c Add Virtual LAN support. 2017-05-03 13:03:50 +02:00
bootp.c calloc: Use calloc() at most places 2020-07-29 16:55:47 +02:00
dns.c malloc: Use overflow checking primitives where we do complex allocations 2020-07-29 16:55:47 +02:00
ethernet.c Add Virtual LAN support. 2017-05-03 13:03:50 +02:00
http.c misc: Make grub_strtol() "end" pointers have safer const qualifiers 2020-02-28 12:41:29 +01:00
icmp.c arp, icmp: Fix handling in case of oversized or invalid packets. 2015-03-27 12:18:25 +01:00
icmp6.c net: fix ipv6 routing 2016-02-25 22:38:52 +03:00
ip.c net/dhcp: Make grub_net_process_dhcp() take an interface 2019-03-12 20:04:07 +01:00
net.c calloc: Use calloc() at most places 2020-07-29 16:55:47 +02:00
netbuff.c arp, icmp: Fix handling in case of oversized or invalid packets. 2015-03-27 12:18:25 +01:00
tcp.c tcp: fix memory leaks 2016-01-16 20:59:50 +03:00
tftp.c tftp: Roll-over block counter to prevent data packets timeouts 2020-09-11 15:52:07 +02:00
udp.c * grub-core/disk/ahci.c: Add needed explicit cast. 2013-08-21 21:02:14 +02:00