Skip to content

Commit 19bca4c

Browse files
authored
Pass the exported blacklist to mintupdate-automation on stdin (#1096)
* Pass the exported blacklist to mintupdate-automation on stdin Exporting the blacklist wrote it to /tmp/mintUpdate/blacklist, then mintupdate-automation read that path as root after pkexec authentication. Another local user can replace the file (or plant a symlink) while the authentication dialog is open, so root appended arbitrary lines or the contents of any file, e.g. /etc/shadow, to world-readable /etc/mintupdate.blacklist. Pipe the blacklist to the helper on stdin instead. * Remove accidentally committed .pyc file --------- Co-authored-by: lbellows <19894143+lbellows@users.noreply.github.com>
1 parent 82c61f0 commit 19bca4c

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

‎usr/bin/mintupdate-automation‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ def do_disable(_automation_id):
5555
print("%s %s removed." % (name, filename))
5656

5757
def add_user_blacklist(outfile):
58-
import tempfile
58+
# The user's blacklist arrives on stdin. Never read it from a shared
59+
# location such as /tmp: another user could swap the file for a symlink
60+
# while the authentication dialog is open.
61+
if sys.stdin is None or sys.stdin.isatty():
62+
return
5963
try:
60-
infile = os.path.join(tempfile.gettempdir(), "mintUpdate/blacklist")
61-
with open(infile, "r") as export:
62-
with open(outfile, "a") as f:
63-
for line in export:
64-
f.write(line)
65-
os.remove(infile)
64+
with open(outfile, "a") as f:
65+
for line in sys.stdin:
66+
f.write(line)
6667
print("User blacklist exported.")
6768
except:
6869
pass

‎usr/lib/linuxmint/mintUpdate/preferences.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import json
66
import os
77
import subprocess
8-
import tempfile
98

109
import gi
1110
gi.require_version('Gtk', '3.0')
@@ -215,11 +214,9 @@ def _build_automation(self, builder):
215214
section.add_row(switch)
216215

217216
def _export_blacklist(self, widget):
218-
filename = os.path.join(tempfile.gettempdir(), "mintUpdate/blacklist")
219217
blacklist = self.settings.get_strv("blacklisted-packages")
220-
with open(filename, "w") as f:
221-
f.write("\n".join(blacklist) + "\n")
222-
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "blacklist", "enable"])
218+
subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "blacklist", "enable"],
219+
input="\n".join(blacklist) + "\n", text=True)
223220

224221
def _set_auto_upgrade(self, widget, param):
225222
self._toggle_automation(widget, "upgrade")

0 commit comments

Comments
 (0)