jfs: fix array-index-out-of-bounds in dtSplitPage
PATCH 1/1 jfs: fix array-index-out-of-bounds in dtSplitPage
The dtSplitPage function creates a new struct dt_lock (which wraps struct linelock) using txLinelock. txLinelock initializes the linelock with maxcnt = TLOCKLONG.
However, struct linelock defines the lv array with size 20, while TLOCKLONG is 28. This leads to a mismatch where maxcnt allows indexing beyond the defined array size.
This causes an array-index-out-of-bounds error when dtSplitPage or dtMoveEntry accesses indices between 20 and 27.
Fix this by using TLOCKLONG for the lv array size in struct linelock. This ensures the structure definition matches the maximum possible index used in the code.
The size of struct linelock increases from 48 bytes to 64 bytes, but this fits safely within the 72-byte struct tlock allocation path used by txLinelock. For the txLock path (where linelock overlays tlock.lock[]), the code explicitly sets maxcnt = TLOCKSHORT (20), so access remains within the safe 48-byte limit.
--- fs/jfs/jfs_txnmgr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/jfs/jfs_txnmgr.h +2 -2
@@ -165,8 +165,8 @@ struct linelock {u8 l2linesize;/* 1: log2 of linesize */ /* (8) */ -struct lv lv[20 ];/* 40: */ -};/* (48) */ +struct lv lv[TLOCKLONG ];/* 56: */ +};/* (64) */ #define dt_lock linelock
Signature · 1 line
2.52.0