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
--089e011609bc6931ef04ef91a33c
Content-Type: text/plain; charset=UTF-8

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

--089e011609bc6931ef04ef91a33c
Content-Type: application/octet-stream; name="pf_print_state.patch"
Content-Disposition: attachment; filename="pf_print_state.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hq8m4iyt0

SW5kZXg6IHBmY3RsL3BmX3ByaW50X3N0YXRlLmMKPT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gcGZjdGwvcGZfcHJp
bnRfc3RhdGUuYwkocmV2aXNpb24gMjYwNDkyKQorKysgcGZjdGwvcGZfcHJpbnRfc3RhdGUuYwko
d29ya2luZyBjb3B5KQpAQCAtMjA4LDcgKzIwOCw3IEBAIHZvaWQKIHByaW50X3N0YXRlKHN0cnVj
dCBwZnN5bmNfc3RhdGUgKnMsIGludCBvcHRzKQogewogCXN0cnVjdCBwZnN5bmNfc3RhdGVfcGVl
ciAqc3JjLCAqZHN0OwotCXN0cnVjdCBwZnN5bmNfc3RhdGVfa2V5ICpzaywgKm5rOworCXN0cnVj
dCBwZnN5bmNfc3RhdGVfa2V5IHNrLCBuazsKIAlzdHJ1Y3QgcHJvdG9lbnQgKnA7CiAJaW50IG1p
biwgc2VjOwogCkBAIC0yMTUsMTcgKzIxNSwxNyBAQCBwcmludF9zdGF0ZShzdHJ1Y3QgcGZzeW5j
X3N0YXRlICpzLCBpbnQgb3B0cykKIAlpZiAocy0+ZGlyZWN0aW9uID09IFBGX09VVCkgewogCQlz
cmMgPSAmcy0+c3JjOwogCQlkc3QgPSAmcy0+ZHN0OwotCQlzayA9ICZzLT5rZXlbUEZfU0tfU1RB
Q0tdOwotCQluayA9ICZzLT5rZXlbUEZfU0tfV0lSRV07CisJCXNrID0gcy0+a2V5W1BGX1NLX1NU
QUNLXTsKKwkJbmsgPSBzLT5rZXlbUEZfU0tfV0lSRV07CiAJCWlmICh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ay5hZGRyWzFdLCAmc2su
YWRkclsxXSwgcy0+YWYpIHx8CisJICAgIG5rLnBvcnRbMV0gIT0gc2sucG9ydFsxXSkgewogCQlw
cmludGYoIiAoIik7Ci0JCXByaW50X2hvc3QoJnNrLT5hZGRyWzFdLCBzay0+cG9ydFsxXSwgcy0+
YWYsIG9wdHMpOworCQlwcmludF9ob3N0KCZzay5hZGRyWzFdLCBzay5wb3J0WzFdLCBzLT5hZiwg
b3B0cyk7CiAJCXByaW50ZigiKSIpOwogCX0KIAlpZiAocy0+ZGlyZWN0aW9uID09IFBGX09VVCkK
QEAgLTI0NCwxMSArMjQ0LDExIEBAIHByaW50X3N0YXRlKHN0cnVjdCBwZnN5bmNfc3RhdGUgKnMs
IGludCBvcHRzKQogCQlwcmludGYoIiAtPiAiKTsKIAllbHNlCiAJCXByaW50ZigiIDwtICIpOwot
CXByaW50X2hvc3QoJm5rLT5hZGRyWzBdLCBuay0+cG9ydFswXSwgcy0+YWYsIG9wdHMpOwotCWlm
IChQRl9BTkVRKCZuay0+YWRkclswXSwgJnNrLT5hZGRyWzBdLCBzLT5hZikgfHwKLQkgICAgbmst
PnBvcnRbMF0gIT0gc2stPnBvcnRbMF0pIHsKKwlwcmludF9ob3N0KCZuay5hZGRyWzBdLCBuay5w
b3J0WzBdLCBzLT5hZiwgb3B0cyk7CisJaWYgKFBGX0FORVEoJm5rLmFkZHJbMF0sICZzay5hZGRy
WzBdLCBzLT5hZikgfHwKKwkgICAgbmsucG9ydFswXSAhPSBzay5wb3J0WzBdKSB7CiAJCXByaW50
ZigiICgiKTsKLQkJcHJpbnRfaG9zdCgmc2stPmFkZHJbMF0sIHNrLT5wb3J0WzBdLCBzLT5hZiwg
b3B0cyk7CisJCXByaW50X2hvc3QoJnNrLmFkZHJbMF0sIHNrLnBvcnRbMF0sIHMtPmFmLCBvcHRz
KTsKIAkJcHJpbnRmKCIpIik7CiAJfQogCg==
--089e011609bc6931ef04ef91a33c--



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