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)
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>
Tue, 3 Dec 2019 09:06:23 +0000 (10:06 +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.

(cherry picked from commit 1dab14aba749b9c5ab8176c5730107b70834240b)

Resolves: #1764560

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

index 7810a0139a96e1bd75ee5e773c10bb0aab3cddcc..0fd6ab2a84539ad0c6b77fbdac7e7a05b481240c 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'