From owner-freebsd-net@FreeBSD.ORG Thu Jan 9 22:17:13 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 8B96EFB8; Thu, 9 Jan 2014 22:17:13 +0000 (UTC) Received: from mail-oa0-x233.google.com (mail-oa0-x233.google.com [IPv6:2607:f8b0:4003:c02::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3A7CE1509; Thu, 9 Jan 2014 22:17:13 +0000 (UTC) Received: by mail-oa0-f51.google.com with SMTP id m1so4138094oag.24 for ; Thu, 09 Jan 2014 14:17:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=d6OF2dt4gC2ZXrs+CdrqbvQa/AqP2T3QhBp8lcCF55I=; b=p3tNvc3F1jxp4ays/DLgj+IHafANlxpXPrdS9Jn6ZAv8DTduSScRfcggm8nKvfAFUV EdFgOIUBMETJH2UU05uMmVticEyFHv6gwgh0IxLtS09TMoCYufyZdKaqp2dyCpTmJiZK V81BfzTsiQW/44As/tW7luciMJpTK8FZgx/xlmaxMIh+aOnfDBItGzjEDfTxpfHAlZwy H6bbbm/IFQkF14PlmiSxY7nJmHYbr/JtzrcfsLmFzmew3Im6PGamYgDr7Lq2+VXPgBkJ Z+f3LieJVkgZRSR/qaEUIlh7Qk2Yrq2GYsFUavrcMfYeAQqX2qTOOON9UlWfowCzjsLe jqTQ== MIME-Version: 1.0 X-Received: by 10.182.221.230 with SMTP id qh6mr4225814obc.7.1389305832460; Thu, 09 Jan 2014 14:17:12 -0800 (PST) Received: by 10.76.20.82 with HTTP; Thu, 9 Jan 2014 14:17:12 -0800 (PST) In-Reply-To: <20140109104223.GS71033@FreeBSD.org> References: <20140109104223.GS71033@FreeBSD.org> Date: Fri, 10 Jan 2014 00:17:12 +0200 Message-ID: Subject: Re: 10.0-RC1, armv6: "pfctl -s state" crashes on BeagleBone Black due to unaligned access From: Guy Yur To: Gleb Smirnoff Content-Type: text/plain; charset=UTF-8 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:17:13 -0000 Hi, 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. Thanks, Guy