Broken system lock counting

Bug #1778547 reported by Julian Andres Klode on 2018-06-25
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
Undecided
Unassigned
Xenial
Undecided
Unassigned
Artful
Undecided
Unassigned
Bionic
Undecided
Unassigned

Bug Description

[Impact]
System lock unrefing is broken, off-by-one error. Locking twice opens a second fd for the lock file, and the old fd gets lost and remains open for the remaining duration of the program

[Test case]

Executing the following script should show one lock file in the first line, and none in the last line.

def maybe_readlink(path):
  try:
    return os.readlink(path)
  except:
    return "<deleted>"

import os, apt_pkg
apt_pkg.init()
apt_pkg.pkgsystem_lock()
apt_pkg.pkgsystem_lock()
print([(p, maybe_readlink("/proc/self/fd/" + p)) for p in os.listdir("/proc/self/fd")])
apt_pkg.pkgsystem_unlock()
apt_pkg.pkgsystem_unlock()
print([(p, maybe_readlink("/proc/self/fd/" + p)) for p in os.listdir("/proc/self/fd")])

[Test output]
good, cosmic:
[('0', '/dev/pts/2'), ('1', '/dev/pts/2'), ('2', '/dev/pts/2'), ('3', '/var/lib/dpkg/lock'), ('4', '<deleted>')]
[('0', '/dev/pts/2'), ('1', '/dev/pts/2'), ('2', '/dev/pts/2'), ('3', '<deleted>')]

bad, bionic:
[('0', '/dev/pts/0'), ('1', '/dev/pts/0'), ('2', '/dev/pts/0'), ('3', 'pipe:[40889331]'), ('4', '/var/lib/dpkg/lock'), ('5', '/var/lib/dpkg/lock'), ('6', '<deleted>'), ('17', 'socket:[53931]')]
[('0', '/dev/pts/0'), ('1', '/dev/pts/0'), ('2', '/dev/pts/0'), ('3', 'pipe:[40889331]'), ('4', '/var/lib/dpkg/lock'), ('5', '<deleted>'), ('17', 'socket:[53931]')]

[Regression potential]
A locking change can potentially break locking, but this one seems like an obvious off-by-one error.

Changed in apt (Ubuntu):
status: New → Fix Committed
Changed in apt (Ubuntu Bionic):
status: New → Triaged
Changed in apt (Ubuntu Artful):
status: New → Confirmed
Changed in apt (Ubuntu Xenial):
status: New → Confirmed
description: updated
description: updated
Changed in apt (Ubuntu Bionic):
status: Triaged → In Progress
Changed in apt (Ubuntu Artful):
status: Confirmed → In Progress
Changed in apt (Ubuntu Xenial):
status: Confirmed → In Progress

Hello Julian, or anyone else affected,

Accepted apt into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.2.27 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 apt (Ubuntu Xenial):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-xenial
Changed in apt (Ubuntu Artful):
status: In Progress → Fix Committed
tags: added: verification-needed-artful
Chris J Arges (arges) wrote :

Hello Julian, or anyone else affected,

Accepted apt into artful-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.5.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-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!

