jfs: fix shift-out-of-bounds in dbJoin
authorManas Ghandat <ghandatmanas@gmail.com>
Wed, 11 Oct 2023 14:39:37 +0000 (20:09 +0530)
committerDave Kleikamp <dave.kleikamp@oracle.com>
Tue, 21 Nov 2023 21:26:33 +0000 (15:26 -0600)
Currently while joining the leaf in a buddy system there is shift out
of bound error in calculation of BUDSIZE. Added the required check
to the BUDSIZE and fixed the documentation as well.

Reported-by: syzbot+411debe54d318eaed386@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=411debe54d318eaed386
Signed-off-by: Manas Ghandat <ghandatmanas@gmail.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
fs/jfs/jfs_dmap.c

index cb3cda1390adb16e1ad8031783849ba59022db87..8eec84c651bfba2da05af6a834c4ad3fe7a60f2b 100644 (file)
@@ -2763,7 +2763,9 @@ static int dbBackSplit(dmtree_t *tp, int leafno, bool is_ctl)
  *     leafno  - the number of the leaf to be updated.
  *     newval  - the new value for the leaf.
  *
- * RETURN VALUES: none
+ * RETURN VALUES:
+ *  0          - success
+ *     -EIO    - i/o error
  */
 static int dbJoin(dmtree_t *tp, int leafno, int newval, bool is_ctl)
 {
@@ -2790,6 +2792,10 @@ static int dbJoin(dmtree_t *tp, int leafno, int newval, bool is_ctl)
                 * get the buddy size (number of words covered) of
                 * the new value.
                 */
+
+               if ((newval - tp->dmt_budmin) > BUDMIN)
+                       return -EIO;
+
                budsz = BUDSIZE(newval, tp->dmt_budmin);
 
                /* try to join.