Bug 206658 - Bus error for pfctl -sa on rpi2 r294499 snap
Summary: Bus error for pfctl -sa on rpi2 r294499 snap
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm Any
: --- Affects Only Me
Assignee: Ian Lepore
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-01-27 02:24 UTC by Jov
Modified: 2016-03-16 17:37 UTC (History)
1 user (show)

See Also:


Attachments
patch for unaligned struct copy (1.18 KB, patch)
2016-01-27 02:46 UTC, Ian Lepore
no flags Details | Diff
Patch submitted by guyyur@gmail.com via https://github.com/guyyur/freebsd-src_patches/blob/master/pfctl_arm_segbus__ver1_part1.patch (2.29 KB, patch)
2016-01-30 21:56 UTC, Ian Lepore
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jov 2016-01-27 02:24:28 UTC
uname -a:
FreeBSD p2 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r294499: Fri Jan 22 01:49:44 UTC 2016     root@releng2.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/RPI2  arm

gdb:
....
pass in log quick on wlan0 inet proto tcp from any to (wlan0) port = 3333 flags S/SA keep state (source-track rule, max-src-conn 5, max-src-conn-rate 3/30, overload <bruteforce> flush global, src.track 30)
pass in log quick on wlan0 inet proto tcp from any to (wlan0) port = 3333 flags S/SA keep state (source-track rule, max-src-conn 5, max-src-conn-rate 3/30, overload <bruteforce> flush global, src.track 30)

STATES:
all tcp 192.168.1.114:48865 -> 103.138.240.229:37005       TIME_WAIT:TIME_WAIT

Program received signal SIGBUS, Bus error.
0x00021614 in print_host (addr=0x2065113e, port=45235, af=2 '\002', opts=1024) at /usr/src/sbin/pfctl/pf_print_state.c:178
178	/usr/src/sbin/pfctl/pf_print_state.c: No such file or directory.
	in /usr/src/sbin/pfctl/pf_print_state.c
Current language:  auto; currently minimal
(gdb) bt
#0  0x00021614 in print_host (addr=0x2065113e, port=45235, af=2 '\002', opts=1024) at /usr/src/sbin/pfctl/pf_print_state.c:178
#1  0x0002189c in print_state (s=0x206510f2, opts=1024) at /usr/src/sbin/pfctl/pf_print_state.c:236
#2  0x0000c35c in pfctl_show_states (dev=<value optimized out>, iface=0x0, opts=<value optimized out>)
    at /usr/src/sbin/pfctl/pfctl.c:1091
#3  0x0000f018 in $a.107 () at /usr/src/sbin/pfctl/pfctl.c:2241
#4  0x0000f018 in $a.107 () at /usr/src/sbin/pfctl/pfctl.c:2241
Comment 1 Ian Lepore freebsd_committer freebsd_triage 2016-01-27 02:46:04 UTC
Created attachment 166167 [details]
patch for unaligned struct copy

Can you please try this patch?  I have no way of testing it myself.
Comment 2 Ian Lepore freebsd_committer freebsd_triage 2016-01-30 21:56:27 UTC
Created attachment 166309 [details]
Patch submitted by guyyur@gmail.com via https://github.com/guyyur/freebsd-src_patches/blob/master/pfctl_arm_segbus__ver1_part1.patch

The original patch I submitted failed to fix the problem due to clang's inlining of memcpy leading to essentially identical code as the struct-assignment code that failed originally.  The changes that should have allowed that to work (such as casting away the alignment by casting the pointer to void* or char* in the memcpy() call, or tagging the pointer argument with __attribute__((aligned_value(1))) failed, apparently due to clang bugs.

Guy Yur <guyyur@gmail.com> pointed out related PR 185617 and submitted a patch he uses to work around the problem, which I've now attached to this PR for completeness.

I intend to commit something very close to this patch, with some changes to make it similar to the way the same problem was solved in the kernel pf code (conditional on __NO_STRICT_ALIGNMENT).
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-01-30 22:03:33 UTC
A commit references this bug:

Author: ian
Date: Sat Jan 30 22:03:15 UTC 2016
New revision: 295086
URL: https://svnweb.freebsd.org/changeset/base/295086

Log:
  Make pfctl(8) work on strict-alignment platforms, by copying a pair of
  embedded structures out of a packed, unaligned struct into local copies
  on the stack which are aligned.

  The original patch to do this was submitted by Guy Yur <guyyur@gmail.com>,
  and this is conceptually the same change, but restructured with the
  #ifndef __NO_STRICT_ALIGNMENT wrapper, similar to how the same issue is
  handled in the kernel pf code.

  PR:		185617
  PR:		206658

Changes:
  head/sbin/pfctl/pf_print_state.c