/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: teddy at recompile
  • Date: 2020-04-05 21:30:59 UTC
  • Revision ID: teddy@recompile.se-20200405213059-fb2a61ckqynrmatk
Fix file descriptor leak in mandos-client

When the local network has Mandos servers announcing themselves using
real, globally reachable, IPv6 addresses (i.e. not link-local
addresses), but there is no router on the local network providing IPv6
RA (Router Advertisement) packets, the client cannot reach the server
by normal means, since the client only has a link-local IPv6 address,
and has no usable route to reach the server's global IPv6 address.
(This is not a common situation, and usually only happens when the
router itself reboots and runs a Mandos client, since it cannot then
give RA packets to itself.)  The client code has a solution for
this, which consists of adding a temporary local route to reach the
address of the server during communication, and removing this
temporary route afterwards.

This solution with a temporary route works, but has a file descriptor
leak; it leaks one file descriptor for each addition and for each
removal of a route.  If one server requiring an added route is present
on the network, but no servers gives a password, making the client
retry after the default ten seconds, and we furthermore assume a
default 1024 open files limit, the client runs out of file descriptors
after about 90 minutes, after which time the client process will be
useless and fail to retrieve any passwords, necessitating manual
password entry via the keyboard.

Fix this by eliminating the file descriptor leak in the client.

* plugins.d/mandos-client.c (add_delete_local_route): Do
  close(devnull) also in parent process, also if fork() fails, and on
  any failure in child process.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
import collections
79
79
import codecs
80
80
import unittest
 
81
import random
 
82
import shlex
81
83
 
82
84
import dbus
83
85
import dbus.service
93
95
    __metaclass__ = type
94
96
    str = unicode
95
97
 
 
98
# Add collections.abc.Callable if it does not exist
 
99
try:
 
100
    collections.abc.Callable
 
101
except AttributeError:
 
102
    class abc:
 
103
        Callable = collections.Callable
 
104
    collections.abc = abc
 
105
    del abc
 
106
 
 
107
# Add shlex.quote if it does not exist
 
108
try:
 
109
    shlex.quote
 
110
except AttributeError:
 
111
    shlex.quote = re.escape
 
112
 
96
113
# Show warnings by default
97
114
if not sys.warnoptions:
98
115
    import warnings
126
143
if sys.version_info < (3, 2):
127
144
    configparser.Configparser = configparser.SafeConfigParser
128
145
 
129
 
version = "1.8.9"
 
146
version = "1.8.10"
130
147
stored_state_file = "clients.pickle"
131
148
 
132
149
logger = logging.getLogger()
1035
1052
        if self.checker_initiator_tag is not None:
1036
1053
            GLib.source_remove(self.checker_initiator_tag)
1037
1054
        self.checker_initiator_tag = GLib.timeout_add(
1038
 
            int(self.interval.total_seconds() * 1000),
 
1055
            random.randrange(int(self.interval.total_seconds() * 1000
 
1056
                                 + 1)),
1039
1057
            self.start_checker)
1040
1058
        # Schedule a disable() when 'timeout' has passed
1041
1059
        if self.disable_initiator_tag is not None:
1116
1134
        if self.checker is None:
1117
1135
            # Escape attributes for the shell
1118
1136
            escaped_attrs = {
1119
 
                attr: re.escape(str(getattr(self, attr)))
 
1137
                attr: shlex.quote(str(getattr(self, attr)))
1120
1138
                for attr in self.runtime_expansions}
1121
1139
            try:
1122
1140
                command = self.checker_command % escaped_attrs
2746
2764
        if command == 'getattr':
2747
2765
            attrname = request[1]
2748
2766
            if isinstance(client_object.__getattribute__(attrname),
2749
 
                          collections.Callable):
 
2767
                          collections.abc.Callable):
2750
2768
                parent_pipe.send(('function', ))
2751
2769
            else:
2752
2770
                parent_pipe.send((