NetBSD Problem Report #14124
Received: (qmail 27755 invoked from network); 2 Oct 2001 07:57:31 -0000
Message-Id: <20011002075715.03E1A11112@www.netbsd.org>
Date: Tue, 2 Oct 2001 00:57:15 -0700 (PDT)
From: guy@alum.mit.edu
Sender: nobody@netbsd.org
Reply-To: guy@alum.mit.edu
To: gnats-bugs@gnats.netbsd.org
Subject: "ip_dooptions()" might dereference unaligned pointer on Alpha
X-Send-Pr-Version: www-1.0
>Number: 14124
>Category: kern
>Synopsis: "ip_dooptions()" might dereference unaligned pointer on Alpha
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 02 07:58:00 +0000 2001
>Closed-Date: Sun Nov 22 21:56:14 +0000 2009
>Last-Modified: Sun Nov 22 21:56:14 +0000 2009
>Originator: Guy Harris
>Release:
>Organization:
>Environment:
>Description:
At Network Appliance, we have a BSD-derived networking stack; one of
our Alpha-based machines crashed due to an incoming IP packet that
had a 15-byte Record Route option followed by a Timestamp option.
The code that processes the Timestamp option casts the pointer to the
beginning of the option to a pointer to a "struct ip_timestamp" and
dereferences that pointer.
The only fields it fetches or sets via that pointer are one-byte
fields; however, at least with the version of GCC we are using
at NetApp, the code the compiler generates to fetch from and store
into those one-byte fields assumes that the structure is aligned
on a 4-byte boundary. (We don't tell the compiler to generate code
to use the BWX extensions, so it generates loads and extracts, and
it generates a load rather than a "load unaligned".)
This meant that the code attempted to dereference an unaligned pointer,
as the 15-byte Record Route option put the next option on an odd-byte
boundary.
>How-To-Repeat:
If the generated Alpha kernel code does an aligned load, send to
an Alpha machine a packet with a Record Route option (which should
contain an odd number of bytes) followed immediately (with no padding)
by a Timestamp option.
>Fix:
Changing the code that processes time stamp options to
code = cp - (u_char *)ip;
if (cp[IPOPT_OLEN] < 4 || cp[IPOPT_OLEN] > 40) {
code = &cp[IPOPT_OLEN] - (u_char *)ip;
goto bad;
}
if (cp[IPOPT_OFFSET] < 5) {
code = &cp[IPOPT_OFFSET] - (u_char *)ip;
goto bad;
}
if (cp[IPOPT_OFFSET] > cp[IPOPT_OLEN] - sizeof(int32_t)) {
/* Increment the overflow counter. */
cp[3] += 0x10;
if ((cp[3] & 0xF0) == 0) {
/* The overflow counter overflowed. */
code = &cp[IPOPT_OFFSET] -
(u_char *)ip;
goto bad;
}
break;
}
cp0 = (cp + cp[IPOPT_OFFSET] - 1);
switch (cp[3] & 0x0F) {
case IPOPT_TS_TSONLY:
break;
case IPOPT_TS_TSANDADDR:
if (cp[IPOPT_OFFSET] - 1 + sizeof(n_time) +
sizeof(struct in_addr) > cp[IPOPT_OLEN]) {
code = &cp[IPOPT_OFFSET] -
(u_char *)ip;
goto bad;
}
ipaddr.sin_addr = dst;
ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr),
m->m_pkthdr.rcvif));
if (ia == 0)
continue;
bcopy(ia->ia_addr.sin_addr,
cp0, sizeof(struct in_addr));
cp[IPOPT_OFFSET] += sizeof(struct in_addr);
break;
case IPOPT_TS_PRESPEC:
if (cp[IPOPT_OFFSET] - 1 + sizeof(n_time) +
sizeof(struct in_addr) > cp[IPOPT_OLEN]) {
code = &cp[IPOPT_OFFSET] -
(u_char *)ip;
goto bad;
}
bcopy(cp0, &ipaddr.sin_addr,
sizeof(struct in_addr));
if (ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)))
== NULL)
continue;
cp[IPOPT_OFFSET] += sizeof(struct in_addr);
break;
default:
code = &cp[3] - (u_char *)ip;
goto bad;
}
ntime = iptime();
cp0 = (u_char *) &ntime; /* XXX grumble, GCC... */
bcopy(cp0, (caddr_t)cp + cp[IPOPT_OFFSET] - 1,
sizeof(n_time));
cp[IPOPT_OFFSET] += sizeof(n_time);
should, I think, do it.
>Release-Note:
>Audit-Trail:
From: itojun@iijlab.net
To: guy@alum.mit.edu
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14124: "ip_dooptions()" might dereference unaligned pointer on Alpha
Date: Tue, 02 Oct 2001 17:34:00 +0900
>>Synopsis: "ip_dooptions()" might dereference unaligned pointer on Alpha
a similar bug report was made from you to openbsd (bug@openbsd),
with a different description of cause. any reasons why you reported it
differently? or did you have different problem between openbsd and
netbsd?
itojun
From: itojun@iijlab.net
To: guy@alum.mit.edu
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14124: "ip_dooptions()" might dereference unaligned pointer on Alpha
Date: Wed, 03 Oct 2001 15:23:26 +0900
>>Synopsis: "ip_dooptions()" might dereference unaligned pointer on Alpha
does it help if we add "__attribute__((__packed__))" to ip_timestamp
itself? i got no alpha boxes to try it out.
itojun
Index: ip.h
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip.h,v
retrieving revision 1.21
diff -u -r1.21 ip.h
--- ip.h 2000/05/02 14:15:07 1.21
+++ ip.h 2001/10/03 06:22:55
@@ -149,7 +149,7 @@
n_time ipt_time;
} ipt_ta[1] __attribute__((__packed__));
} ipt_timestamp __attribute__((__packed__));
-};
+} __attribute__((__packed__));
/* flag bits for ipt_flg */
#define IPOPT_TS_TSONLY 0 /* timestamps only */
State-Changed-From-To: open->closed
State-Changed-By: dsl@NetBSD.org
State-Changed-When: Sun, 22 Nov 2009 21:56:14 +0000
State-Changed-Why:
Structure marked __packed in rev 1.22 befor 1.6
>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.