ebtables lock file fcntl errno value not correctly checked

Bug #1772456 reported by Dan Streetman on 2018-05-21
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ebtables (Ubuntu)
Medium
Dan Streetman
Trusty
Medium
Dan Streetman
Xenial
Medium
Dan Streetman
Artful
Medium
Dan Streetman
Bionic
Medium
Dan Streetman
Cosmic
Medium
Dan Streetman

Bug Description

[impact]

bug 1645324 introduced code to improve the existing file-based locking, by using fcntl instead of exclusive file opening.

However, when fcntl fails the new code tries to check for errno of EAGAIN or EACCES, but does so incorrectly:

+ ret = fcntl(lockfd, F_SETLK, &fl);
+ if (ret == -1 && errno != (EAGAIN || EACCES))

"errno != (EAGAIN || EACCES)" is not correct, because it will always evaluate to true when errno is either EAGAIN or EACCES; the bitwise OR of EAGAIN (11) and EACCES (13) produces 15 (ENOTBLK) which will never match either, so != always is true.

[test case]

run ebtables in a tight loop from two separate shells, to force lockfile contention, for example:

#!/bin/bash

dev="$1"

while test 1; do
sleep 0
ebtables --concurrent -t nat -A PREROUTING -i ${dev} -j ACCEPT
if [ $? -ne 0 ]; then
echo "odd!"
fi
ebtables --concurrent -t nat -D PREROUTING -i ${dev} -j ACCEPT
if [ $? -ne 0 ]; then
echo "odd!"
fi
done

that can be run with any text param (e.g. "foo" and "bar") from 2 shells, to produce the failure:

Unable to create lock file /var/lib/ebtables/lock.

[regression potential]

like the previous patch, this change also has the potential to introduce errors in file locking that ebtables uses; however considering the file locking currently does not work at all due to the above logic error, this patch should only help. The only regression potential is see is the possibility of breaking non-contended file locking, which currently does work.

[other info]

see previous bug 1645324
https://launchpad.net/bugs/1645324

Dan Streetman (ddstreet) wrote :

thanks @setuid for reproducer bash script that I used in description

Changed in ebtables (Ubuntu):
status: New → In Progress
assignee: nobody → Dan Streetman (ddstreet)
importance: Undecided → Medium
no longer affects: ebtables (Ubuntu Precise)
no longer affects: ebtables (Ubuntu Precise)
Changed in ebtables (Ubuntu Trusty):
status: New → In Progress
Dan Streetman (ddstreet) on 2018-05-21
Changed in ebtables (Ubuntu Bionic):
status: New → In Progress
Changed in ebtables (Ubuntu Artful):
status: New → In Progress
Changed in ebtables (Ubuntu Xenial):
status: New → In Progress
Changed in ebtables (Ubuntu Bionic):
importance: Undecided → Medium
Changed in ebtables (Ubuntu Artful):
importance: Undecided → Medium
Changed in ebtables (Ubuntu Xenial):
importance: Undecided → Medium
Changed in ebtables (Ubuntu Trusty):
importance: Undecided → Medium
Changed in ebtables (Ubuntu Bionic):
assignee: nobody → Dan Streetman (ddstreet)
Changed in ebtables (Ubuntu Artful):
assignee: nobody → Dan Streetman (ddstreet)
Changed in ebtables (Ubuntu Xenial):
assignee: nobody → Dan Streetman (ddstreet)
Changed in ebtables (Ubuntu Trusty):
assignee: nobody → Dan Streetman (ddstreet)

Hello Dan, or anyone else affected,

