From nobody@FreeBSD.org  Sun Aug 19 00:53:02 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 9B43037B411
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 19 Aug 2001 00:53:02 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id f7J7r2J31957;
	Sun, 19 Aug 2001 00:53:02 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200108190753.f7J7r2J31957@freefall.freebsd.org>
Date: Sun, 19 Aug 2001 00:53:02 -0700 (PDT)
From: Steve Whiteley <stevew@wrcad.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: 4.3 timed master can't sync Red Hat Linux 6.0 box
X-Send-Pr-Version: www-1.0

>Number:         29867
>Category:       misc
>Synopsis:       4.3 timed master can't sync Red Hat Linux 6.0 box
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kris
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 19 01:00:08 PDT 2001
>Closed-Date:    Sun Aug 19 23:16:42 PDT 2001
>Last-Modified:  Sun Aug 19 23:17:04 PDT 2001
>Originator:     Steve Whiteley
>Release:        4.3-stable
>Organization:
Whiteley Research Inc.
>Environment:
FreeBSD chaucer.srware.com 4.3-RC FreeBSD 4.3-RC #2:
Sun Apr 22 14:16:02 PDT 2001     stevew@chaucer.srware.com:/usr3/obj/usr/src/sys/CHAUCER  i386
>Description:
Running timed as master, to synchronize a Red Hat Linux 6.0 box.  This
worked with FBSD3.5, after upgrading to 4.3, got console error
"short packet (xx/xx bytes) from keats"
(The real message included the byte counts.)
There appeared to be no clock sync.
>How-To-Repeat:
boot and run
>Fix:
The problem is that the sizeof(struct tsp) differs on the two systems.
Made the following change in readmsg.c near line 215, which seems to have fixed the problem.
----------------------------------------------------------------------
        length = sizeof(from);
        if ((n = recvfrom(sock, (char *)&msgin, sizeof(struct tsp), 0,
                 (struct sockaddr*)&from, &length)) < 0) {
            syslog(LOG_ERR, "recvfrom: %m");
            exit(1);
        }
/* SRW */
/* Here is a bug: the sizeof(struct tsp) is OS dependent, depending on the
 * length of the tsp_name field (MAXHOSTNAMELEN) which is, e.g., 256 for
 * FreeBSD 4.3 and 64 for RH Linux 6.0.  Keep this as a sanity check,
 * but assume that the name field is 64 or larger
 */  
        if (n < (ssize_t)sizeof(struct tsp) - MAXHOSTNAMELEN + 64) {
/*
        if (n < (ssize_t)sizeof(struct tsp)) {
*/
            syslog(LOG_NOTICE,
                "short packet (%u/%u bytes) from %s",
                  n, sizeof(struct tsp),
                  inet_ntoa(from.sin_addr));
            continue;  
        }

>Release-Note:
>Audit-Trail:

