Skip to content

Commit cc38044

Browse files
committed
Merge tag 'jfs-6.12' of github.com:kleikamp/linux-shaggy
Pull jfs updates from David Kleikamp: "A few fixes for jfs" * tag 'jfs-6.12' of github.com:kleikamp/linux-shaggy: jfs: Fix uninit-value access of new_ea in ea_buffer jfs: check if leafidx greater than num leaves per dmap tree jfs: Fix uaf in dbFreeBits jfs: fix out-of-bounds in dbNextAG() and diAlloc() jfs: UBSAN: shift-out-of-bounds in dbFindBits
2 parents 45d986d + 2b59ffa commit cc38044

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

fs/jfs/jfs_discard.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void jfs_issue_discard(struct inode *ip, u64 blkno, u64 nblocks)
6565
int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
6666
{
6767
struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
68-
struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
68+
struct bmap *bmp;
6969
struct super_block *sb = ipbmap->i_sb;
7070
int agno, agno_end;
7171
u64 start, end, minlen;
@@ -83,10 +83,15 @@ int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
8383
if (minlen == 0)
8484
minlen = 1;
8585

86+
down_read(&sb->s_umount);
87+
bmp = JFS_SBI(ip->i_sb)->bmap;
88+
8689
if (minlen > bmp->db_agsize ||
8790
start >= bmp->db_mapsize ||
88-
range->len < sb->s_blocksize)
91+
range->len < sb->s_blocksize) {
92+
up_read(&sb->s_umount);
8993
return -EINVAL;
94+
}
9095

9196
if (end >= bmp->db_mapsize)
9297
end = bmp->db_mapsize - 1;
@@ -100,6 +105,8 @@ int jfs_ioc_trim(struct inode *ip, struct fstrim_range *range)
100105
trimmed += dbDiscardAG(ip, agno, minlen);
101106
agno++;
102107
}
108+
109+
up_read(&sb->s_umount);
103110
range->len = trimmed << sb->s_blocksize_bits;
104111

105112
return 0;

fs/jfs/jfs_dmap.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int dbMount(struct inode *ipbmap)
187187
}
188188

189189
bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
190-
if (!bmp->db_numag) {
190+
if (!bmp->db_numag || bmp->db_numag >= MAXAG) {
191191
err = -EINVAL;
192192
goto err_release_metapage;
193193
}
@@ -652,7 +652,7 @@ int dbNextAG(struct inode *ipbmap)
652652
* average free space.
653653
*/
654654
for (i = 0 ; i < bmp->db_numag; i++, agpref++) {
655-
if (agpref == bmp->db_numag)
655+
if (agpref >= bmp->db_numag)
656656
agpref = 0;
657657

658658
if (atomic_read(&bmp->db_active[agpref]))
@@ -2944,9 +2944,10 @@ static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl)
29442944
static int dbFindLeaf(dmtree_t *tp, int l2nb, int *leafidx, bool is_ctl)
29452945
{
29462946
int ti, n = 0, k, x = 0;
2947-
int max_size;
2947+
int max_size, max_idx;
29482948

29492949
max_size = is_ctl ? CTLTREESIZE : TREESIZE;
2950+
max_idx = is_ctl ? LPERCTL : LPERDMAP;
29502951

29512952
/* first check the root of the tree to see if there is
29522953
* sufficient free space.
@@ -2978,6 +2979,8 @@ static int dbFindLeaf(dmtree_t *tp, int l2nb, int *leafidx, bool is_ctl)
29782979
*/
29792980
assert(n < 4);
29802981
}
2982+
if (le32_to_cpu(tp->dmt_leafidx) >= max_idx)
2983+
return -ENOSPC;
29812984

29822985
/* set the return to the leftmost leaf describing sufficient
29832986
* free space.
@@ -3022,7 +3025,7 @@ static int dbFindBits(u32 word, int l2nb)
30223025

30233026
/* scan the word for nb free bits at nb alignments.
30243027
*/
3025-
for (bitno = 0; mask != 0; bitno += nb, mask >>= nb) {
3028+
for (bitno = 0; mask != 0; bitno += nb, mask = (mask >> nb)) {
30263029
if ((mask & word) == mask)
30273030
break;
30283031
}

fs/jfs/jfs_imap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)
13601360
/* get the ag number of this iag */
13611361
agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb));
13621362
dn_numag = JFS_SBI(pip->i_sb)->bmap->db_numag;
1363-
if (agno < 0 || agno > dn_numag)
1363+
if (agno < 0 || agno > dn_numag || agno >= MAXAG)
13641364
return -EIO;
13651365

13661366
if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {

fs/jfs/xattr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
434434
int rc;
435435
int quota_allocation = 0;
436436

437+
memset(&ea_buf->new_ea, 0, sizeof(ea_buf->new_ea));
438+
437439
/* When fsck.jfs clears a bad ea, it doesn't clear the size */
438440
if (ji->ea.flag == 0)
439441
ea_size = 0;

0 commit comments

Comments
 (0)