Accepted ebtables into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ebtables/2.0.10.4-3.5ubuntu2.18.04.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in ebtables (Ubuntu Cosmic):
status: In Progress → Fix Committed
Changed in ebtables (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-bionic
Changed in ebtables (Ubuntu Xenial):
status: In Progress → Fix Committed
tags: added: verification-needed-xenial
Steve Langasek (vorlon) wrote :

Hello Dan, or anyone else affected,

Accepted ebtables into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ebtables/2.0.10.4-3.4ubuntu2.16.04.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-xenial to verification-done-xenial. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-xenial. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in ebtables (Ubuntu Artful):
status: In Progress → Fix Committed
tags: added: verification-needed-artful
Steve Langasek (vorlon) wrote :

Hello Dan, or anyone else affected,

Accepted ebtables into artful-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ebtables/2.0.10.4-3.5ubuntu2.17.10.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-artful to verification-done-artful. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-artful. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Steve Langasek (vorlon) wrote :

Hello Dan, or anyone else affected,

Accepted ebtables into trusty-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ebtables/2.0.10.4-3ubuntu1.14.04.2 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-trusty to verification-done-trusty. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-trusty. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in ebtables (Ubuntu Trusty):
status: In Progress → Fix Committed
tags: added: verification-needed-trusty
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ebtables - 2.0.10.4-3.5ubuntu3

---------------
ebtables (2.0.10.4-3.5ubuntu3) cosmic; urgency=medium

  * Fix check of fcntl errno value, to allow lockfile contention to work.
    (LP: #1772456)

 -- Dan Streetman <email address hidden> Mon, 21 May 2018 13:20:15 -0400

Changed in ebtables (Ubuntu Cosmic):
status: Fix Committed → Fix Released
Dan Streetman (ddstreet) wrote :

cosmic:

ubuntu@lp1772456-c:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.5ubuntu3 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-c:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 15848
[2] 15849
ubuntu@lp1772456-c:~$ Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock

verified fixed in cosmic.

Dan Streetman (ddstreet) wrote :

bionic:

ubuntu@lp1772456-b:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.5ubuntu2 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-b:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 2807
[2] 2808
ubuntu@lp1772456-b:~$ Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.

ubuntu@lp1772456-b:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.5ubuntu2.18.04.1 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-b:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 17609
[2] 17610
ubuntu@lp1772456-b:~$ Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock

verified fixed in bionic.

Dan Streetman (ddstreet) wrote :

artful:

ubuntu@lp1772456-a:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.5ubuntu2 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-a:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 2576
[2] 2577
ubuntu@lp1772456-a:~$ Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Sorry, rule does not exist.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Sorry, rule does not exist.
odd!
Unable to create lock file /run/ebtables.lock.

ubuntu@lp1772456-a:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.5ubuntu2.17.10.1 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-a:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 30343
[2] 30344
ubuntu@lp1772456-a:~$ Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock

verified fixed in artful.

Dan Streetman (ddstreet) wrote :

xenial:

ubuntu@lp1772456-x:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.4ubuntu2 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-x:~$ sudo ./repro.sh foor & sudo ./repro.sh bar &
[1] 18987
[2] 18988
ubuntu@lp1772456-x:~$ Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Unable to create lock file /run/ebtables.lock.
odd!
Sorry, rule does not exist.
Unable to create lock file /run/ebtables.lock.
odd!
odd!
Unable to create lock file /run/ebtables.lock.

ubuntu@lp1772456-x:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3.4ubuntu2.16.04.1 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-x:~$ sudo ./repro.sh foor & sudo ./repro.sh bar &
[1] 23212
[2] 23213
ubuntu@lp1772456-x:~$ Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock
Trying to obtain lock /run/ebtables.lock

verified fixed in xenial.

Dan Streetman (ddstreet) wrote :

trusty:

ubuntu@lp1772456-t:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3ubuntu1.14.04.1 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-t:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 2728
[2] 2729
ubuntu@lp1772456-t:~$ Unable to create lock file /var/lib/ebtables/lock.
odd!
Unable to create lock file /var/lib/ebtables/lock.
odd!
Unable to create lock file /var/lib/ebtables/lock.
odd!
Sorry, rule does not exist.
odd!
Unable to create lock file /var/lib/ebtables/lock.
odd!
Unable to create lock file /var/lib/ebtables/lock.

ubuntu@lp1772456-t:~$ dpkg -l | grep ebtables
ii ebtables 2.0.10.4-3ubuntu1.14.04.2 amd64 Ethernet bridge frame table administration

ubuntu@lp1772456-t:~$ sudo ./repro.sh foo & sudo ./repro.sh bar &
[1] 5643
[2] 5644
ubuntu@lp1772456-t:~$ Trying to obtain lock /var/lib/ebtables/lock
Trying to obtain lock /var/lib/ebtables/lock
Trying to obtain lock /var/lib/ebtables/lock
Trying to obtain lock /var/lib/ebtables/lock
Trying to obtain lock /var/lib/ebtables/lock

verified fixed in trusty.

tags: added: verification-done verification-done-artful verification-done-bionic verification-done-trusty verification-done-xenial
removed: verification-needed verification-needed-artful verification-needed-bionic verification-needed-trusty verification-needed-xenial
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ebtables - 2.0.10.4-3.5ubuntu2.18.04.1

---------------
ebtables (2.0.10.4-3.5ubuntu2.18.04.1) bionic; urgency=medium

  * Fix check of fcntl errno value, to allow lockfile contention to work.
    (LP: #1772456)

 -- Dan Streetman <email address hidden> Mon, 21 May 2018 13:20:15 -0400

Changed in ebtables (Ubuntu Bionic):
status: Fix Committed → Fix Released

The verification of the Stable Release Update for ebtables has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ebtables - 2.0.10.4-3.5ubuntu2.17.10.1

---------------
ebtables (2.0.10.4-3.5ubuntu2.17.10.1) artful; urgency=medium

  * Fix check of fcntl errno value, to allow lockfile contention to work.
    (LP: #1772456)

 -- Dan Streetman <email address hidden> Mon, 21 May 2018 13:20:15 -0400

Changed in ebtables (Ubuntu Artful):
status: Fix Committed → Fix Released
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ebtables - 2.0.10.4-3.4ubuntu2.16.04.1

---------------
ebtables (2.0.10.4-3.4ubuntu2.16.04.1) xenial; urgency=medium

  * Fix check of fcntl errno value, to allow lockfile contention to work.
    (LP: #1772456)

 -- Dan Streetman <email address hidden> Mon, 21 May 2018 13:20:15 -0400

Changed in ebtables (Ubuntu Xenial):
status: Fix Committed → Fix Released
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ebtables - 2.0.10.4-3ubuntu1.14.04.2

---------------
ebtables (2.0.10.4-3ubuntu1.14.04.2) trusty; urgency=medium

  * Fix check of fcntl errno value, to allow lockfile contention to work.
    (LP: #1772456)

 -- Dan Streetman <email address hidden> Mon, 21 May 2018 13:20:15 -0400

Changed in ebtables (Ubuntu Trusty):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers