]> git.ipfire.org Git - thirdparty/pdns.git/commit
dnsdist: Fix a race in the XSK/AF_XDP backend handling code
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 4 Jul 2024 15:16:54 +0000 (17:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 5 Jul 2024 08:35:20 +0000 (10:35 +0200)
commitb81c7e42fcdec03a3541329a5704487d5c9e925a
tree7e2dc76252dbf77f6447fd25205ed6c45151726b
parent39a927130c4e73421b9ad6d1f309d7c40d725354
dnsdist: Fix a race in the XSK/AF_XDP backend handling code

For performance reasons we used to keep a local list of available frames
in our `XskWorker` object, like we are doing in the `XskSocket` one,
to avoid having to go to the shared list which is protected by a lock.
Unfortunately, while it works well for the `XskSocket` because it is
accessed by a single `XskRouter` thread, the `XskWorker` object can
be accessed by multiple threads at once: `XskResponderThread`,
`responderThread`, `XskClientThread` and `XskRouter`. Most of the
time these threads do not acquire nor release frames to the local
list, but `responderThread` does acquire one when a response frame
is punted to the regular networking stack, and all of them release
frames when an unexpected condition occurs, for example when a queue
is full. This leads to memory corruption and to a crash.

This commit gets rid of the local list of frames in the `XskWorker`
object, acquiring and releasing them to the shared list instead, since
performance in these cases is likely not as critical. If it turns out
to be too slow, we can look into caching a few frames in a thread-local
list, but then we need to be careful not to hold on them indefinitely
which might be tricky.
pdns/xsk.cc
pdns/xsk.hh