xfs: fix mount failure crash on invalid iclog memory access
authorBrian Foster <bfoster@redhat.com>
Tue, 3 Dec 2019 15:53:15 +0000 (07:53 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 Jan 2020 18:18:43 +0000 (19:18 +0100)
commit 798a9cada4694ca8d970259f216cec47e675bfd5 upstream.

syzbot (via KASAN) reports a use-after-free in the error path of
xlog_alloc_log(). Specifically, the iclog freeing loop doesn't
handle the case of a fully initialized ->l_iclog linked list.
Instead, it assumes that the list is partially constructed and NULL
terminated.

This bug manifested because there was no possible error scenario
after iclog list setup when the original code was added.  Subsequent
code and associated error conditions were added some time later,
while the original error handling code was never updated. Fix up the
error loop to terminate either on a NULL iclog or reaching the end
of the list.

Reported-by: syzbot+c732f8644185de340492@syzkaller.appspotmail.com
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/xfs_log.c

index 641d07f30a2771731dede545dbeb219cef43f5a6..7b0d9ad8cb1a9dd424e96d4d66344df1f14279ad 100644 (file)
@@ -1495,6 +1495,8 @@ xlog_alloc_log(
                prev_iclog = iclog->ic_next;
                kmem_free(iclog->ic_data);
                kmem_free(iclog);
+               if (prev_iclog == log->l_iclog)
+                       break;
        }
 out_free_log:
        kmem_free(log);