From: Kris Kennaway <kris@obsecurity.org>
To: Steve Whiteley <stevew@wrcad.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/29867: 4.3 timed master can't sync Red Hat Linux 6.0 box
Date: Sun, 19 Aug 2001 02:18:52 -0700

 --4zI0WCX1RcnW9Hbu
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 > The problem is that the sizeof(struct tsp) differs on the two systems.
 > Made the following change in readmsg.c near line 215, which seems to have=
  fixed the problem.
 > ----------------------------------------------------------------------
 >         length =3D sizeof(from);
 >         if ((n =3D recvfrom(sock, (char *)&msgin, sizeof(struct tsp), 0,
 >                  (struct sockaddr*)&from, &length)) < 0) {
 >             syslog(LOG_ERR, "recvfrom: %m");
 >             exit(1);
 >         }
 > /* SRW */
 > /* Here is a bug: the sizeof(struct tsp) is OS dependent, depending on the
 >  * length of the tsp_name field (MAXHOSTNAMELEN) which is, e.g., 256 for
 >  * FreeBSD 4.3 and 64 for RH Linux 6.0.  Keep this as a sanity check,
 >  * but assume that the name field is 64 or larger
 >  */ =20
 >         if (n < (ssize_t)sizeof(struct tsp) - MAXHOSTNAMELEN + 64) {
 > /*
 >         if (n < (ssize_t)sizeof(struct tsp)) {
 > */
 >             syslog(LOG_NOTICE,
 >                 "short packet (%u/%u bytes) from %s",
 >                   n, sizeof(struct tsp),
 >                   inet_ntoa(from.sin_addr));
 >             continue; =20
 >         }
 
 I think this is a more complete fix.  According to
 
   http://sunsite.berkeley.edu/Dienst/UI/2.0/Describe/ncstrl.ucb/CSD-85-250
 
 the original 4.3BSD code had sizeof(tsp.tsp_name) =3D=3D 32, so that's
 probably a safe minimum packet size to use.  Can you please test?
 
 Kris
 
 Index: timed/readmsg.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /mnt/ncvs/src/usr.sbin/timed/timed/readmsg.c,v
 retrieving revision 1.7
 diff -u -r1.7 readmsg.c
 --- timed/readmsg.c	2001/01/01 18:43:21	1.7
 +++ timed/readmsg.c	2001/08/19 09:14:07
 @@ -212,10 +212,15 @@
  			syslog(LOG_ERR, "recvfrom: %m");
  			exit(1);
  		}
 -		if (n < (ssize_t)sizeof(struct tsp)) {
 +		/*
 +		 * The 4.3BSD protocol spec had a 32-byte tsp_name field, and
 +		 * this is still OS-dependent.  Demand that the packet is at
 +		 * least long enough to hold a 4.3BSD packet.
 +		 */
 +		if (n < (ssize_t)(sizeof(struct tsp) - MAXHOSTNAMELEN + 32)) {
  			syslog(LOG_NOTICE,
  			    "short packet (%u/%u bytes) from %s",
 -			      n, sizeof(struct tsp),
 +			      n, sizeof(struct tsp) - MAXHOSTNAMELEN + 32,
  			      inet_ntoa(from.sin_addr));
  			continue;
  		}
 Index: timedc/cmds.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /mnt/ncvs/src/usr.sbin/timed/timedc/cmds.c,v
 retrieving revision 1.7
 diff -u -r1.7 cmds.c
 --- timedc/cmds.c	2001/05/09 08:37:18	1.7
 +++ timedc/cmds.c	2001/08/19 09:17:16
 @@ -332,10 +332,15 @@
  				warn("recvfrom");
  				continue;
  			}
 -			if (cc < sizeof(struct tsp)) {
 +			/*
 +			 * The 4.3BSD protocol spec had a 32-byte tsp_name field, and
 +			 * this is still OS-dependent.  Demand that the packet is at
 +			 * least long enough to hold a 4.3BSD packet.
 +			 */
 +			if (cc < (sizeof(struct tsp) - MAXHOSTNAMELEN + 32)) {
  				fprintf(stderr,=20
  				   "short packet (%u/%u bytes) from %s\n",
 -				   cc, sizeof(struct tsp),
 +				   cc, sizeof(struct tsp) - MAXHOSTNAMELEN + 32,
  				   inet_ntoa(from.sin_addr));
  				continue;
  			}
 @@ -484,9 +489,15 @@
  			warn("recvfrom");
  			return;
  		}
 -		if (cc < sizeof(struct tsp)) {
 -			fprintf(stderr, "short pack (%u/%u bytes) from %s\n",
 -			   cc, sizeof(struct tsp), inet_ntoa(from.sin_addr));
 +		/*
 +		 * The 4.3BSD protocol spec had a 32-byte tsp_name field, and
 +		 * this is still OS-dependent.  Demand that the packet is at
 +		 * least long enough to hold a 4.3BSD packet.
 +		 */
 +		if (cc < (sizeof(struct tsp) - MAXHOSTNAMELEN + 32)) {
 +			fprintf(stderr, "short packet (%u/%u bytes) from %s\n",
 +			    cc, sizeof(struct tsp) - MAXHOSTNAMELEN + 32,
 +			    inet_ntoa(from.sin_addr));
  			return;
  		}
  		bytehostorder(&msg);
 
 
 --4zI0WCX1RcnW9Hbu
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iD8DBQE7f4R7Wry0BWjoQKURAmHOAKCb8u6QOI/gl8VxPQOhIRpX5JIzzACdHL/Z
 sYN3B6/EEKDmbX9mpo5mFcI=
 =ODjL
 -----END PGP SIGNATURE-----
 
 --4zI0WCX1RcnW9Hbu--
State-Changed-From-To: open->analyzed 
State-Changed-By: kris 
State-Changed-When: Sun Aug 19 02:20:08 PDT 2001 
State-Changed-Why:  
I've developed a patch to correct this. 


Responsible-Changed-From-To: freebsd-bugs->kris 
Responsible-Changed-By: kris 
Responsible-Changed-When: Sun Aug 19 02:20:08 PDT 2001 
Responsible-Changed-Why:  

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29867 
State-Changed-From-To: analyzed->closed 
State-Changed-By: kris 
State-Changed-When: Sun Aug 19 23:16:42 PDT 2001 
State-Changed-Why:  
Patch committed.  I'll consult the release engineer about 
merging this into 4.4. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29867 
>Unformatted:
