Skip to content

Commit 1cbf99e

Browse files
committed
Merge tag 'jfs-6.16' of github.com:kleikamp/linux-shaggy
Pull jfs updates from David Kleikamp: "A few small fixes for jfs" * tag 'jfs-6.16' of github.com:kleikamp/linux-shaggy: jfs: fix array-index-out-of-bounds read in add_missing_indices jfs: Fix null-ptr-deref in jfs_ioc_trim jfs: validate AG parameters in dbMount() to prevent crashes
2 parents b1fd8bd + 5dff41a commit 1cbf99e

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

fs/jfs/jfs_discard.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
8686
down_read(&sb->s_umount);
8787
bmp = JFS_SBI(ip->i_sb)->bmap;
8888

89-
if (minlen > bmp->db_agsize ||
89+
if (bmp == NULL ||
90+
minlen > bmp->db_agsize ||
9091
start >= bmp->db_mapsize ||
9192
range->len < sb->s_blocksize) {
9293
up_read(&sb->s_umount);

fs/jfs/jfs_dmap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ int dbMount(struct inode *ipbmap)
194194
!bmp->db_numag || (bmp->db_numag > MAXAG) ||
195195
(bmp->db_maxag >= MAXAG) || (bmp->db_maxag < 0) ||
196196
(bmp->db_agpref >= MAXAG) || (bmp->db_agpref < 0) ||
197-
!bmp->db_agwidth ||
197+
(bmp->db_agheight < 0) || (bmp->db_agheight > (L2LPERCTL >> 1)) ||
198+
(bmp->db_agwidth < 1) || (bmp->db_agwidth > (LPERCTL / MAXAG)) ||
199+
(bmp->db_agwidth > (1 << (L2LPERCTL - (bmp->db_agheight << 1)))) ||
200+
(bmp->db_agstart < 0) ||
201+
(bmp->db_agstart > (CTLTREESIZE - 1 - bmp->db_agwidth * (MAXAG - 1))) ||
198202
(bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG) ||
199203
(bmp->db_agl2size < 0) ||
200204
((bmp->db_mapsize - 1) >> bmp->db_agl2size) > MAXAG) {

fs/jfs/jfs_dtree.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ void dtInitRoot(tid_t tid, struct inode *ip, u32 idotdot)
26132613
* fsck.jfs should really fix this, but it currently does not.
26142614
* Called from jfs_readdir when bad index is detected.
26152615
*/
2616-
static void add_missing_indices(struct inode *inode, s64 bn)
2616+
static int add_missing_indices(struct inode *inode, s64 bn)
26172617
{
26182618
struct ldtentry *d;
26192619
struct dt_lock *dtlck;
@@ -2622,7 +2622,7 @@ static void add_missing_indices(struct inode *inode, s64 bn)
26222622
struct lv *lv;
26232623
struct metapage *mp;
26242624
dtpage_t *p;
2625-
int rc;
2625+
int rc = 0;
26262626
s8 *stbl;
26272627
tid_t tid;
26282628
struct tlock *tlck;
@@ -2647,6 +2647,16 @@ static void add_missing_indices(struct inode *inode, s64 bn)
26472647

26482648
stbl = DT_GETSTBL(p);
26492649
for (i = 0; i < p->header.nextindex; i++) {
2650+
if (stbl[i] < 0) {
2651+
jfs_err("jfs: add_missing_indices: Invalid stbl[%d] = %d for inode %ld, block = %lld",
2652+
i, stbl[i], (long)inode->i_ino, (long long)bn);
2653+
rc = -EIO;
2654+
2655+
DT_PUTPAGE(mp);
2656+
txAbort(tid, 0);
2657+
goto end;
2658+
}
2659+
26502660
d = (struct ldtentry *) &p->slot[stbl[i]];
26512661
index = le32_to_cpu(d->index);
26522662
if ((index < 2) || (index >= JFS_IP(inode)->next_index)) {
@@ -2664,6 +2674,7 @@ static void add_missing_indices(struct inode *inode, s64 bn)
26642674
(void) txCommit(tid, 1, &inode, 0);
26652675
end:
26662676
txEnd(tid);
2677+
return rc;
26672678
}
26682679

26692680
/*
@@ -3017,7 +3028,8 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
30173028
}
30183029

30193030
if (fix_page) {
3020-
add_missing_indices(ip, bn);
3031+
if ((rc = add_missing_indices(ip, bn)))
3032+
goto out;
30213033
page_fixed = 1;
30223034
}
30233035

0 commit comments

Comments
 (0)