ufw doesn't support concurrent updates
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ufw |
Fix Released
|
Medium
|
Jamie Strandboge | ||
ufw (Debian) |
Fix Released
|
Unknown
|
|||
ufw (Ubuntu) |
Fix Released
|
Medium
|
Jamie Strandboge | ||
Bionic |
Fix Released
|
Medium
|
Jamie Strandboge | ||
Cosmic |
Fix Released
|
Medium
|
Jamie Strandboge | ||
Disco |
Fix Released
|
Medium
|
Jamie Strandboge |
Bug Description
[Impact]
ufw prior to 0.36 did not support locking or use xtables locking which can lead to problems when using ufw as a dynamic firewall.
[Test Case]
$ sudo apt-get install python-minimal # for the test script
$ sudo ./test_
A patched ufw will complete with no errors. With an unpatched ufw, there will be many errors like:
$ sudo ./test_
...
ERROR: initcaps
[Errno 2] iptables: Chain already exists.
ERROR: initcaps
[Errno 2] iptables: Chain already exists.
[Regression Potential]
ufw 0.36 implements a global exclusive lock before doing any kernel or file writes. Risk of regression includes the lock file not being released due to coding error. The locking is done via fcntl.lockf and ufw releases it in a finally clause that is careful to always release it.
[Other Info]
This locking code has been in production in the ufw snap for years and is known to work is static environments as well as in dynamic environments (IPS/fail2ban/etc).
= Original description =
On a server under Ubuntu 12.04 I automatically update firewall rules and I unfortunately noticed that if 2 rules are processed at the same time it leads to an inconsistent result between iptables and ufw status.
In fact it can be reproduced using the python script in attachment.
Before executing this script I didn't have any rules matching the ip 192.168.254.1 on my computer.
After a launch iptables takes into acount 464 rules.
sudo iptables -L -n | grep 192.168.254.1 | wc -l
464
It should be 500 rules but the script stressed a lot my system and all rules can't be processed by iptables
sudo ./test_
iptables: Resource temporarily unavailable.
iptables: Resource temporarily unavailable.
iptables: Resource temporarily unavailable.
[...]
Anyway, ufw stores only the last updates (in /lib/ufw/
sudo ufw status
État : actif
Vers Action Depuis
---- ------ ------
192.168.254.1 1234/tcp ALLOW 192.168.46.9
192.168.254.1 1234/tcp ALLOW 192.168.22.10
192.168.254.1 1234/tcp ALLOW 192.168.32.10
192.168.254.1 1234/tcp ALLOW 192.168.5.10
192.168.254.1 1234/tcp ALLOW 192.168.43.9
192.168.254.1 1234/tcp ALLOW 192.168.40.10
192.168.254.1 1234/tcp ALLOW 192.168.46.10
192.168.254.1 1234/tcp ALLOW 192.168.48.10
192.168.254.1 1234/tcp ALLOW 192.168.42.10
192.168.254.1 1234/tcp ALLOW 192.168.43.10
So I can't delete other rules using ufw, I had to directly use iptables.
In this case I can only delete 10 rules using ufw.
Could you please handle some kind of lock?
Changed in ufw (Ubuntu): | |
status: | New → Triaged |
Changed in ufw: | |
status: | New → Triaged |
Changed in ufw (Ubuntu): | |
importance: | Undecided → Medium |
Changed in ufw: | |
importance: | Undecided → Medium |
Changed in ufw: | |
status: | Triaged → Fix Committed |
milestone: | none → 0.34 |
Changed in ufw: | |
status: | Fix Committed → In Progress |
Changed in ufw (Debian): | |
status: | Unknown → New |
Changed in ufw: | |
status: | In Progress → Triaged |
Changed in ufw (Ubuntu): | |
status: | Triaged → In Progress |
assignee: | nobody → Jamie Strandboge (jdstrand) |
Changed in ufw (Ubuntu Cosmic): | |
status: | New → Triaged |
Changed in ufw (Ubuntu Bionic): | |
status: | New → Triaged |
Changed in ufw (Ubuntu Cosmic): | |
importance: | Undecided → Medium |
Changed in ufw (Ubuntu Bionic): | |
importance: | Undecided → Medium |
Changed in ufw (Ubuntu Cosmic): | |
assignee: | nobody → Jamie Strandboge (jdstrand) |
Changed in ufw (Ubuntu Bionic): | |
assignee: | nobody → Jamie Strandboge (jdstrand) |
Changed in ufw (Debian): | |
status: | New → Fix Released |
description: | updated |
Changed in ufw (Ubuntu Bionic): | |
status: | Triaged → In Progress |
Changed in ufw (Ubuntu Cosmic): | |
status: | Triaged → In Progress |
There was a problem with the patch and this will be in the next release of ufw.