Fix nf_conntrack races when dealing with same origin requests in NAT environments
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
linux (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
Bionic |
Fix Released
|
Medium
|
Matthew Ruffell | ||
Cosmic |
Won't Fix
|
Medium
|
Unassigned |
Bug Description
BugLink: https:/
[Impact]
There are a number of races in nf_conntrack when multiple packets are sent from the same origin to the same destination at the same time, where there is no pre-existing confirmed conntrack entry, in a NAT environment.
This is most frequently seen in users with kubernetes workloads, where dns
requests are sent from the same socket at the same time, from different threads. One request is for a A record, the other AAAA. A conntrack race happens, which leads to one request being dropped, which leads to 5 second dns timeouts.
This problem is not specific to kubernetes, as any multi-threaded process
which sends UDP packets from the same socket at the same time from different
threads is affected.
Note that since UDP is connectionless, no packet is sent when connect() is
called, so no conntrack entries are created until a packet is first sent.
In the scenario where two UDP packets are sent at the same time from the same
socket on different threads, there are the following possible races:
1.) Neither of the packets find a confirmed conntrack entry. This leads to two conntrack entries being created with the same tuples.
2.) Same as 1), but a conntrack entry is confirmed for one of the packets before the other calls get_unique_tuple(). The other packet gets a different reply tuple with the source port changed.
The outcomes of the races are the same, one of the packets is dropped when it
comes time to confirm conntrack entries with __nf_conntrack_
For more information, read the technical blog post:
https:/
[Fix]
The fix to race 1) was included in 4.19 upstream by this commit:
netfilter: nf_conntrack: resolve clash for matching conntracks
commit ed07d9a021df6da
Author: Martynas Pumputis <email address hidden>
Date: Mon Jul 2 16:52:14 2018 +0200
This commit adds an extra check to see if the two entries are the same and to
merge the entries if they are.
The fix to race 2) was included in 5.0 upstream by this commit:
netfilter: nf_nat: skip nat clash resolution for same-origin entries
commit 4e35c1cb9460240
Author: Martynas Pumputis <email address hidden>
Date: Tue Jan 29 15:51:42 2019 +0100
This commit ensures that a new source port is not allocated to a duplicated
entry, and forwards the duplicated entries to be resolved later on.
Note that 4e35c1cb9460240
Both commits cherry-pick to 4.15 bionic cleanly. Please cherry-pick both commits to all bionic kernels.
[Testcase]
The reproducer has been provided by the author of the fixes, and is best viewed here:
https:/
The dmesg logs and packet traces in the above github repo are best viewed while reading upstream discussion:
https:/
I have built a test kernel for xenial HWE, which can be found here:
https:/
The test kernel has been tested with a kubernetes workload and aided with
resolution of kubernetes problems.
[Regression Potential]
As noted previously, 4e35c1cb9460240
backported to stable releases 4.9.163, 4.14.106, 4.19.29, 4.20.16 and has no
changes to the primary commit. This commit is well tested and considered stable by the community.
Both commits have also been present in the -azure kernels since 4.15.0-1030.31 and 4.18.0-1004.4, as per LP #1795493, http://
They have received wide testing, and no problems have been reported.
The changes are specifically limited to resolving clashes between duplicate
conntrack entries, and any regressions will be limited to that scenario. The
overall risk of regression is very low.
[Notes]
The commits in the -azure kernels will need to be reverted before importing the generic bionic updates, since they are the pre-upstream commits, and have had several revisions since they were imported. Replacing them with the
actual upstream commits will make things easier in the future to maintain.
http://
For race 1):
Azure: https:/
Upstream: ed07d9a021df6da
Commits are the same.
For race 2):
Azure: https:/
Upstream: 4e35c1cb9460240
Note the difference, old commit must be reverted first.
Changed in linux (Ubuntu Bionic): | |
status: | New → In Progress |
Changed in linux (Ubuntu Cosmic): | |
status: | New → Won't Fix |
Changed in linux (Ubuntu Bionic): | |
importance: | Undecided → Medium |
Changed in linux (Ubuntu Cosmic): | |
importance: | Undecided → Medium |
Changed in linux (Ubuntu Bionic): | |
assignee: | nobody → Matthew Ruffell (mruffell) |
description: | updated |
tags: | added: sts |
Changed in linux (Ubuntu Bionic): | |
status: | In Progress → Fix Committed |
Changed in linux (Ubuntu): | |
status: | Incomplete → Invalid |
This bug is missing log files that will aid in diagnosing the problem. While running an Ubuntu kernel (not a mainline or third-party kernel) please enter the following command in a terminal window:
apport-collect 1836816
and then change the status of the bug to 'Confirmed'.
If, due to the nature of the issue you have encountered, you are unable to run this command, please add a comment stating that fact and change the bug status to 'Confirmed'.
This change has been made by an automated script, maintained by the Ubuntu Kernel Team.