__init__.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. # coding=utf-8
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2013-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  5. # Copyright (C) 2013-2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. ''' Qrexec policy parser and evaluator '''
  22. import enum
  23. import itertools
  24. import json
  25. import os
  26. import os.path
  27. import socket
  28. import subprocess
  29. # don't import 'qubes.config' please, it takes 0.3s
  30. QREXEC_CLIENT = '/usr/lib/qubes/qrexec-client'
  31. QUBES_RPC_MULTIPLEXER_PATH = '/usr/lib/qubes/qubes-rpc-multiplexer'
  32. POLICY_DIR = '/etc/qubes-rpc/policy'
  33. QUBESD_INTERNAL_SOCK = '/var/run/qubesd.internal.sock'
  34. QUBESD_SOCK = '/var/run/qubesd.sock'
  35. class AccessDenied(Exception):
  36. ''' Raised when qrexec policy denied access '''
  37. pass
  38. class PolicySyntaxError(AccessDenied):
  39. ''' Syntax error in qrexec policy, abort parsing '''
  40. def __init__(self, filename, lineno, msg):
  41. super(PolicySyntaxError, self).__init__(
  42. '{}:{}: {}'.format(filename, lineno, msg))
  43. class Action(enum.Enum):
  44. ''' Action as defined by policy '''
  45. allow = 1
  46. deny = 2
  47. ask = 3
  48. def verify_target_value(system_info, value):
  49. ''' Check if given value names valid target
  50. This function check if given value is not only syntactically correct,
  51. but also if names valid service call target (existing domain,
  52. or valid $dispvm like keyword)
  53. :param system_info: information about the system
  54. :param value: value to be checked
  55. '''
  56. if value == '$dispvm':
  57. return True
  58. elif value == '$adminvm':
  59. return True
  60. elif value.startswith('$dispvm:'):
  61. dispvm_base = value.split(':', 1)[1]
  62. if dispvm_base not in system_info['domains']:
  63. return False
  64. dispvm_base_info = system_info['domains'][dispvm_base]
  65. return bool(dispvm_base_info['dispvm_allowed'])
  66. else:
  67. return value in system_info['domains']
  68. def verify_special_value(value, for_target=True):
  69. '''
  70. Verify if given special VM-specifier ('$...') is valid
  71. :param value: value to verify
  72. :param for_target: should classify target-only values as valid (
  73. '$default', '$dispvm')
  74. :return: True or False
  75. '''
  76. # pylint: disable=too-many-return-statements
  77. if value.startswith('$tag:') and len(value) > len('$tag:'):
  78. return True
  79. elif value.startswith('$type:') and len(value) > len('$type:'):
  80. return True
  81. elif value == '$anyvm':
  82. return True
  83. elif value == '$adminvm':
  84. return True
  85. elif value.startswith('$dispvm:') and for_target:
  86. return True
  87. elif value == '$dispvm' and for_target:
  88. return True
  89. elif value == '$default' and for_target:
  90. return True
  91. return False
  92. class PolicyRule(object):
  93. ''' A single line of policy file '''
  94. def __init__(self, line, filename=None, lineno=None):
  95. '''
  96. Load a single line of qrexec policy and check its syntax.
  97. Do not verify existence of named objects.
  98. :raise PolicySyntaxError: when syntax error is found
  99. :param line: a single line of actual qrexec policy (not a comment,
  100. empty line or $include)
  101. :param filename: name of the file from which this line is loaded
  102. :param lineno: line number from which this line is loaded
  103. '''
  104. self.lineno = lineno
  105. self.filename = filename
  106. try:
  107. self.source, self.target, self.full_action = line.split(maxsplit=2)
  108. except ValueError:
  109. raise PolicySyntaxError(filename, lineno, 'wrong number of fields')
  110. (action, *params) = self.full_action.replace(',', ' ').split()
  111. try:
  112. self.action = Action[action]
  113. except KeyError:
  114. raise PolicySyntaxError(filename, lineno,
  115. 'invalid action: {}'.format(action))
  116. #: alternative target, used instead of the one specified by the caller
  117. self.override_target = None
  118. #: alternative user, used instead of vm.default_user
  119. self.override_user = None
  120. #: default target when asking the user for confirmation
  121. self.default_target = None
  122. for param in params:
  123. try:
  124. param_name, value = param.split('=')
  125. except ValueError:
  126. raise PolicySyntaxError(filename, lineno,
  127. 'invalid action parameter syntax: {}'.format(param))
  128. if param_name == 'target':
  129. if self.action == Action.deny:
  130. raise PolicySyntaxError(filename, lineno,
  131. 'target= option not allowed for deny action')
  132. self.override_target = value
  133. elif param_name == 'user':
  134. if self.action == Action.deny:
  135. raise PolicySyntaxError(filename, lineno,
  136. 'user= option not allowed for deny action')
  137. self.override_user = value
  138. elif param_name == 'default_target':
  139. if self.action != Action.ask:
  140. raise PolicySyntaxError(filename, lineno,
  141. 'default_target= option allowed only for ask action')
  142. self.default_target = value
  143. else:
  144. raise PolicySyntaxError(filename, lineno,
  145. 'invalid option {} for {} action'.format(param, action))
  146. # verify special values
  147. if self.source.startswith('$'):
  148. if not verify_special_value(self.source, False):
  149. raise PolicySyntaxError(filename, lineno,
  150. 'invalid source specification: {}'.format(self.source))
  151. if self.target.startswith('$'):
  152. if not verify_special_value(self.target, True):
  153. raise PolicySyntaxError(filename, lineno,
  154. 'invalid target specification: {}'.format(self.target))
  155. if self.target == '$default' \
  156. and self.action == Action.allow \
  157. and self.override_target is None:
  158. raise PolicySyntaxError(filename, lineno,
  159. 'allow action for $default rule must specify target= option')
  160. if self.override_target is not None:
  161. if self.override_target.startswith('$') and \
  162. not self.override_target.startswith('$dispvm') and \
  163. self.override_target != '$adminvm':
  164. raise PolicySyntaxError(filename, lineno,
  165. 'target= option needs to name specific target')
  166. @staticmethod
  167. def is_match_single(system_info, policy_value, value):
  168. '''
  169. Evaluate if a single value (VM name or '$default') matches policy
  170. specification
  171. :param system_info: information about the system
  172. :param policy_value: value from qrexec policy (either self.source or
  173. self.target)
  174. :param value: value to be compared (source or target)
  175. :return: True or False
  176. '''
  177. # pylint: disable=too-many-return-statements
  178. # not specified target matches only with $default and $anyvm policy
  179. # entry
  180. if value == '$default' or value == '':
  181. return policy_value in ('$default', '$anyvm')
  182. # if specific target used, check if it's valid
  183. # this function (is_match_single) is also used for checking call source
  184. # values, but this isn't a problem, because it will always be a
  185. # domain name (not $dispvm or such) - this is guaranteed by a nature
  186. # of qrexec call
  187. if not verify_target_value(system_info, value):
  188. return False
  189. # handle $adminvm keyword
  190. if policy_value == 'dom0':
  191. # TODO: log a warning in Qubes 4.1
  192. policy_value = '$adminvm'
  193. if value == 'dom0':
  194. value = '$adminvm'
  195. # allow any _valid_, non-dom0 target
  196. if policy_value == '$anyvm':
  197. return value != '$adminvm'
  198. # exact match, including $dispvm* and $adminvm
  199. if value == policy_value:
  200. return True
  201. # if $dispvm* not matched above, reject it; missing ':' is
  202. # intentional - handle both '$dispvm' and '$dispvm:xxx'
  203. if value.startswith('$dispvm'):
  204. return False
  205. # require $adminvm to be matched explicitly (not through $tag or $type)
  206. # - if not matched already, reject it
  207. if value == '$adminvm':
  208. return False
  209. # at this point, value name a specific target
  210. domain_info = system_info['domains'][value]
  211. if policy_value.startswith('$tag:'):
  212. tag = policy_value.split(':', 1)[1]
  213. return tag in domain_info['tags']
  214. if policy_value.startswith('$type:'):
  215. type_ = policy_value.split(':', 1)[1]
  216. return type_ == domain_info['type']
  217. return False
  218. def is_match(self, system_info, source, target):
  219. '''
  220. Check if given (source, target) matches this policy line.
  221. :param system_info: information about the system - available VMs,
  222. their types, labels, tags etc. as returned by
  223. :py:func:`app_to_system_info`
  224. :param source: name of the source VM
  225. :param target: name of the target VM, or None if not specified
  226. :return: True or False
  227. '''
  228. if not self.is_match_single(system_info, self.source, source):
  229. return False
  230. if not self.is_match_single(system_info, self.target, target):
  231. return False
  232. return True
  233. def expand_target(self, system_info):
  234. '''
  235. Return domains matching target of this policy line
  236. :param system_info: information about the system
  237. :return: matching domains
  238. '''
  239. if self.target.startswith('$tag:'):
  240. tag = self.target.split(':', 1)[1]
  241. for name, domain in system_info['domains'].items():
  242. if tag in domain['tags']:
  243. yield name
  244. elif self.target.startswith('$type:'):
  245. type_ = self.target.split(':', 1)[1]
  246. for name, domain in system_info['domains'].items():
  247. if type_ == domain['type']:
  248. yield name
  249. elif self.target == '$anyvm':
  250. for name, domain in system_info['domains'].items():
  251. if name != 'dom0':
  252. yield name
  253. if domain['dispvm_allowed']:
  254. yield '$dispvm:' + name
  255. yield '$dispvm'
  256. elif self.target.startswith('$dispvm:'):
  257. dispvm_base = self.target.split(':', 1)[1]
  258. try:
  259. if system_info['domains'][dispvm_base]['dispvm_allowed']:
  260. yield self.target
  261. except KeyError:
  262. # TODO log a warning?
  263. pass
  264. elif self.target == '$adminvm':
  265. yield self.target
  266. elif self.target == '$dispvm':
  267. yield self.target
  268. else:
  269. if self.target in system_info['domains']:
  270. yield self.target
  271. def expand_override_target(self, system_info, source):
  272. '''
  273. Replace '$dispvm' with specific '$dispvm:...' value, based on qrexec
  274. call source.
  275. :param system_info: System information
  276. :param source: Source domain name
  277. :return: :py:attr:`override_target` with '$dispvm' substituted
  278. '''
  279. if self.override_target == '$dispvm':
  280. if system_info['domains'][source]['default_dispvm'] is None:
  281. return None
  282. return '$dispvm:' + system_info['domains'][source]['default_dispvm']
  283. else:
  284. return self.override_target
  285. class PolicyAction(object):
  286. ''' Object representing positive policy evaluation result -
  287. either ask or allow action '''
  288. def __init__(self, service, source, target, rule, original_target,
  289. targets_for_ask=None):
  290. #: service name
  291. self.service = service
  292. #: calling domain
  293. self.source = source
  294. #: target domain the service should be connected to, None if
  295. # not chosen yet
  296. if targets_for_ask is None or target in targets_for_ask:
  297. self.target = target
  298. else:
  299. # TODO: log a warning?
  300. self.target = None
  301. #: original target specified by the caller
  302. self.original_target = original_target
  303. #: targets for the user to choose from
  304. self.targets_for_ask = targets_for_ask
  305. #: policy rule from which this action is derived
  306. self.rule = rule
  307. if rule.action == Action.deny:
  308. # this should be really rejected by Policy.eval()
  309. raise AccessDenied(
  310. 'denied by policy {}:{}'.format(rule.filename, rule.lineno))
  311. elif rule.action == Action.ask:
  312. assert targets_for_ask is not None
  313. elif rule.action == Action.allow:
  314. assert targets_for_ask is None
  315. assert target is not None
  316. self.action = rule.action
  317. def handle_user_response(self, response, target=None):
  318. '''
  319. Handle user response for the 'ask' action
  320. :param response: whether the call was allowed or denied (bool)
  321. :param target: target chosen by the user (if reponse==True)
  322. :return: None
  323. '''
  324. assert self.action == Action.ask
  325. if response:
  326. assert target in self.targets_for_ask
  327. self.target = target
  328. self.action = Action.allow
  329. else:
  330. self.action = Action.deny
  331. raise AccessDenied(
  332. 'denied by the user {}:{}'.format(self.rule.filename,
  333. self.rule.lineno))
  334. def execute(self, caller_ident):
  335. ''' Execute allowed service call
  336. :param caller_ident: Service caller ident
  337. (`process_ident,source_name, source_id`)
  338. '''
  339. assert self.action == Action.allow
  340. assert self.target is not None
  341. if self.target == '$adminvm':
  342. self.target = 'dom0'
  343. if self.target == 'dom0':
  344. cmd = '{multiplexer} {service} {source} {original_target}'.format(
  345. multiplexer=QUBES_RPC_MULTIPLEXER_PATH,
  346. service=self.service,
  347. source=self.source,
  348. original_target=self.original_target)
  349. else:
  350. cmd = '{user}:QUBESRPC {service} {source}'.format(
  351. user=(self.rule.override_user or 'DEFAULT'),
  352. service=self.service,
  353. source=self.source)
  354. if self.target.startswith('$dispvm:'):
  355. target = self.spawn_dispvm()
  356. dispvm = True
  357. else:
  358. target = self.target
  359. dispvm = False
  360. self.ensure_target_running()
  361. qrexec_opts = ['-d', target, '-c', caller_ident]
  362. if dispvm:
  363. qrexec_opts.append('-W')
  364. try:
  365. subprocess.call([QREXEC_CLIENT] + qrexec_opts + [cmd])
  366. finally:
  367. if dispvm:
  368. self.cleanup_dispvm(target)
  369. def spawn_dispvm(self):
  370. '''
  371. Create and start Disposable VM based on AppVM specified in
  372. :py:attr:`target`
  373. :return: name of new Disposable VM
  374. '''
  375. base_appvm = self.target.split(':', 1)[1]
  376. dispvm_name = qubesd_call(base_appvm, 'admin.vm.CreateDisposable')
  377. dispvm_name = dispvm_name.decode('ascii')
  378. qubesd_call(dispvm_name, 'admin.vm.Start')
  379. return dispvm_name
  380. def ensure_target_running(self):
  381. '''
  382. Start domain if not running already
  383. :return: None
  384. '''
  385. if self.target == 'dom0':
  386. return
  387. try:
  388. qubesd_call(self.target, 'admin.vm.Start')
  389. except QubesMgmtException as e:
  390. if e.exc_type == 'QubesVMNotHaltedError':
  391. pass
  392. else:
  393. raise
  394. @staticmethod
  395. def cleanup_dispvm(dispvm):
  396. '''
  397. Kill and remove Disposable VM
  398. :param dispvm: name of Disposable VM
  399. :return: None
  400. '''
  401. qubesd_call(dispvm, 'admin.vm.Kill')
  402. class Policy(object):
  403. ''' Full policy for a given service
  404. Usage:
  405. >>> system_info = get_system_info()
  406. >>> policy = Policy('some-service')
  407. >>> action = policy.evaluate(system_info, 'source-name', 'target-name')
  408. >>> if action.action == Action.ask:
  409. >>> # ... ask the user, see action.targets_for_ask ...
  410. >>> action.handle_user_response(response, target_chosen_by_user)
  411. >>> action.execute('process-ident')
  412. '''
  413. def __init__(self, service, policy_dir=POLICY_DIR):
  414. policy_file = os.path.join(policy_dir, service)
  415. if not os.path.exists(policy_file):
  416. # fallback to policy without specific argument set (if any)
  417. policy_file = os.path.join(policy_dir, service.split('+')[0])
  418. #: policy storage directory
  419. self.policy_dir = policy_dir
  420. #: service name
  421. self.service = service
  422. #: list of PolicyLine objects
  423. self.policy_rules = []
  424. try:
  425. self.load_policy_file(policy_file)
  426. except OSError as e:
  427. raise AccessDenied(
  428. 'failed to load {} file: {!s}'.format(e.filename, e))
  429. def load_policy_file(self, path):
  430. ''' Load policy file and append rules to :py:attr:`policy_rules`
  431. :param path: file to load
  432. '''
  433. with open(path) as policy_file:
  434. for lineno, line in zip(itertools.count(start=1),
  435. policy_file.readlines()):
  436. line = line.strip()
  437. if not line:
  438. # skip empty lines
  439. continue
  440. if line[0] == '#':
  441. # skip comments
  442. continue
  443. if line.startswith('$include:'):
  444. include_path = line.split(':', 1)[1]
  445. # os.path.join will leave include_path unchanged if it's
  446. # already absolute
  447. include_path = os.path.join(self.policy_dir, include_path)
  448. self.load_policy_file(include_path)
  449. else:
  450. self.policy_rules.append(PolicyRule(line, path, lineno))
  451. def find_matching_rule(self, system_info, source, target):
  452. ''' Find the first rule matching given arguments '''
  453. for rule in self.policy_rules:
  454. if rule.is_match(system_info, source, target):
  455. return rule
  456. raise AccessDenied('no matching rule found')
  457. def collect_targets_for_ask(self, system_info, source):
  458. ''' Collect targets the user can choose from in 'ask' action
  459. Word 'targets' is used intentionally instead of 'domains', because it
  460. can also contains $dispvm like keywords.
  461. '''
  462. targets = set()
  463. # iterate over rules in reversed order to easier handle 'deny'
  464. # actions - simply remove matching domains from allowed set
  465. for rule in reversed(self.policy_rules):
  466. if rule.is_match_single(system_info, rule.source, source):
  467. if rule.action == Action.deny:
  468. targets -= set(rule.expand_target(system_info))
  469. else:
  470. if rule.override_target is not None:
  471. override_target = rule.expand_override_target(
  472. system_info, source)
  473. if verify_target_value(system_info, override_target):
  474. targets.add(rule.override_target)
  475. else:
  476. targets.update(rule.expand_target(system_info))
  477. # expand default DispVM
  478. if '$dispvm' in targets:
  479. targets.remove('$dispvm')
  480. if system_info['domains'][source]['default_dispvm'] is not None:
  481. dispvm = '$dispvm:' + \
  482. system_info['domains'][source]['default_dispvm']
  483. if verify_target_value(system_info, dispvm):
  484. targets.add(dispvm)
  485. return targets
  486. def evaluate(self, system_info, source, target):
  487. ''' Evaluate policy
  488. :raise AccessDenied: when action should be denied unconditionally
  489. :return tuple(rule, considered_targets) - where considered targets is a
  490. list of possible targets for 'ask' action (rule.action == Action.ask)
  491. '''
  492. rule = self.find_matching_rule(system_info, source, target)
  493. if rule.action == Action.deny:
  494. raise AccessDenied(
  495. 'denied by policy {}:{}'.format(rule.filename, rule.lineno))
  496. if rule.override_target is not None:
  497. override_target = rule.expand_override_target(system_info, source)
  498. if not verify_target_value(system_info, override_target):
  499. raise AccessDenied('invalid target= value in {}:{}'.format(
  500. rule.filename, rule.lineno))
  501. actual_target = override_target
  502. else:
  503. actual_target = target
  504. if rule.action == Action.ask:
  505. if rule.override_target is not None:
  506. targets = [actual_target]
  507. else:
  508. targets = list(
  509. self.collect_targets_for_ask(system_info, source))
  510. if not targets:
  511. raise AccessDenied(
  512. 'policy define \'ask\' action at {}:{} but no target is '
  513. 'available to choose from'.format(
  514. rule.filename, rule.lineno))
  515. return PolicyAction(self.service, source, rule.default_target,
  516. rule, target, targets)
  517. elif rule.action == Action.allow:
  518. if actual_target == '$default':
  519. raise AccessDenied(
  520. 'policy define \'allow\' action at {}:{} but no target is '
  521. 'specified by caller or policy'.format(
  522. rule.filename, rule.lineno))
  523. if actual_target == '$dispvm':
  524. if system_info['domains'][source]['default_dispvm'] is None:
  525. raise AccessDenied(
  526. 'policy define \'allow\' action to $dispvm at {}:{} '
  527. 'but no DispVM base is set for this VM'.format(
  528. rule.filename, rule.lineno))
  529. actual_target = '$dispvm:' + \
  530. system_info['domains'][source]['default_dispvm']
  531. return PolicyAction(self.service, source,
  532. actual_target, rule, target)
  533. else:
  534. # should be unreachable
  535. raise AccessDenied(
  536. 'invalid action?! {}:{}'.format(rule.filename, rule.lineno))
  537. class QubesMgmtException(Exception):
  538. ''' Exception returned by qubesd '''
  539. def __init__(self, exc_type):
  540. super(QubesMgmtException, self).__init__()
  541. self.exc_type = exc_type
  542. def qubesd_call(dest, method, arg=None, payload=None):
  543. if method.startswith('internal.'):
  544. socket_path = QUBESD_INTERNAL_SOCK
  545. else:
  546. socket_path = QUBESD_SOCK
  547. try:
  548. client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  549. client_socket.connect(socket_path)
  550. except IOError:
  551. # TODO:
  552. raise
  553. # src, method, dest, arg
  554. for call_arg in ('dom0', method, dest, arg):
  555. if call_arg is not None:
  556. client_socket.sendall(call_arg.encode('ascii'))
  557. client_socket.sendall(b'\0')
  558. if payload is not None:
  559. client_socket.sendall(payload)
  560. client_socket.shutdown(socket.SHUT_WR)
  561. return_data = client_socket.makefile('rb').read()
  562. if return_data.startswith(b'0\x00'):
  563. return return_data[2:]
  564. elif return_data.startswith(b'2\x00'):
  565. (_, exc_type, _traceback, _format_string, _args) = \
  566. return_data.split(b'\x00', 4)
  567. raise QubesMgmtException(exc_type.decode('ascii'))
  568. else:
  569. raise AssertionError(
  570. 'invalid qubesd response: {!r}'.format(return_data))
  571. def get_system_info():
  572. ''' Get system information
  573. This retrieve information necessary to process qrexec policy. Returned
  574. data is nested dict structure with this structure:
  575. - domains:
  576. - `<domain name>`:
  577. - tags: list of tags
  578. - type: domain type
  579. - dispvm_allowed: should DispVM based on this VM be allowed
  580. - default_dispvm: name of default AppVM for DispVMs started from here
  581. '''
  582. system_info = qubesd_call('dom0', 'internal.GetSystemInfo')
  583. return json.loads(system_info.decode('utf-8'))