[PATCH] jfs: fix shift-out-of-bounds in dbSplit

Ghanshyam Agrawal posted 1 patch 1 month, 4 weeks ago
fs/jfs/jfs_dmap.c | 5 +++++
1 file changed, 5 insertions(+)
[PATCH] jfs: fix shift-out-of-bounds in dbSplit
Posted by Ghanshyam Agrawal 1 month, 4 weeks ago
When dmt_budmin is less than zero, it causes errors
in the later stages. Added a check to return an error beforehand
in dbAllocCtl itself.

Reported-by: syzbot+b5ca8a249162c4b9a7d0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b5ca8a249162c4b9a7d0
Signed-off-by: Ghanshyam Agrawal <ghanshyam1898@gmail.com>
---
 fs/jfs/jfs_dmap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 974ecf5e0d95..f65a07252c22 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -1808,6 +1808,7 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
 	s64 b, lblkno, n;
 	struct metapage *mp;
 	struct dmap *dp;
+	dmtree_t *tp;
 
 	/* check if the allocation request is confined to a single dmap.
 	 */
@@ -1819,6 +1820,10 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
 		if (mp == NULL)
 			return -EIO;
 		dp = (struct dmap *) mp->data;
+		tp = (dmtree_t *) &dp->tree;
+
+		if (tp->dmt_budmin < 0)
+			return -EIO;
 
 		/* try to allocate the blocks.
 		 */
-- 
2.34.1
Re: [PATCH] jfs: fix shift-out-of-bounds in dbSplit
Posted by Dave Kleikamp 4 weeks, 1 day ago
On 9/30/24 3:12AM, Ghanshyam Agrawal wrote:
> When dmt_budmin is less than zero, it causes errors
> in the later stages. Added a check to return an error beforehand
> in dbAllocCtl itself.
> 
> Reported-by: syzbot+b5ca8a249162c4b9a7d0@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b5ca8a249162c4b9a7d0
> Signed-off-by: Ghanshyam Agrawal <ghanshyam1898@gmail.com>
> ---
>   fs/jfs/jfs_dmap.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
> index 974ecf5e0d95..f65a07252c22 100644
> --- a/fs/jfs/jfs_dmap.c
> +++ b/fs/jfs/jfs_dmap.c
> @@ -1808,6 +1808,7 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
>   	s64 b, lblkno, n;
>   	struct metapage *mp;
>   	struct dmap *dp;
> +	dmtree_t *tp;
>   
>   	/* check if the allocation request is confined to a single dmap.
>   	 */
> @@ -1819,6 +1820,10 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
>   		if (mp == NULL)
>   			return -EIO;
>   		dp = (struct dmap *) mp->data;
> +		tp = (dmtree_t *) &dp->tree;
> +
> +		if (tp->dmt_budmin < 0)
> +			return -EIO;

I'm simplifying this to:

		if (dp->tree.budmin < 0)
			return -EIO;
>   
>   		/* try to allocate the blocks.
>   		 */

Other than that. It looks good. I'll apply it.

Shaggy