Skip to content

Commit dd272d2

Browse files
martinpittjelly
authored andcommitted
sosreport: Fix command injection with crafted report names [CVE-2024-2947]
Files in /var/tmp/ are controllable by any user. In particular, an unprivileged user could create an sosreport* file containing a `'` and a shell command, which would then run with root privileges when the admin Cockpit user tried to delete the report. Use the `cockpit.file()` API instead, which entirely avoids shell. The main motivation for using shell and the glob was to ensure that the auxiliary files like *.gpg and *.sha256 get cleaned up -- do that explicitly (which is much safer anyway), and let our tests make sure that we don't leave files behind. https://bugzilla.redhat.com/show_bug.cgi?id=2271614 https://bugzilla.redhat.com/show_bug.cgi?id=2271815 Cherry-picked from main commit 9c4cc9b
1 parent c44296c commit dd272d2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/sosreport/sosreport.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,16 @@ function sosDownload(path) {
220220
}
221221

222222
function sosRemove(path) {
223-
return cockpit.script(cockpit.format("rm -f '$0' '$0'.*", path), { superuser: true, err: "message" });
223+
// there are various potential extra files; not all of them are expected to exist,
224+
// the file API tolerates removing nonexisting files
225+
const paths = [
226+
path,
227+
path + ".asc",
228+
path + ".gpg",
229+
path + ".md5",
230+
path + ".sha256",
231+
];
232+
return Promise.all(paths.map(p => cockpit.file(p, { superuser: true }).replace(null)));
224233
}
225234

226235
const SOSDialog = () => {

test/verify/check-sosreport

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ only-plugins=release,date,host,cgroups,networking
8484
report_gpg = downloaded_sosreports()[0]
8585
base_report_gpg = os.path.basename(report_gpg)
8686
report = report_gpg.replace(".gpg", "")
87+
base_report = base_report_gpg.replace(".gpg", "")
8788

8889
m.execute(f"test -f /var/tmp/{base_report_gpg}")
8990

@@ -100,7 +101,8 @@ only-plugins=release,date,host,cgroups,networking
100101
b.click("tr:contains(mylabel) button.pf-v5-c-dropdown__toggle")
101102
b.click("tr:contains(mylabel) li:contains(Delete)")
102103
b.click("#sos-remove-dialog button:contains(Delete)")
103-
testlib.wait(lambda: m.execute(f"! test -f /var/tmp/{base_report_gpg} && echo yes"))
104+
# ensure it removes the report itself, and auxiliary files like .gpg
105+
m.execute(f"while ls /var/tmp/{base_report}*; do sleep 1; done", stdout=None, timeout=10)
104106

105107
# error reporting
106108
self.write_file("/usr/sbin/sos", """#!/bin/sh

0 commit comments

Comments
 (0)