Not usual setup can lead to surprise
The 5th of December 2012, I’ve setup suricata in AF_PACKET IPS mode between a WiFi interface and an Ethernet interface. The result was surprising as it was leading to a crash after some time:
The issue was linked with the defrag option of AF_PACKEt fanout. I’ve proposed a patch the 7th Dec 2012 and after a discussion with David Miller and Johannes Berg, Johannes has proposed a better patch which was included in official tree. So the problem is fixed for kernel superior or equal to 3.7.
Here’s the list of affected kernel:
- All kernel prior to 3.2.36
- All 3.3.x kernel
- All 3.4.x kernel prior to 3.4.25
- All 3.5.x kernel prior to 22.214.171.124
- All 3.6.x kernel prior to 3.6.11
Workaround in Suricata
If you can’t update to a not affected kernel, you can set defrag to no in af-packet configuration to avoid the issue:
- interface: wlan0
# In some fragmentation case, the hash can not be computed. If "defrag" is set
# to yes, the kernel will do the needed defragmentation before sending the packets.
Kernel oops have been reported by some users running Suricata with AF_PACKET multiple thread capture activated. This is due to a bug I’ve introduced in AF_PACKET when fixing an other bug.
Which kernel not to use with Suricata in AF_PACKET mode
The following kernel version will surely crash if Suricata or any other program is used with AF_PACKET capture with multiple capture threads:
- Linux 3.2.30 to 3.2.33
- Linux 3.4.12 to 3.4.18
- Linux 3.5.5 to 3.5.7
- Linux 3.6.0 to 3.6.6
If only one capture thread is used there is no risk of crash. If you are running a vulnerable kernel, your configuration should looks like:
- interface: eth0
# Number of receive threads (>1 will crash with bad kernel)
AF_PACKET capture is one of my favorite capture method on Linux with Suricata. It is mainline and it offers really good performance with latest kernel. For example, this is deployed on one of our box and run at 10Gbps speed on non-expensive hardware.
This speed is achieved by using load-balanced capture. This feature allows to have multiple thread/process listening to the same interface. The load-balancing is made by the kernel.
This feature has been developed by David Miller and is available since Linux 3.1.
In summer 2012, I’ve worked on adding AF_PACKET IPS mode and I’ve discovered a kernel bug which was causing a packet sending loop in the IPS code. I’ve proposed a fix af_packet: don’t emit packet on orig fanout group. The patch has reached mainline with Linux 3.6. As it was fixing a real problem it was propagated to most Linux stable branches. Some distributions, like Ubuntu, have also backported the patch to their official kernel.
But the patch was buggy and some Suricata users have reported kernel oops. I’ve fixed the bug af-packet: fix oops when socket is not present and the patch will be available in Linux 3.7.
The kernel stable team has incorporated this patch in their subsequent releases so most stable branches but 3.5 don’t suffer anymore of this problem.
Ubuntu Quantal has a patched kernel since at least 3.5.0-25.
I was looking for some minimal Linux kernel configuration for Virtualbox guest and did only find some old one. I thus decide to build one and to publish them.
They are available on github: regit-config
For now, the only published configuration are for Linux kernel 3.5: