]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: check whether sscanf has changed the value corresponding to %n
authorEvgeny Vereshchagin <evvers@ya.ru>
Fri, 16 Nov 2018 22:32:31 +0000 (23:32 +0100)
committerEvgeny Vereshchagin <evvers@ya.ru>
Sat, 17 Nov 2018 10:25:19 +0000 (11:25 +0100)
It's possible for sscanf to receive strings containing all three fields
and not matching the template at the same time. When this happens the
value of k doesn't change, which basically means that process_audit_string
tries to access memory randomly. Sometimes it works and sometimes it doesn't :-)

See also https://bugzilla.redhat.com/show_bug.cgi?id=1059314.

src/journal/journald-audit.c
test/fuzz/fuzz-journald-audit/crash [new file with mode: 0644]

index 94484f5d01c68244cf456c9930b5bf60cd2f7dc9..345e43ef44f7d3627be1b50cf922c24d397345fb 100644 (file)
@@ -341,11 +341,12 @@ void process_audit_string(Server *s, int type, const char *data, size_t size) {
         if (!p)
                 return;
 
+        k = 0;
         if (sscanf(p, "(%" PRIu64 ".%" PRIu64 ":%" PRIu64 "):%n",
                    &seconds,
                    &msec,
                    &id,
-                   &k) != 3)
+                   &k) != 3 || k == 0)
                 return;
 
         p += k;
diff --git a/test/fuzz/fuzz-journald-audit/crash b/test/fuzz/fuzz-journald-audit/crash
new file mode 100644 (file)
index 0000000..91bd85c
--- /dev/null
@@ -0,0 +1 @@
+audit(1542398162.211:744) pid=7376 uid=1000 auid=1000 ses=6 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:accounting grantors=pam_unix,pam_localuser acct="vagrant" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/1 res=success'