From owner-freebsd-net@FreeBSD.ORG Sat Jan 4 13:06:03 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 73E36BFE; Sat, 4 Jan 2014 13:06:03 +0000 (UTC) Received: from mail-ob0-x235.google.com (mail-ob0-x235.google.com [IPv6:2607:f8b0:4003:c01::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3338E1069; Sat, 4 Jan 2014 13:06:03 +0000 (UTC) Received: by mail-ob0-f181.google.com with SMTP id uy5so16646478obc.40 for ; Sat, 04 Jan 2014 05:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=sbl4FXQ3qDnbB4XkgGp1rgq2KMw1ystdVO9eawOfOYk=; b=pPgvzReqS3kV9pcSekWiBaftACpKOnBpRSLwpgxwH4/qWQueOF0iyHVa7iW0YPUtUa lyNA2AVzlAFa5L2Por3sM4BN8NH63z6nut1TOmou8lYH0fWyCU1cxfUcr81Lj4n/iNza tFzn7IVKQkiCqxZICKJKHjy55VLUaEZWdo1bng2Zy1rtpzY9AJdJHxolvUwrk0a2MVTp UEkJOwO/RRzC3VUgSxXKoR2XlTuhUDuxTnRt0H20ATMqwloPlkjjUqUe9DcOp+Xzift2 bjAgS4Wm6dOviOcJ2O0q57QY1pM/hcjWGT8xMsaVZtttbHi+vnT9CY51A71XRgav1lN5 52lQ== MIME-Version: 1.0 X-Received: by 10.60.161.229 with SMTP id xv5mr44024492oeb.20.1388840762437; Sat, 04 Jan 2014 05:06:02 -0800 (PST) Received: by 10.76.20.82 with HTTP; Sat, 4 Jan 2014 05:06:02 -0800 (PST) Date: Sat, 4 Jan 2014 15:06:02 +0200 Message-ID: Subject: 10.0-RC1, armv6: "pfctl -s state" crashes on BeagleBone Black due to unaligned access From: Guy Yur To: freebsd-net@freebsd.org, freebsd-arm@freebsd.org Content-Type: text/plain; charset=UTF-8 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: Sat, 04 Jan 2014 13:06:03 -0000 Hi, I am running 10.0-RC1 arm.armv6 on the BeagleBone Black. The "pfctl -s state" command is crashing when trying to print the second entry. struct pfsync_state has a size that is not divisiable by 4 or 8 leading to the second entry in the returned state array not being aligned and pfctl core dumps on Bus error when trying to access a uint32_t field. (gdb) bt #0 print_host (addr=0x2085a11a, port=7660, af=2 '\002', opts=1024) at /usr/src/sbin/pfctl/pf_print_state.c:178 #1 0x00021c4c in print_state (s=0x2085a0f2, opts=1024) at /usr/src/sbin/pfctl/pf_print_state.c:236 #2 0x0000c664 in pfctl_show_states (dev=, iface=0x0, opts=1024) at /usr/src/sbin/pfctl/pfctl.c:1095 sizeof(struct pfsync_state_key) is 36 sizeof(struct pfsync_state_peer) is 32 sizeof(struct pf_addr) is 16 sizeof(struct pfsync_state) is 242 Removing the __spare[2] field will allow the struct to be aligned on 8 bytes for the u_int64_t id field and also cover the uint32_t fields alignment but this will break KBI. I am currently using an inefficient workaround in pfctl_show_states that memcpy each entry to a struct pfsync_state on the stack ensuring each call to print_state receives an aligned struct. 10.0-RC1 World and kernel were compiled in a VirtualBox VM running 9.2-RELEASE-p2 i386. clang and ARM_EABI used as the default make options. Regards, Guy