NetBSD Problem Report #10076
Received: (qmail 15405 invoked from network); 8 May 2000 21:33:18 -0000
Message-Id: <200005082133.XAA01213@rangerover>
Date: Mon, 8 May 2000 23:33:57 +0200 (CEST)
From: Reinoud Zandijk <reinoud@rangerover>
Reply-To: zandijk@cs.utwente.nl
To: gnats-bugs@gnats.netbsd.org
Subject: 16MB limit in tftp / tftpd
X-Send-Pr-Version: 3.95
>Number: 10076
>Category: bin
>Synopsis: Due to a malicious block counter type, the tftp/tftpd has a maximum 16Mb size limit
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon May 08 21:34:02 +0000 2000
>Closed-Date: Mon Nov 06 05:06:02 +0000 2000
>Last-Modified: Mon Nov 06 05:06:02 +0000 2000
>Originator: Reinoud Zandijk
>Release: Mon May 1 CEST 2000 <NetBSD-current source date>
>Organization:
>Environment:
System: NetBSD rangerover 1.4X NetBSD 1.4X (config.rangerover) #0: Mon May 1 13:33:05 CEST 2000 reinoud@rangerover:/usr/sources/anon-cvs/syssrc/sys/arch/sparc/compile/config.rangerover sparc
>Description:
Every tftp request made for a file bigger than 16Mb, the transfer stops when the 16Mb is reached ... this is due to the block counter.
This counter is a signed short in the protocol, and so the maximum number of blocks is 16Mb/512 bytes = 32768 and will then wrap to a
negative number. Since the tftpd deamon and the tftp client also keep a counter for block numbering and is declared as an `int',
this counter won't wrap and thus breaking the protocol, for it can't resynchronise anymore
The code is tested on NetBSD/i386 and NetBSD/sparc
>How-To-Repeat:
Fetch a file from a NetBSD system that is bigger than 16Mb... it won't give you more than the 16Mb and then just not respond anymore.
>Fix:
Patching the following files by changing the type of the `block' counter from `int' to `signed short' :
===================================================================
RCS file: /pub/NetBSD-CVS/basesrc/libexec/tftpd/tftpd.c,v
retrieving revision 1.18
diff -c -r1.18 tftpd.c
*** tftpd.c 1999/07/12 20:17:09 1.18
--- tftpd.c 2000/05/08 21:20:45
***************
*** 592,598 ****
struct tftphdr *dp;
struct tftphdr *ap; /* ack packet */
int size, n;
! volatile int block;
signal(SIGALRM, timer);
dp = r_init();
--- 592,598 ----
struct tftphdr *dp;
struct tftphdr *ap; /* ack packet */
int size, n;
! volatile signed short block;
signal(SIGALRM, timer);
dp = r_init();
***************
*** 662,668 ****
struct tftphdr *dp;
struct tftphdr *ap; /* ack buffer */
int n, size;
! volatile int block;
signal(SIGALRM, timer);
dp = w_init();
--- 662,668 ----
struct tftphdr *dp;
struct tftphdr *ap; /* ack buffer */
int n, size;
! volatile signed short block;
signal(SIGALRM, timer);
dp = w_init();
===================================================================
and
===================================================================
RCS file: /pub/NetBSD-CVS/basesrc/usr.bin/tftp/tftp.c,v
retrieving revision 1.11
diff -c -r1.11 tftp.c
*** tftp.c 2000/01/21 17:08:36 1.11
--- tftp.c 2000/05/08 21:19:52
***************
*** 99,105 ****
struct tftphdr *ap; /* data and ack packets */
struct tftphdr *dp;
int n;
! volatile int block, size, convert;
volatile unsigned long amount;
struct sockaddr_storage from;
int fromlen;
--- 99,106 ----
struct tftphdr *ap; /* data and ack packets */
struct tftphdr *dp;
int n;
! volatile signed short block;
! volatile int size, convert;
volatile unsigned long amount;
struct sockaddr_storage from;
int fromlen;
***************
*** 218,224 ****
struct tftphdr *ap;
struct tftphdr *dp;
int n;
! volatile int block, size, firsttrip;
volatile unsigned long amount;
struct sockaddr_storage from;
int fromlen;
--- 219,226 ----
struct tftphdr *ap;
struct tftphdr *dp;
int n;
! volatile signed short block;
! volatile int size, firsttrip;
volatile unsigned long amount;
struct sockaddr_storage from;
int fromlen;
===================================================================
>Release-Note:
>Audit-Trail:
From: Matthias Drochner <M.Drochner@fz-juelich.de>
To: zandijk@cs.utwente.nl
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/10076: 16MB limit in tftp / tftpd
Date: Tue, 09 May 2000 12:54:11 +0200
reinoud@rangerover.netbsd.org said:
> This counter is a signed short in the protocol, and so the maximum
> number of blocks is 16Mb/512 bytes = 32768 and will then wrap to a
> negative number.
It would be cleaner to make the block counter (th_block
in <arpa/tftp.h>) unsigned.
(It is at least done so in Digital Unix.)
There is still a hard 32M limit, but we can't change it (unless
the blocksize option is used).
best regards
Matthias
From: Reinoud Zandijk <zandijk@cs.utwente.nl>
To: Matthias Drochner <M.Drochner@fz-juelich.de>
Cc: gnats-bugs@gnats.netbsd.org
Subject: bin/10076: 16MB limit in tftp / tftpd
Date: Wed, 10 May 2000 16:23:03 +0200 (CEST)
Hi Mattias,
On Tue, 9 May 2000, Matthias Drochner wrote:
> reinoud@rangerover.netbsd.org said:
hehe... that would be neat!
> > This counter is a signed short in the protocol, and so the maximum
> > number of blocks is 16Mb/512 bytes = 32768 and will then wrap to a
> > negative number.
>
> It would be cleaner to make the block counter (th_block
> in <arpa/tftp.h>) unsigned.
> (It is at least done so in Digital Unix.)
> There is still a hard 32M limit, but we can't change it (unless
> the blocksize option is used).
This is indeed the case when i try to download a huge file from my patched
NetBSD machine to a FreeBSD machine. FreeBSD has this `th_block' changed
to `unsigned short' indeed.
I've patched <arpa/tftp.h> too and with the following patch it will
successfully download and upload a 130Mb+ file from a patched NetBSD
machine to a patched NetBSD machine and still upload and download normally
from any other machine (the last one is a wierd extra ... not nessisary) :
root@rangerover 10> cvs -q diff -u basesrc
Index: basesrc/include/arpa/tftp.h
===================================================================
RCS file: /pub/NetBSD-CVS/basesrc/include/arpa/tftp.h,v
retrieving revision 1.5
diff -u -r1.5 tftp.h
--- tftp.h 1998/02/10 00:32:59 1.5
+++ tftp.h 2000/05/10 14:05:18
@@ -53,13 +53,13 @@
#define ERROR 05 /* error code */
struct tftphdr {
- short th_opcode; /* packet type */
+ short th_opcode; /* packet type */
union {
- short tu_block; /* block # */
- short tu_code; /* error code */
- char tu_stuff[1]; /* request packet stuff */
+ unsigned short tu_block; /* block # */
+ short tu_code; /* error code */
+ char tu_stuff[1]; /* request packet stuff */
} th_u;
- char th_data[1]; /* data or error string */
+ char th_data[1]; /* data or error string */
};
#define th_block th_u.tu_block
Index: basesrc/libexec/tftpd/tftpd.c
===================================================================
RCS file: /pub/NetBSD-CVS/basesrc/libexec/tftpd/tftpd.c,v
retrieving revision 1.18
diff -u -r1.18 tftpd.c
--- tftpd.c 1999/07/12 20:17:09 1.18
+++ tftpd.c 2000/05/10 14:05:48
@@ -592,7 +592,7 @@
struct tftphdr *dp;
struct tftphdr *ap; /* ack packet */
int size, n;
- volatile int block;
+ volatile unsigned short block;
signal(SIGALRM, timer);
dp = r_init();
@@ -662,7 +662,7 @@
struct tftphdr *dp;
struct tftphdr *ap; /* ack buffer */
int n, size;
- volatile int block;
+ volatile unsigned short block;
signal(SIGALRM, timer);
dp = w_init();
Index: basesrc/usr.bin/tftp/tftp.c
===================================================================
RCS file: /pub/NetBSD-CVS/basesrc/usr.bin/tftp/tftp.c,v
retrieving revision 1.11
diff -u -r1.11 tftp.c
--- tftp.c 2000/01/21 17:08:36 1.11
+++ tftp.c 2000/05/10 14:06:15
@@ -99,7 +99,8 @@
struct tftphdr *ap; /* data and ack packets */
struct tftphdr *dp;
int n;
- volatile int block, size, convert;
+ volatile unsigned short block;
+ volatile int size, convert;
volatile unsigned long amount;
struct sockaddr_storage from;
int fromlen;
@@ -218,7 +219,8 @@
struct tftphdr *ap;
struct tftphdr *dp;
int n;
- volatile int block, size, firsttrip;
+ volatile unsigned short block;
+ volatile int size, firsttrip;
volatile unsigned long amount;
struct sockaddr_storage from;
int fromlen;
Index: basesrc/usr.sbin/ipf/Makefile
===================================================================
RCS file: /pub/NetBSD-CVS/basesrc/usr.sbin/ipf/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- Makefile 2000/05/03 11:40:53 1.7
+++ Makefile 2000/05/10 14:06:35
@@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.7 2000/05/03 11:40:53 veego Exp $
-SUBDIR= ipf ipfstat ipfs ipftest ipmon ipnat ipresend ipsend
iptest rules
+SUBDIR= ipf ipfstat ipftest ipmon ipnat ipresend ipsend iptest
rules
.include <bsd.subdir.mk>
root@rangerover 11>
I've tested the code on NetBSD/i386 and NetBSD/sparc, and both function OK
Regards,
Reinoud
State-Changed-From-To: open->closed
State-Changed-By: tv
State-Changed-When: Sun Nov 5 21:05:37 PST 2000
State-Changed-Why:
This has been fixed in -current, although was just slightly too late for 1.5;
it should be pulled into 1.5.1.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.