[PATCH] jfs: fix array-index-out-of-bounds in dtExtendPage

Kery Qi posted 1 patch 2 weeks, 2 days ago
fs/jfs/jfs_dtree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] jfs: fix array-index-out-of-bounds in dtExtendPage
Posted by Kery Qi 2 weeks, 2 days ago
Similar to the issue fixed in commit 27e56f59bab5 ("UBSAN:
array-index-out-of-bounds in dtSplitRoot"), the loop that traverses
the freelist in dtExtendPage() uses the condition (fsi != -1) to
terminate. However, if the filesystem image is corrupted or maliciously
crafted, f->next could contain a value less than -1 (e.g., -2), causing
the loop to continue and resulting in an out-of-bounds array access
when indexing sp->slot[fsi].

Fix this by changing the loop termination condition from (fsi != -1)
to (fsi >= 0), so that any negative value will properly terminate the
loop.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
 fs/jfs/jfs_dtree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 0ab83bb7bbdf..3e365ccfb33b 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -1804,7 +1804,7 @@ static int dtExtendPage(tid_t tid,
 		do {
 			f = &sp->slot[fsi];
 			fsi = f->next;
-		} while (fsi != -1);
+		} while (fsi >= 0);
 
 		f->next = n;
 	}
-- 
2.34.1