Skip to contentSkip to conversation

xfs: fix mount failure crash on invalid iclog memory access

PATCH In review Brian Foster 2 participants 3 messages Dec 3, 2019 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix mount failure crash on invalid iclog memory access

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.

---
 fs/xfs/xfs_log.c | 2 ++
 1 file changed, 2 insertions(+)
fs/xfs/xfs_log.c +2 -0
index 6a147c63a8a6..f6006d94a581 100644
@@ -1542,6 +1542,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);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 13 lines · Brian Foster

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.

Quoted 3 lines

---

Hmm.. I didn't realize Hillf Danton already replied to the original thread with this same fix until I looked at the ML archive. His reply isn't in my mailbox for some reason. Anyways, feel free to skip this patch in favor of that one..

Brian

Quoted 19 lines
 fs/xfs/xfs_log.c | 2 ++
 1 file changed, 2 insertions(+)
fs/xfs/xfs_log.c +2 -0
index 6a147c63a8a6..f6006d94a581 100644
@@ -1542,6 +1542,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);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Brian Foster
Quoted 13 lines · Brian Foster

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.

Quoted 2 lines

Ahh, a proper S-o-B! Thank you,

--D

Quoted 20 lines
---
 fs/xfs/xfs_log.c | 2 ++
 1 file changed, 2 insertions(+)
fs/xfs/xfs_log.c +2 -0
index 6a147c63a8a6..f6006d94a581 100644
@@ -1542,6 +1542,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);
Signature · 1 line
2.20.1