ia64/81284: Unaligned Reference with pf on 5.4/IA64

Marcel Moolenaar marcel at xcllnt.net
Wed Jun 15 22:57:37 GMT 2005


On Jun 15, 2005, at 3:34 PM, Daniel Hartmeier wrote:

> On Wed, Jun 15, 2005 at 02:23:24PM -0700, Marcel Moolenaar wrote:
>
>> 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.
>
> 'packed', as I understand it, prohibits the compiler from inserting any
> padding anywhere in the struct. That is, it guarantees that the total
> size of a struct object equals the sum of the sizes of its members.
>
> As a consequence, individual members can't be aligned properly if that
> would require padding in front of them. The compiler can (and must?)
> still align the first member, i.e. the beginning of the struct object,
> though, no?

No, it can't guarantee alignment of the first field and consequently
will not bother trying. The best way to picture this is with an array.
Alignment guarantees has to come from the implementation, the compiler
will not guarantee alignment.

> So, are you really sure we should do differently in pf, instead of
> looking for a bridge problem, where bridge constructs an mbuf with the
> IP header not properly aligned?

I've not been sure to begin with. I forwarded this PR because I have
no clue as to where the root problem is. If you say that pf(4) is not
at fault and it's the bridge code then fine, fix the bridge code. All
I see is an unaligned memory access and plenty of yellow flags in the
source code.

> I.e. if the IP header is properly aligned within the mbuf (on 32-bit
> boundaries, I presume), wouldn't ip_src/dst have to be properly aligned
> as well, even though __packed is used, because the layout of struct ip
> is chosen like that?

Yes.

-- 
  Marcel Moolenaar         USPA: A-39004          marcel at xcllnt.net



More information about the freebsd-pf mailing list