Changed in apt (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed-bionic
Chris J Arges (arges) wrote :

Hello Julian, or anyone else affected,

Accepted apt into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.6.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-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!

Julian Andres Klode (juliank) wrote :

Sorry, few typos in the script

description: updated
description: updated
Julian Andres Klode (juliank) wrote :
Download full text (4.7 KiB)

=========== bionic OK (1.6.1 -> 1.6.2) =====================

+ lxc launch -e ubuntu:bionic lp1778547-bionic
Creating lp1778547-bionic
Starting lp1778547-bionic
+ sleep 5
+ lxc exec lp1778547-bionic -- sh -c 'apt-cache policy libapt-pkg5.0 | grep Inst ; python3 /home/jak/a.py'
  Installed: 1.6.1
[('0', '/dev/pts/5'), ('1', '/dev/pts/5'), ('2', '/dev/pts/5'), ('3', 'pipe:[749881]'), ('4', '/var/lib/dpkg/lock'), ('5', '/var/lib/dpkg/lock'), ('6', '<deleted>'), ('17', 'socket:[43872]')]
[('0', '/dev/pts/5'), ('1', '/dev/pts/5'), ('2', '/dev/pts/5'), ('3', 'pipe:[749881]'), ('4', '/var/lib/dpkg/lock'), ('5', '<deleted>'), ('17', 'socket:[43872]')]
+ lxc exec lp1778547-bionic -- sh -c 'echo deb http://archive.ubuntu.com/ubuntu bionic-proposed main >> /etc/apt/sources.list && apt-get update && apt-get -qy install libapt-pkg5.0'
dpkg-preconfigure: unable to re-open stdin: No such file or directory
+ lxc exec lp1778547-bionic -- sh -c 'apt-cache policy libapt-pkg5.0 | grep Inst ; python3 /home/jak/a.py'
  Installed: 1.6.2
[('0', '/dev/pts/4'), ('1', '/dev/pts/4'), ('2', '/dev/pts/4'), ('3', 'pipe:[779703]'), ('4', '/var/lib/dpkg/lock'), ('5', '<deleted>'), ('17', 'socket:[43872]')]
[('0', '/dev/pts/4'), ('1', '/dev/pts/4'), ('2', '/dev/pts/4'), ('3', 'pipe:[779703]'), ('4', '<deleted>'), ('17', 'socket:[43872]')]
+ lxc stop lp1778547-bionic

==================== artful OK (1.5.1 -> 1.5.2) ===============================
+ lxc launch -e ubuntu:artful lp1778547-artful
Creating lp1778547-artful
Starting lp1778547-artful
+ sleep 5
+ lxc exec lp1778547-artful -- sh -c 'apt-cache policy libapt-pkg5.0 | grep Inst ; python3 /home/jak/a.py'
  Installed: 1.5.1
[('0', '/dev/pts/4'), ('1', '/dev/pts/4'), ('2', '/dev/pts/4'), ('3', 'pipe:[818873]'), ('4', '/var/lib/dpkg/lock'), ('5', '/var/lib/dpkg/lock'), ('6', '<deleted>'), ('17', 'socket:[43872]')]
[('0', '/dev/pts/4'), ('1', '/dev/pts/4'), ('2', '/dev/pts/4'), ('3', 'pipe:[818873]'), ('4', '/var/lib/dpkg/lock'), ('5', '<deleted>'), ('17', 'socket:[43872]')]
+ lxc exec lp1778547-artful -- sh -c 'echo deb http://archive.ubuntu.com/ubuntu artful-proposed main >> /etc/apt/sources.list && apt-get update && apt-cache policy libapt-pkg5.0 && apt-get -y install libapt-pkg5.0'
dpkg-preconfigure: unable to re-open stdin: No such file or directory
+ lxc exec lp1778547-artful -- sh -c 'apt-cache policy libapt-pkg5.0 | grep Inst ; python3 /home/jak/a.py'
  Installed: 1.5.2
[('0', '/dev/pts/4'), ('1', '/dev/pts/4'), ('2', '/dev/pts/4'), ('3', 'pipe:[826053]'), ('4', '/var/lib/dpkg/lock'), ('5', '<deleted>'), ('17', 'socket:[43872]')] ...

Read more...

tags: added: verification-done verification-done-artful verification-done-bionic verification-done-xenial
removed: verification-needed verification-needed-artful verification-needed-bionic verification-needed-xenial

The verification of the Stable Release Update for apt 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 apt - 1.6.2

---------------
apt (1.6.2) unstable; urgency=medium

  * Fix build with new gtest (Closes: #897149)
  * Handle a missed case of timed out ip addresses (LP: #1766542)
  * Lower default network timeouts from 120s to 30s
  * apt-key: Pass all instead of gpg-agent to gpgconf --kill (LP: #1773992)
  * Fix lock counting in debSystem (LP: #1778547)
  * CI fixes:
   - tests: Do not expect requested-by if sudo was invoked by root
   - Run tests on GitLab CI
   - CI: Export DEBIAN_FRONTEND=noninteractive in all CI environments

 -- Julian Andres Klode <email address hidden> Mon, 25 Jun 2018 17:15:10 +0200

Changed in apt (Ubuntu Bionic):
status: Fix Committed → Fix Released
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.5.2

---------------
apt (1.5.2) artful; urgency=medium

  * apt.conf.autoremove: Catch some new Ubuntu module packages (LP: #1778551)
  * Fix lock counting in debSystem (LP: #1778547)

 -- Julian Andres Klode <email address hidden> Tue, 26 Jun 2018 12:51:24 +0200

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

This bug was fixed in the package apt - 1.2.27

---------------
apt (1.2.27) xenial; urgency=medium

  [ David Kalnischkies ]
  * don't hang if multiple sources use unavailable method (Closes: 870675)
    (LP: #1762766)

  [ Julian Andres Klode ]
  * Fix lock counting in debSystem (LP: #1778547)
  * apt.conf.autoremove: Catch some new Ubuntu module packages (LP: #1778551)

 -- Julian Andres Klode <email address hidden> Tue, 26 Jun 2018 12:55:03 +0200

Changed in apt (Ubuntu Xenial):
status: Fix Committed → Fix Released
Julian Andres Klode (juliank) wrote :

Fixed in 1.7.0~alpha1 in cosmic

Changed in apt (Ubuntu):
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