jfs: validate budmin to prevent shift-out-of-bounds in dbAllocAG()
PATCH 1/1 jfs: validate budmin to prevent shift-out-of-bounds in dbAllocAG()
syzbot reported "UBSAN: shift-out-of-bounds in fs/jfs/jfs_dmap.c:1440:48 shift exponent -1 is negative".
The budmin value can have a negative value and cause shift-out-of- -bounds from UBSAN.
Add a check on budmin immediately after reading it from the metapage, and return an error if it's negative. This prevents UBSAN reports and correctly treats corrupted metadata as an I/O error.
--- fs/jfs/jfs_dmap.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/jfs/jfs_dmap.c +6 -0
@@ -1372,6 +1372,12 @@ dbAllocAG(struct bmap * bmp, int agno, s64 nblocks, int l2nb, s64 * results) dcp = (struct dmapctl *) mp->data; budmin = dcp->budmin; +if (unlikely (budmin <0 )) { +jfs_err ("JFS: dmapctl corruption: budmin=%d" , budmin); +release_metapage (mp); +return -EIO ; + } +if (dcp->leafidx !=cpu_to_le32 (CTLLEAFIND )) {jfs_error (bmp->db_ipbmap->i_sb,"Corrupt dmapctl page\n" );release_metapage (mp);
Signature · 1 line
2.43.0
Quoted 1 line · Sukrut Heroorkar
Tested-by [email protected]
Hey Sukrut,
Did you do any other testing other than syzbot testing?
Thanks,
David Hunter
Hi David,
Quoted 8 lines · David Hunter
Quoted 1 line · Sukrut Heroorkar
Tested-by [email protected]Hey Sukrut,
Did you do any other testing other than syzbot testing?
I also used the C reproducer to test my fix locally with QEMU and it no longer triggers error. Do you recommend any
other tests? Please let me know.
Thanks,
Sukrut.
Quoted 2 lines
Thanks,
David Hunter
Quoted 8 lines · sukrut heroorkar
Hi David,
Quoted 5 lines · David Hunter
Quoted 1 line · Sukrut Heroorkar
Tested-by [email protected]
Quoted 10 lines
Quoted 3 lines
Hey Sukrut,
Did you do any other testing other than syzbot testing?
I also used the C reproducer to test my fix locally with QEMU and it no longer triggers error. Do you recommend any
other tests? Please let me know.
Thanks,
Sukrut.Quoted 2 lines
Thanks,
David Hunter
Hey Sukrut,
You always need to do testing to ensure that your code does not bring in regressions into the kernel. If doing things to file systems, xfstests is at least the basic testing that you should do. You can also search to see if any other publicly tools are available and/or applicable, but xfstests are the minimum.
Thanks,
David Hunter