Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion qubesagent/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,18 @@
self.qdb.rm('/dns/{}/'.format(source))

for host, hostaddrs in dns.items():
self.qdb.write('/dns/{}/{}'.format(source, host), str(hostaddrs))
path = '/dns/{}/{}'.format(source, host)
try:
self.qdb.write(path, str(hostaddrs))
except Exception as err:
if len(path) > 64 and err.args == (0, 'Error'):
self.log.error(('Unable to add DNS information for {} ({})'
' due to qubesdb path length limit').format(
host, source))
self.log.error('See https://github.com/QubesOS/'
'qubes-issues/issues/9084')
else:
raise

Check warning on line 181 in qubesagent/firewall.py

View check run for this annotation

Codecov / codecov/patch

qubesagent/firewall.py#L181

Added line #L181 was not covered by tests

def update_handled(self, addr):
"""
Expand Down
21 changes: 21 additions & 0 deletions qubesagent/test_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def rm(self, path):
self.entries.pop(path)

def write(self, path, val):
if len(path) > 64:
raise DummyQubesDBError(0, 'Error')
self.entries[path] = val

def multiread(self, prefix):
Expand All @@ -65,6 +67,8 @@ def read_watch(self):
except IndexError:
return None

class DummyQubesDBError(Exception):
"Raised by QubesDB"

class FirewallWorker(qubesagent.firewall.FirewallWorker):
def __init__(self):
Expand Down Expand Up @@ -159,6 +163,23 @@ def test_701_dns_info(self):
self.obj.apply_rules('10.137.0.1', [{'action': 'drop'}])
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.1/ripe.net'))

def test_702_dns_info_qubesdb_path_length_crash(self):
self.obj.conntrack_get_connections = Mock(return_value=[])
rules = [
{'action': 'accept', 'proto': 'tcp',
'dstports': '443-443', 'dsthost': 'www.google.com'},
{'action': 'accept', 'proto': 'tcp',
'dstports': '443-443', 'dsthost': 'prod-dynamite-prod-05-us-signaler-pa.clients6.google.com'},
{'action': 'drop'},
]
self.obj.apply_rules('10.137.0.22', rules)
self.assertIsNotNone(self.obj.qdb.read('/dns/10.137.0.22/www.google.com'))
# Unfortunately, this is assertIsNone until the QubesDB path length limit is raised.
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.22/prod-dynamite-prod-05-us-signaler-pa.clients6.google.com'))
self.obj.apply_rules('10.137.0.22', [{'action': 'drop'}])
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.22/www.google.com'))
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.22/prod-dynamite-prod-05-us-signaler-pa.clients6.google.com'))

class TestNftablesWorker(TestCase, WorkerCommon):
def setUp(self):
super(TestNftablesWorker, self).setUp()
Expand Down