From owner-freebsd-net@FreeBSD.ORG Wed Jun 15 21:23:49 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D979916A41C; Wed, 15 Jun 2005 21:23:49 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 56F9D43D48; Wed, 15 Jun 2005 21:23:48 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from [192.168.4.250] (dhcp50.pn.xcllnt.net [192.168.4.250]) by ns1.xcllnt.net (8.13.3/8.13.3) with ESMTP id j5FLNRvj008982; Wed, 15 Jun 2005 14:23:28 -0700 (PDT) (envelope-from marcel@xcllnt.net) In-Reply-To: <20050615204232.GX8526@insomnia.benzedrine.cx> References: <200506132123.j5DLNove069255@freefall.freebsd.org> <20050615204232.GX8526@insomnia.benzedrine.cx> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Marcel Moolenaar Date: Wed, 15 Jun 2005 14:23:24 -0700 To: Daniel Hartmeier X-Mailer: Apple Mail (2.622) Cc: freebsd-net@freebsd.org, Marcel Moolenaar , freebsd-pf@freebsd.org Subject: Re: ia64/81284: Unaligned Reference with pf on 5.4/IA64 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2005 21:23:50 -0000 On Jun 15, 2005, at 1:42 PM, Daniel Hartmeier wrote: > On Mon, Jun 13, 2005 at 09:23:50PM +0000, Marcel Moolenaar wrote: > >> Synopsis: Unaligned Reference with pf on 5.4/IA64 >> >> Responsible-Changed-From-To: freebsd-net->freebsd-pf >> Responsible-Changed-By: marcel >> Responsible-Changed-When: Mon Jun 13 21:22:54 GMT 2005 >> Responsible-Changed-Why: >> Move to a more pf-focussed responsible party. >> >> http://www.freebsd.org/cgi/query-pr.cgi?pr=81284 > > If I understand the problem correctly, there is an underlying > network-generic question I'd like to ask here. > > When a function in the kernel gets passed a struct ip pointer, can it > assume that the struct ip object pointed to is properly aligned? Or > should it assume that this is not the case, and extract members more > carefully? That entirely depends. If a struct ip pointer is constructed without any form of casting, then one can assume that alignment is guaranteed. The compiler guarantees to do so, except of course in this case: the structure is defined as a packed structure. We, as the developers, have told the compiler to *NOT* guarantee alignment of fields. We're on our own and we miserably fail being on our own. > We can fix the access in pf of course, but if other functions > rightfully > count on struct ip objects being properly aligned, this might simply > crash outside of pf, too. True. But since struct ip is defined as packed, nobody can assume proper alignment of multi-byte fields and all code needs to be fixed if such assumptions are being made. > In short, is the problem that bridge doesn't properly align the struct > ip object (which I can try to fix, too), or that pf assumes that such > objects should be aligned? pf(4) falsely assumes alignment. > If I'm way off, and proper alignment of struct ip objects does not > guarantee proper alignment of the ip_src/dst members as 32-bit > unsigneds, please explain. You're not way off. It's just that we tried to outsmart ourselves by telling the compiler that it should not enforce proper alignment of fields in struct ip. > If ia64 is different from other 64-bit > architectures (of which I only know amd64, sparc64 and alpha), please > explain what alignment rules there are for u_int32_t. ia64 is not different in this respect. That's why the bug is not specific to ia64. Note that amd64 may not be a perfect reference in this case because it's too much like i386, which does unaligned loads and stores. FYI, -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net