CVE-2017-7572: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') (CWE-362)
value: The _checkPolkitPrivilege function in serviceHelper.py in Back In Time (aka backintime) 1.1.18 and earlier uses a deprecated polkit authorization method (unix-process) that is subject to a race condition (time of check, time of use). With this authorization method, the owner of a process requesting a polkit operation is checked by polkitd via /proc/<pid>/status, by which time the requesting process may have been replaced by a different process with the same PID that has different privileges then the original requester.
CWE description: The product contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently.
CVSS v3 base score: 8.1
Published: 2017-04-06T18:59Z
Repository: https://github.com/bit-team/backintime
Language: Python
Files changed: qt/serviceHelper.py
Commit date: 2017-04-06 10:33:33 +0200
Commit message: polkit CheckAuthorization: fix race condition in privilege authorization

The unix-process authorization subject is deprecated:

https://www.freedesktop.org/software/polkit/docs/latest/PolkitUnixProcess.html#polkit-unix-process-new

as it is subject to a race condition. A client process requesting
authorization can replace itself by a suid or otherwise root owned
executable, thus granting the original non-privileged request
privileges.

See also:

https://bugzilla.redhat.com/show_bug.cgi?id=1002375
https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack/blob/master/2011/CVE-2011-1485/polkit-pwnage.c

Polkit uses the real-uid of the process by now, thus mitigating the
exploit using suid binaries. It is still possible, however, to exit the
client process and try to get a root program to get the same PID.

In worst case this would allow an unauthenticated user to get backintime
or some other program to be executed via udev rules as root user.

Diff: diff --git a/qt/serviceHelper.py b/qt/serviceHelper.py
index d45d99e5..ec643c11 100644
--- a/qt/serviceHelper.py
+++ b/qt/serviceHelper.py
@@ -280,22 +280,16 @@ class UdevRules(dbus.service.Object):
         if not self.enforce_polkit:
             # that happens for testing purposes when running on the session
             # bus, and it does not make sense to restrict operations here
             return
 
-        info = SenderInfo(sender, conn)
-
-        # get peer PID
-        pid = info.connectionPid()
-
         # query PolicyKit
         self._initPolkit()
         try:
             # we don't need is_challenge return here, since we call with AllowUserInteraction
             (is_auth, _, details) = self.polkit.CheckAuthorization(
-                    ('unix-process', {'pid': dbus.UInt32(pid, variant_level=1),
-                    'start-time': dbus.UInt64(0, variant_level=1)}),
+                    ('system-bus-name', {'name': dbus.String(sender, variant_level=1)}),
                     privilege, {'': ''}, dbus.UInt32(1), '', timeout=3000)
         except dbus.DBusException as e:
             if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
                 # polkitd timed out, connect again
                 self.polkit = None

Vulnerable code:         info = SenderInfo(sender, conn)

        # get peer PID
        pid = info.connectionPid()

                    ('unix-process', {'pid': dbus.UInt32(pid, variant_level=1),
                    'start-time': dbus.UInt64(0, variant_level=1)}),
Fixed code:                     ('system-bus-name', {'name': dbus.String(sender, variant_level=1)}),