2024-01-12 16:50:55

by Mikhail Ukhin

[permalink] [raw]
Subject: [PATCH 5.10/5.15] jfs: add check if log->bdev is NULL in lbmStartIO()

Fuzzing of 5.10 stable branch shows NULL pointer dereference happens in
lbmStartIO() on log->bdev pointer. The reason for bdev being NULL is the
JFS_NOINTEGRITY flag is set on mount of this fs. When this flag is enabled,
it results in the open_dummy_log function being called, which initializes a
new dummy_log, but does not assign a value to bdev.

The error is fixed in 5.18 by commit
07888c665b405b1cd3577ddebfeb74f4717a84c4.
Backport of this commit is too intrusive, so it is more reasonable to apply
a small patch to fix this issue.

Found by Linux Verification Center (linuxtesting.org) with syzkaller.

Signed-off-by: Mikhail Ukhin <[email protected]>
Signed-off-by: Mikhail Ivanov <[email protected]>
Signed-off-by: Pavel Koshutin <[email protected]>
Signed-off-by: Artem Sadovnikov <[email protected]>
---
fs/jfs/jfs_logmgr.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 78fd136ac13b..d6f0fea96ba1 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1983,7 +1983,8 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp)
bio = bio_alloc(GFP_NOFS, 1);

bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
- bio_set_dev(bio, log->bdev);
+ if (log->bdev != NULL)
+ bio_set_dev(bio, log->bdev);

bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
@@ -2127,7 +2128,8 @@ static void lbmStartIO(struct lbuf * bp)

bio = bio_alloc(GFP_NOFS, 1);
bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
- bio_set_dev(bio, log->bdev);
+ if (log->bdev != NULL)
+ bio_set_dev(bio, log->bdev);

bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
--
2.25.1



2024-01-12 19:31:46

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 5.10/5.15] jfs: add check if log->bdev is NULL in lbmStartIO()

On Fri, Jan 12, 2024 at 07:50:07PM +0300, Mikhail Ukhin wrote:
> Fuzzing of 5.10 stable branch shows NULL pointer dereference happens in
> lbmStartIO() on log->bdev pointer. The reason for bdev being NULL is the
> JFS_NOINTEGRITY flag is set on mount of this fs. When this flag is enabled,
> it results in the open_dummy_log function being called, which initializes a
> new dummy_log, but does not assign a value to bdev.
>
> The error is fixed in 5.18 by commit
> 07888c665b405b1cd3577ddebfeb74f4717a84c4.
> Backport of this commit is too intrusive, so it is more reasonable to apply
> a small patch to fix this issue.
>
> Found by Linux Verification Center (linuxtesting.org) with syzkaller.
>
> Signed-off-by: Mikhail Ukhin <[email protected]>
> Signed-off-by: Mikhail Ivanov <[email protected]>
> Signed-off-by: Pavel Koshutin <[email protected]>
> Signed-off-by: Artem Sadovnikov <[email protected]>
> ---
> fs/jfs/jfs_logmgr.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)

Who is using jfs in 5.10 and 5.15? Why not just mark the filesystem as
BROKEN there instead? If you need to access your ancient filesystem
image just use a newer kernel.

For filesystems that are not used in older kernels, work like this feels
odd, especially for something just like a NULL dereference which doesn't
do much, right?

thanks,

greg k-h

2024-01-22 18:22:10

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 5.10/5.15] jfs: add check if log->bdev is NULL in lbmStartIO()

On Fri, Jan 12, 2024 at 08:31:30PM +0100, Greg Kroah-Hartman wrote:
> On Fri, Jan 12, 2024 at 07:50:07PM +0300, Mikhail Ukhin wrote:
> > Fuzzing of 5.10 stable branch shows NULL pointer dereference happens in
> > lbmStartIO() on log->bdev pointer. The reason for bdev being NULL is the
> > JFS_NOINTEGRITY flag is set on mount of this fs. When this flag is enabled,
> > it results in the open_dummy_log function being called, which initializes a
> > new dummy_log, but does not assign a value to bdev.
> >
> > The error is fixed in 5.18 by commit
> > 07888c665b405b1cd3577ddebfeb74f4717a84c4.
> > Backport of this commit is too intrusive, so it is more reasonable to apply
> > a small patch to fix this issue.
> >
> > Found by Linux Verification Center (linuxtesting.org) with syzkaller.
> >
> > Signed-off-by: Mikhail Ukhin <[email protected]>
> > Signed-off-by: Mikhail Ivanov <[email protected]>
> > Signed-off-by: Pavel Koshutin <[email protected]>
> > Signed-off-by: Artem Sadovnikov <[email protected]>
> > ---
> > fs/jfs/jfs_logmgr.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
>
> Who is using jfs in 5.10 and 5.15? Why not just mark the filesystem as
> BROKEN there instead? If you need to access your ancient filesystem
> image just use a newer kernel.
>
> For filesystems that are not used in older kernels, work like this feels
> odd, especially for something just like a NULL dereference which doesn't
> do much, right?

Now dropped from my review queue due to lack of response...