jfs: fix array-index-out-of-bounds in dtExtendPage
PATCH 1/1 jfs: fix array-index-out-of-bounds in dtExtendPage
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 <[email protected]>
--- fs/jfs/jfs_dtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dtree.c +1 -1
@@ -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; }
Signature · 1 line
2.34.1