Page MenuHomeFreeBSD

pf: Send syncookies from the receiving thread
ClosedPublic

Authored by bnovkov on Fri, Aug 21, 12:21 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Sep 13, 8:13 AM
Unknown Object (File)
Sat, Sep 12, 3:45 PM
Unknown Object (File)
Fri, Sep 11, 8:57 AM
Unknown Object (File)
Fri, Sep 11, 7:25 AM
Unknown Object (File)
Wed, Sep 9, 5:10 PM
Unknown Object (File)
Wed, Sep 9, 1:09 PM
Unknown Object (File)
Wed, Sep 9, 10:20 AM
Unknown Object (File)
Tue, Sep 8, 11:38 PM

Details

Summary

pf sends outbound packets by offloading them to a single per-vnet SWI handler
through the V_pf_sendqueue mbuf queue. A large DDoS attack may overwhelm
that per-vnet queue with syncookie packets and cause contention in the SWI
handler that negatively affects other pf operations.

Fix this by sending the initial syncookie challenge from the context
of the receiving thread. This avoids the syncookie-induced contention on
the pf_intr mbuf queue.

Sponsored by: Klara, Inc.
Sponsored by: Entersekt
MFC after: 3 weeks

Test Plan

I've tested this patch by flooding a host using hping3. The two attached pmcstat-generated flamegraphs show that the patch is successfully removing the load from the SWI handler.


Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Can you check or host the results somewhere else? Maybe freefall?

Can you check or host the results somewhere else? Maybe freefall?

Sorry, I forgot that phabricator doesn't automatically attach the referenced files, they should be visible now.

In case they're not, I've also uploaded them to freefall.

sys/netpfil/pf/pf.h
756

Why? It doesn't seem to be used anywhere outside of pf.c

757

Pretty much everything in pf works on mbufs. It seems rather pointless to include that in the function name.

I would name this pf_send_ip_direct() so that it's clear that this function will emit the packet directly (as opposed to say pf_send(), pf_send_icmp(), ... which use the swi).

I'm also struggling to make sense of the baseline flame graph. It seems to be spending a lot of time removing interfaces (5% of samples in pf_kkif_free()!) and I don't see any calls to pf_test(), which we should see if we were handling traffic.
Maybe the address decoding went wrong, because those stacks just look wrong.

bnovkov edited the test plan for this revision. (Show Details)

Address @kp 's comments

bnovkov added inline comments.
sys/netpfil/pf/pf.h
756

thanks for catching this, this is a leftover from a previous iteration of this patch.

In D59068#1356482, @kp wrote:

I'm also struggling to make sense of the baseline flame graph. It seems to be spending a lot of time removing interfaces (5% of samples in pf_kkif_free()!) and I don't see any calls to pf_test(), which we should see if we were handling traffic.
Maybe the address decoding went wrong, because those stacks just look wrong.

Hm, that's odd. I'll try to find out what went wrong.

In D59068#1356482, @kp wrote:

I'm also struggling to make sense of the baseline flame graph. It seems to be spending a lot of time removing interfaces (5% of samples in pf_kkif_free()!) and I don't see any calls to pf_test(), which we should see if we were handling traffic.
Maybe the address decoding went wrong, because those stacks just look wrong.

It also looks like the samples were taken from a kernel with INVARIANTS enabled. (trash_ctor() wouldn't appear in the profile otherwise.)

I think the patch is fine now, but I would like to see the flame graphs anyway, so we're sure this does what we think it does.

In D59068#1356482, @kp wrote:

I'm also struggling to make sense of the baseline flame graph. It seems to be spending a lot of time removing interfaces (5% of samples in pf_kkif_free()!) and I don't see any calls to pf_test(), which we should see if we were handling traffic.
Maybe the address decoding went wrong, because those stacks just look wrong.

Hm, that's odd. I'll try to find out what went wrong.

I have indeed managed to fumble the kernel config while testing, sorry about that.
I've generated new flamegraphs that have decoded properly.

This revision is now accepted and ready to land.Thu, Aug 27, 3:44 PM