From owner-freebsd-net@FreeBSD.ORG Thu Jan 9 22:26:11 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C4D07366; Thu, 9 Jan 2014 22:26:11 +0000 (UTC) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9B7A715CD; Thu, 9 Jan 2014 22:26:11 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id s09MQAGw058049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 9 Jan 2014 14:26:10 -0800 (PST) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id s09MQAlA058048; Thu, 9 Jan 2014 14:26:10 -0800 (PST) (envelope-from jmg) Date: Thu, 9 Jan 2014 14:26:10 -0800 From: John-Mark Gurney To: Guy Yur Subject: Re: 10.0-RC1, armv6: "pfctl -s state" crashes on BeagleBone Black due to unaligned access Message-ID: <20140109222610.GJ46596@funkthat.com> Mail-Followup-To: Guy Yur , Gleb Smirnoff , freebsd-net@freebsd.org, freebsd-arm@freebsd.org References: <20140109104223.GS71033@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Thu, 09 Jan 2014 14:26:10 -0800 (PST) Cc: freebsd-net@freebsd.org, freebsd-arm@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jan 2014 22:26:11 -0000 Guy Yur wrote this message on Fri, Jan 10, 2014 at 00:17 +0200: > On Thu, Jan 9, 2014 at 12:42 PM, Gleb Smirnoff wrote: > > Guy, > > > > On Sat, Jan 04, 2014 at 03:06:02PM +0200, Guy Yur wrote: > > G> I am running 10.0-RC1 arm.armv6 on the BeagleBone Black. > > G> The "pfctl -s state" command is crashing when trying to print the > > G> second entry. > > > G> > > G> (gdb) bt > > G> #0 print_host (addr=0x2085a11a, port=7660, af=2 '\002', opts=1024) at > > G> /usr/src/sbin/pfctl/pf_print_state.c:178 > > G> #1 0x00021c4c in print_state (s=0x2085a0f2, opts=1024) at > > G> /usr/src/sbin/pfctl/pf_print_state.c:236 > > G> #2 0x0000c664 in pfctl_show_states (dev=, > > G> iface=0x0, opts=1024) at /usr/src/sbin/pfctl/pfctl.c:1095 > > G> > > G> sizeof(struct pfsync_state_key) is 36 > > G> sizeof(struct pfsync_state_peer) is 32 > > G> sizeof(struct pf_addr) is 16 > > G> sizeof(struct pfsync_state) is 242 > > G> > > > > > I will try to fix this making new structure for the ioctl. That will mean > > moving slowly towards divorcing internal structures and ioctl ones. > > > > I'd appreciate if you file a PR on that, so that problem won't leave forgotten > > in the mailing list. You can even code the bugfix :) > > > > Thanks! > > > > -- > > Totus tuus, Glebius. > > I filled arm/185617 with some updated information. > > After further looking at why the kernel doesn't crash when filling > the pfsync_state array and only the userspace pfctl is crashing I > see that pfsync_state has the __packed attribute which means on arm > unaligned access is used so there is no problem handling an unaligned > pfsync_state. > > The reason pfctl crashes is because it passes a structure field > as a pf_addr pointer. struct pf_addr is not __packed so on arm > word access will be used, triggering the unaligned fault. > > So there is indeed no need to break the pfsync protocol. > > In if_pfsync.c I think all the accesses to pfsync_state are done using > a pfsync_state pointer, there is no passing of struct fields as > separate pointers and since the struct is covered by __packed > there won't be an unaligned access. Ok, that makes sense... so, either we mark struct pf_addr as __packed, or we do some nasty stuff, like the following in print_host: struct { struct pf_addr a } *uaddr __packed; uaddr = addr; aw.v.a.addr = uaddr->a; it's not pretty, but I believe it would work... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."