Skip to content

Commit fc39fb5

Browse files
committed
Merge tag 'jfs-6.13' of github.com:kleikamp/linux-shaggy
Pull jfs updates from Dave Kleikamp: "A few more patches to add sanity checks in jfs" * tag 'jfs-6.13' of github.com:kleikamp/linux-shaggy: jfs: add a check to prevent array-index-out-of-bounds in dbAdjTree jfs: xattr: check invalid xattr size more strictly jfs: fix array-index-out-of-bounds in jfs_readdir jfs: fix shift-out-of-bounds in dbSplit jfs: array-index-out-of-bounds fix in dtReadFirst
2 parents 6a550ae + a174706 commit fc39fb5

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

fs/jfs/jfs_dmap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,9 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
18201820
return -EIO;
18211821
dp = (struct dmap *) mp->data;
18221822

1823+
if (dp->tree.budmin < 0)
1824+
return -EIO;
1825+
18231826
/* try to allocate the blocks.
18241827
*/
18251828
rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results);
@@ -2888,6 +2891,9 @@ static void dbAdjTree(dmtree_t *tp, int leafno, int newval, bool is_ctl)
28882891
/* bubble the new value up the tree as required.
28892892
*/
28902893
for (k = 0; k < le32_to_cpu(tp->dmt_height); k++) {
2894+
if (lp == 0)
2895+
break;
2896+
28912897
/* get the index of the first leaf of the 4 leaf
28922898
* group containing the specified leaf (leafno).
28932899
*/

fs/jfs/jfs_dtree.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,14 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
28912891
stbl = DT_GETSTBL(p);
28922892

28932893
for (i = index; i < p->header.nextindex; i++) {
2894+
if (stbl[i] < 0 || stbl[i] > 127) {
2895+
jfs_err("JFS: Invalid stbl[%d] = %d for inode %ld, block = %lld",
2896+
i, stbl[i], (long)ip->i_ino, (long long)bn);
2897+
free_page(dirent_buf);
2898+
DT_PUTPAGE(mp);
2899+
return -EIO;
2900+
}
2901+
28942902
d = (struct ldtentry *) & p->slot[stbl[i]];
28952903

28962904
if (((long) jfs_dirent + d->namlen + 1) >
@@ -3086,6 +3094,13 @@ static int dtReadFirst(struct inode *ip, struct btstack * btstack)
30863094

30873095
/* get the leftmost entry */
30883096
stbl = DT_GETSTBL(p);
3097+
3098+
if (stbl[0] < 0 || stbl[0] > 127) {
3099+
DT_PUTPAGE(mp);
3100+
jfs_error(ip->i_sb, "stbl[0] out of bound\n");
3101+
return -EIO;
3102+
}
3103+
30893104
xd = (pxd_t *) & p->slot[stbl[0]];
30903105

30913106
/* get the child page block address */

fs/jfs/xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
559559

560560
size_check:
561561
if (EALIST_SIZE(ea_buf->xattr) != ea_size) {
562-
int size = min_t(int, EALIST_SIZE(ea_buf->xattr), ea_size);
562+
int size = clamp_t(int, ea_size, 0, EALIST_SIZE(ea_buf->xattr));
563563

564564
printk(KERN_ERR "ea_get: invalid extended attribute\n");
565565
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1,

0 commit comments

Comments
 (0)