* [PATCH v2] jfs: jfs_dmap: Validate db_l2nbperpage while mounting
@ 2023-06-19 13:16 Siddh Raman Pant
2023-06-20 16:41 ` Siddh Raman Pant
0 siblings, 1 reply; 2+ messages in thread
From: Siddh Raman Pant @ 2023-06-19 13:16 UTC (permalink / raw)
To: Dave Kleikamp, Hoi Pok Wu, Liu Shixin, Dongliang Mu
Cc: jfs-discussion, linux-kernel, syzbot+d2cd27dcf8e04b232eb2, stable
In jfs_dmap.c at line 381, BLKTODMAP is used to get a logical block
number inside dbFree(). db_l2nbperpage, which is the log2 number of
blocks per page, is passed as an argument to BLKTODMAP which uses it
for shifting.
Syzbot reported a shift out-of-bounds crash because db_l2nbperpage is
too big. This happens because the large value is set without any
validation in dbMount() at line 181.
Thus, make sure that db_l2nbperpage is correct while mounting.
Max number of pages = Page size / Min block size
=> log2(Max number of pages) = log2(Page size / Min block size)
= log2(Page size) - log2(Min block size)
=> Max db_l2nbperpage = L2PSIZE - L2MINBLOCKSIZE
Reported-and-tested-by: syzbot+d2cd27dcf8e04b232eb2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?id=2a70a453331db32ed491f5cbb07e81bf2d225715
Cc: stable@vger.kernel.org
Suggested-by: Dave Kleikamp <dave.kleikamp@oracle.com>
Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
Changes in v2:
- Fix upper bound as pointed out in v1 by Shaggy.
- Add an explanation for the same in commit message for completeness.
fs/jfs/jfs_dmap.c | 6 ++++++
fs/jfs/jfs_filsys.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index a3eb1e826947..da6a2bc6bf02 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -178,7 +178,13 @@ int dbMount(struct inode *ipbmap)
dbmp_le = (struct dbmap_disk *) mp->data;
bmp->db_mapsize = le64_to_cpu(dbmp_le->dn_mapsize);
bmp->db_nfree = le64_to_cpu(dbmp_le->dn_nfree);
+
bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage);
+ if (bmp->db_l2nbperpage > L2PSIZE - L2MINBLOCKSIZE) {
+ err = -EINVAL;
+ goto err_release_metapage;
+ }
+
bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
if (!bmp->db_numag) {
err = -EINVAL;
diff --git a/fs/jfs/jfs_filsys.h b/fs/jfs/jfs_filsys.h
index b5d702df7111..33ef13a0b110 100644
--- a/fs/jfs/jfs_filsys.h
+++ b/fs/jfs/jfs_filsys.h
@@ -122,7 +122,9 @@
#define NUM_INODE_PER_IAG INOSPERIAG
#define MINBLOCKSIZE 512
+#define L2MINBLOCKSIZE 9
#define MAXBLOCKSIZE 4096
+#define L2MAXBLOCKSIZE 12
#define MAXFILESIZE ((s64)1 << 52)
#define JFS_LINK_MAX 0xffffffff
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] jfs: jfs_dmap: Validate db_l2nbperpage while mounting
2023-06-19 13:16 [PATCH v2] jfs: jfs_dmap: Validate db_l2nbperpage while mounting Siddh Raman Pant
@ 2023-06-20 16:41 ` Siddh Raman Pant
0 siblings, 0 replies; 2+ messages in thread
From: Siddh Raman Pant @ 2023-06-20 16:41 UTC (permalink / raw)
To: Dave Kleikamp, Hoi Pok Wu, Liu Shixin, Dongliang Mu
Cc: jfs-discussion, linux-kernel, syzbot+d2cd27dcf8e04b232eb2, stable
On Mon, 19 Jun 2023 18:46:44 +0530 I wrote:
> Max number of pages = Page size / Min block size
Sorry for this typo, it should be max number of blocks (per page).
Will fix and send.
Thanks,
Siddh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-20 16:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-19 13:16 [PATCH v2] jfs: jfs_dmap: Validate db_l2nbperpage while mounting Siddh Raman Pant
2023-06-20 16:41 ` Siddh Raman Pant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).