Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Jan 2014 01:04:57 +0200
From:      Guy Yur <guyyur@gmail.com>
To:        Guy Yur <guyyur@gmail.com>, Gleb Smirnoff <glebius@freebsd.org>, freebsd-net@freebsd.org, freebsd-arm@freebsd.org
Subject:   Re: 10.0-RC1, armv6: "pfctl -s state" crashes on BeagleBone Black due to unaligned access
Message-ID:  <CAC67Hz--9ur8wLbqkB=aw8fK9MXjokZi9qULVa-ox_uubUz0vQ@mail.gmail.com>
In-Reply-To: <20140109222610.GJ46596@funkthat.com>
References:  <CAC67Hz_QXcHHSFOLLgUGqLWRQpzhRRv_b%2BWGMMQsfk-VQp74RA@mail.gmail.com> <20140109104223.GS71033@FreeBSD.org> <CAC67Hz-Rz557COtyE1AurduZrstOqaMaA_H9VzBypsaHfSc=cg@mail.gmail.com> <20140109222610.GJ46596@funkthat.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Fri, Jan 10, 2014 at 12:26 AM, John-Mark Gurney <jmg@funkthat.com> wrote:
> 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 <glebius@freebsd.org> 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.
>>

> 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."

For performance reasons, I don't think pf_addr should be marked as __packed.

I attached the changes I am now using in print_state() since there is
no need to copy
the full pfsync_state, only pf_addr.
I converted sk and nk from pointers to structs on the stack and using
struct copy.
pf_addr is 16 bytes.


Regards,
Guy

[-- Attachment #2 --]
Index: pfctl/pf_print_state.c
===================================================================
--- pfctl/pf_print_state.c	(revision 260492)
+++ pfctl/pf_print_state.c	(working copy)
@@ -208,7 +208,7 @@ void
 print_state(struct pfsync_state *s, int opts)
 {
 	struct pfsync_state_peer *src, *dst;
-	struct pfsync_state_key *sk, *nk;
+	struct pfsync_state_key sk, nk;
 	struct protoent *p;
 	int min, sec;
 
@@ -215,17 +215,17 @@ print_state(struct pfsync_state *s, int opts)
 	if (s->direction == PF_OUT) {
 		src = &s->src;
 		dst = &s->dst;
-		sk = &s->key[PF_SK_STACK];
-		nk = &s->key[PF_SK_WIRE];
+		sk = s->key[PF_SK_STACK];
+		nk = s->key[PF_SK_WIRE];
 		if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) 
-			sk->port[0] = nk->port[0];
+			sk.port[0] = nk.port[0];
 	} else {
 		src = &s->dst;
 		dst = &s->src;
-		sk = &s->key[PF_SK_WIRE];
-		nk = &s->key[PF_SK_STACK];
+		sk = s->key[PF_SK_WIRE];
+		nk = s->key[PF_SK_STACK];
 		if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) 
-			sk->port[1] = nk->port[1];
+			sk.port[1] = nk.port[1];
 	}
 	printf("%s ", s->ifname);
 	if ((p = getprotobynumber(s->proto)) != NULL)
@@ -233,11 +233,11 @@ print_state(struct pfsync_state *s, int opts)
 	else
 		printf("%u ", s->proto);
 
-	print_host(&nk->addr[1], nk->port[1], s->af, opts);
-	if (PF_ANEQ(&nk->addr[1], &sk->addr[1], s->af) ||
-	    nk->port[1] != sk->port[1]) {
+	print_host(&nk.addr[1], nk.port[1], s->af, opts);
+	if (PF_ANEQ(&nk.addr[1], &sk.addr[1], s->af) ||
+	    nk.port[1] != sk.port[1]) {
 		printf(" (");
-		print_host(&sk->addr[1], sk->port[1], s->af, opts);
+		print_host(&sk.addr[1], sk.port[1], s->af, opts);
 		printf(")");
 	}
 	if (s->direction == PF_OUT)
@@ -244,11 +244,11 @@ print_state(struct pfsync_state *s, int opts)
 		printf(" -> ");
 	else
 		printf(" <- ");
-	print_host(&nk->addr[0], nk->port[0], s->af, opts);
-	if (PF_ANEQ(&nk->addr[0], &sk->addr[0], s->af) ||
-	    nk->port[0] != sk->port[0]) {
+	print_host(&nk.addr[0], nk.port[0], s->af, opts);
+	if (PF_ANEQ(&nk.addr[0], &sk.addr[0], s->af) ||
+	    nk.port[0] != sk.port[0]) {
 		printf(" (");
-		print_host(&sk->addr[0], sk->port[0], s->af, opts);
+		print_host(&sk.addr[0], sk.port[0], s->af, opts);
 		printf(")");
 	}
 

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAC67Hz--9ur8wLbqkB=aw8fK9MXjokZi9qULVa-ox_uubUz0vQ>