Hi,
With the new m_pullup() code, I see crashes on armv7 and sparc64.
regress/sbin/slaacd sends some IPv6 ND6 packets over pair(4) from
scapy. It crashes after m_pullup() in ipv6_check().
==== run-parse-ra ====
ifconfig pair1 destroy 2>/dev/null || true
ifconfig pair2 destroy 2>/dev/null || true
ifconfig pair1 rdomain 1 10.11.12.1/24 up
ifconfig pair2 rdomain 1 10.11.12.2/24 up
ifconfig pair1 rdomain 1 patch pair2
ifconfig pair1 inet6 rdomain 1 eui64
ifconfig pair2 inet6 rdomain 1 eui64
ifconfig pair2 inet6 rdomain 1 autoconf
route -nq -T 1 add -host default 10.11.12.1 -reject
route -T1 exec python3 -B -u /usr/src/regress/sbin/slaacd/process_ra.py pair1
pair2 /dev/slaacd.sock
Timeout, server ot21 not responding.
panic: trap type 0x34 (mem address not aligned): pc=14a1a7c npc=14a1a80
pstate=99820006<PRIV,IE>
Stopped at db_enter+0x8: nop
TID PID UID PRFLAGS PFLAGS CPU COMMAND
*317234 41858 0 0x14000 0x200 0 softnet
416946 63125 0 0x14000 0x200 1 systq
trap(40025e91650, 34, 14a1a7c, 99820006, 180, 3b9ac800) at trap+0x328
Lslowtrap_reenter(40005090d00, 0, fffffffffffffffe, 1832866, 6000, 6) at
Lslowtrap_reenter+0xf8
ipv6_check(40005364000, 40005090d00, 0, 2018000, e0018000, 1a) at
ipv6_check+0x21c
ip6_input_if(40025e91a68, 40025e91a74, 29, 0, 40005364000, 3b9ac800) at
ip6_input_if+0x7c
ipv6_input(40005364000, 198a2f0, 40005090d00, 1, e, 0) at ipv6_input+0x3c
ether_input(40005364000, 40005090d00, 20, 1780210, 0, 1780210) at
ether_input+0x274
if_input_process(40005364000, 40025e91ce0, 20, 1780210, 0, 6) at
if_input_process+0x44
ifiq_process(40005364410, 40025e91dc8, 1cd6288, 1cc1840, 1c00, 6) at
ifiq_process+0x68
taskq_thread(4000432e080, 40004300810, 1775908, 480, 180, 3b9ac800) at
taskq_thread+0x7c
proc_trampoline(0, 0, 0, 0, 0, 0) at proc_trampoline+0x14
bpfwrite() calls bpf_movein() which fills the mbuf with these
wonderful comments:
case DLT_EN10MB:
sockp->sa_family = AF_UNSPEC;
/* XXX Would MAXLINKHDR be better? */
hlen = ETHER_HDR_LEN;
...
m->m_data += hlen; /* XXX */
Note that ETHER_HDR_LEN is 14, so the mbuf is not 4 byte aligned.
Next ether_encap() makes room for an aligned ehternet header. This
is 16 bytes and does not fit. So we prepend a new empty mbuf.
m = m_prepend(m, ETHER_ALIGN + sizeof(eh), M_DONTWAIT);
When we reach ip6_input(), the ethernet header was added and removed.
So we still have an empty mbuf in front of an mbuf with an unaligned
IPv6 header.
New m_pullup() code preserves the alingment of the second mbuf data.
During review we agreed that this might be a good idea. Mbuf
alingnmet is very fragile, but it works unless you change anything.
So back to the old behavior, align the data at the beginning of the
empty mbuf.
ok?
bluhm
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.280
diff -u -p -r1.280 uipc_mbuf.c
--- kern/uipc_mbuf.c 18 Jan 2022 12:38:21 -0000 1.280
+++ kern/uipc_mbuf.c 2 Feb 2022 20:02:50 -0000
@@ -955,7 +955,7 @@ m_pullup(struct mbuf *m0, int len)
if (!M_READONLY(m0) && len <= tail - head) {
/* we can copy everything into the first mbuf */
if (m0->m_len == 0) {
- m0->m_data = head;
+ m0->m_data = M_DATABUF(m0);
} else if (len > tail - mtod(m0, caddr_t)) {
/* need to memmove to make space at the end */
memmove(head, mtod(m0, caddr_t), m0->m_len);