* [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock()
@ 2011-11-01 2:05 Eryu Guan
2011-11-01 6:55 ` Andreas Dilger
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Eryu Guan @ 2011-11-01 2:05 UTC (permalink / raw)
To: linux-ext4; +Cc: Eryu Guan, Jan Kara, Theodore Ts'o
I hit a J_ASSERT(blocknr != 0) failure in cleanup_journal_tail() when
mounting a fsfuzzed ext3 image. It turns out that the corrupted ext3
image has s_first = 0 in journal superblock, and the 0 is passed to
journal->j_head in journal_reset(), then to blocknr in
cleanup_journal_tail(), in the end the J_ASSERT failed.
So validate s_first after reading journal superblock from disk in
journal_get_superblock() to ensure s_first is valid.
The following script could reproduce it:
fstype=ext3
blocksize=1024
img=$fstype.img
offset=0
found=0
magic="c0 3b 39 98"
dd if=/dev/zero of=$img bs=1M count=8
mkfs -t $fstype -b $blocksize -F $img
filesize=`stat -c %s $img`
while [ $offset -lt $filesize ]
do
if od -j $offset -N 4 -t x1 $img | grep -i "$magic";then
echo "Found journal: $offset"
found=1
break
fi
offset=`echo "$offset+$blocksize" | bc`
done
if [ $found -ne 1 ];then
echo "Magic \"$magic\" not found"
exit 1
fi
dd if=/dev/zero of=$img seek=$(($offset+23)) conv=notrunc bs=1 count=1
mkdir -p ./mnt
mount -o loop $img ./mnt
Cc: Jan Kara <jack@suse.cz>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
---
fs/jbd/journal.c | 8 ++++++++
fs/jbd2/journal.c | 8 ++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index 9fe061f..0c401de 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -1135,6 +1135,14 @@ static int journal_get_superblock(journal_t *journal)
goto out;
}
+ if (be32_to_cpu(sb->s_first) == 0 ||
+ be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
+ printk(KERN_WARNING
+ "JBD: Invalid start block of journal: %u\n",
+ be32_to_cpu(sb->s_first));
+ goto out;
+ }
+
return 0;
out:
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index f24df13..e2d0e13 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1251,6 +1251,14 @@ static int journal_get_superblock(journal_t *journal)
goto out;
}
+ if (be32_to_cpu(sb->s_first) == 0 ||
+ be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
+ printk(KERN_WARNING
+ "JBD2: Invalid start block of journal: %u\n",
+ be32_to_cpu(sb->s_first));
+ goto out;
+ }
+
return 0;
out:
--
1.7.7.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock()
2011-11-01 2:05 [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock() Eryu Guan
@ 2011-11-01 6:55 ` Andreas Dilger
2011-11-01 22:29 ` Jan Kara
2011-11-01 23:06 ` Ted Ts'o
2 siblings, 0 replies; 6+ messages in thread
From: Andreas Dilger @ 2011-11-01 6:55 UTC (permalink / raw)
To: Eryu Guan; +Cc: linux-ext4, Jan Kara, Theodore Ts'o
On 2011-10-31, at 8:05 PM, Eryu Guan wrote:
> I hit a J_ASSERT(blocknr != 0) failure in cleanup_journal_tail() when
> mounting a fsfuzzed ext3 image. It turns out that the corrupted ext3
> image has s_first = 0 in journal superblock, and the 0 is passed to
> journal->j_head in journal_reset(), then to blocknr in
> cleanup_journal_tail(), in the end the J_ASSERT failed.
>
> So validate s_first after reading journal superblock from disk in
> journal_get_superblock() to ensure s_first is valid.
>
> The following script could reproduce it:
>
> fstype=ext3
> blocksize=1024
> img=$fstype.img
> offset=0
> found=0
> magic="c0 3b 39 98"
>
> dd if=/dev/zero of=$img bs=1M count=8
> mkfs -t $fstype -b $blocksize -F $img
> filesize=`stat -c %s $img`
> while [ $offset -lt $filesize ]
> do
> if od -j $offset -N 4 -t x1 $img | grep -i "$magic";then
> echo "Found journal: $offset"
> found=1
> break
> fi
> offset=`echo "$offset+$blocksize" | bc`
> done
>
> if [ $found -ne 1 ];then
> echo "Magic \"$magic\" not found"
> exit 1
> fi
>
> dd if=/dev/zero of=$img seek=$(($offset+23)) conv=notrunc bs=1 count=1
>
> mkdir -p ./mnt
> mount -o loop $img ./mnt
>
> Cc: Jan Kara <jack@suse.cz>
> Cc: "Theodore Ts'o" <tytso@mit.edu>
> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
> ---
> fs/jbd/journal.c | 8 ++++++++
> fs/jbd2/journal.c | 8 ++++++++
> 2 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
> index 9fe061f..0c401de 100644
> --- a/fs/jbd/journal.c
> +++ b/fs/jbd/journal.c
> @@ -1135,6 +1135,14 @@ static int journal_get_superblock(journal_t *journal)
> goto out;
> }
>
> + if (be32_to_cpu(sb->s_first) == 0 ||
> + be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
(style) Please fix the indenting to align with '(' on previous line.
> + printk(KERN_WARNING
> + "JBD: Invalid start block of journal: %u\n",
> + be32_to_cpu(sb->s_first));
> + goto out;
> + }
> +
> return 0;
>
> out:
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index f24df13..e2d0e13 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1251,6 +1251,14 @@ static int journal_get_superblock(journal_t *journal)
> goto out;
> }
>
> + if (be32_to_cpu(sb->s_first) == 0 ||
> + be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
(style) same.
> + printk(KERN_WARNING
> + "JBD2: Invalid start block of journal: %u\n",
> + be32_to_cpu(sb->s_first));
> + goto out;
> + }
> +
> return 0;
Looks fine otherwise.
Cheers, Andreas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock()
2011-11-01 2:05 [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock() Eryu Guan
2011-11-01 6:55 ` Andreas Dilger
@ 2011-11-01 22:29 ` Jan Kara
2011-11-01 23:16 ` Ted Ts'o
2011-11-01 23:06 ` Ted Ts'o
2 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2011-11-01 22:29 UTC (permalink / raw)
To: Eryu Guan; +Cc: linux-ext4, Jan Kara, Theodore Ts'o
On Tue 01-11-11 10:05:03, Eryu Guan wrote:
> I hit a J_ASSERT(blocknr != 0) failure in cleanup_journal_tail() when
> mounting a fsfuzzed ext3 image. It turns out that the corrupted ext3
> image has s_first = 0 in journal superblock, and the 0 is passed to
> journal->j_head in journal_reset(), then to blocknr in
> cleanup_journal_tail(), in the end the J_ASSERT failed.
>
> So validate s_first after reading journal superblock from disk in
> journal_get_superblock() to ensure s_first is valid.
>
> The following script could reproduce it:
>
> fstype=ext3
> blocksize=1024
> img=$fstype.img
> offset=0
> found=0
> magic="c0 3b 39 98"
>
> dd if=/dev/zero of=$img bs=1M count=8
> mkfs -t $fstype -b $blocksize -F $img
> filesize=`stat -c %s $img`
> while [ $offset -lt $filesize ]
> do
> if od -j $offset -N 4 -t x1 $img | grep -i "$magic";then
> echo "Found journal: $offset"
> found=1
> break
> fi
> offset=`echo "$offset+$blocksize" | bc`
> done
>
> if [ $found -ne 1 ];then
> echo "Magic \"$magic\" not found"
> exit 1
> fi
>
> dd if=/dev/zero of=$img seek=$(($offset+23)) conv=notrunc bs=1 count=1
>
> mkdir -p ./mnt
> mount -o loop $img ./mnt
Thanks. I've fixed-up the style problems pointed out by Andreas and added
the patch to my tree.
Honza
>
> Cc: Jan Kara <jack@suse.cz>
> Cc: "Theodore Ts'o" <tytso@mit.edu>
> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
> ---
> fs/jbd/journal.c | 8 ++++++++
> fs/jbd2/journal.c | 8 ++++++++
> 2 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
> index 9fe061f..0c401de 100644
> --- a/fs/jbd/journal.c
> +++ b/fs/jbd/journal.c
> @@ -1135,6 +1135,14 @@ static int journal_get_superblock(journal_t *journal)
> goto out;
> }
>
> + if (be32_to_cpu(sb->s_first) == 0 ||
> + be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
> + printk(KERN_WARNING
> + "JBD: Invalid start block of journal: %u\n",
> + be32_to_cpu(sb->s_first));
> + goto out;
> + }
> +
> return 0;
>
> out:
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index f24df13..e2d0e13 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1251,6 +1251,14 @@ static int journal_get_superblock(journal_t *journal)
> goto out;
> }
>
> + if (be32_to_cpu(sb->s_first) == 0 ||
> + be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
> + printk(KERN_WARNING
> + "JBD2: Invalid start block of journal: %u\n",
> + be32_to_cpu(sb->s_first));
> + goto out;
> + }
> +
> return 0;
>
> out:
> --
> 1.7.7.1
>
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock()
2011-11-01 2:05 [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock() Eryu Guan
2011-11-01 6:55 ` Andreas Dilger
2011-11-01 22:29 ` Jan Kara
@ 2011-11-01 23:06 ` Ted Ts'o
2 siblings, 0 replies; 6+ messages in thread
From: Ted Ts'o @ 2011-11-01 23:06 UTC (permalink / raw)
To: Eryu Guan; +Cc: linux-ext4, Jan Kara
On Tue, Nov 01, 2011 at 10:05:03AM +0800, Eryu Guan wrote:
> I hit a J_ASSERT(blocknr != 0) failure in cleanup_journal_tail() when
> mounting a fsfuzzed ext3 image. It turns out that the corrupted ext3
> image has s_first = 0 in journal superblock, and the 0 is passed to
> journal->j_head in journal_reset(), then to blocknr in
> cleanup_journal_tail(), in the end the J_ASSERT failed.
>
> So validate s_first after reading journal superblock from disk in
> journal_get_superblock() to ensure s_first is valid.
>
> ...
>
> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Thanks, applied. (I took the jbd fixup as well, since it's obvious)
- Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock()
2011-11-01 22:29 ` Jan Kara
@ 2011-11-01 23:16 ` Ted Ts'o
2011-11-02 14:24 ` Jan Kara
0 siblings, 1 reply; 6+ messages in thread
From: Ted Ts'o @ 2011-11-01 23:16 UTC (permalink / raw)
To: Jan Kara; +Cc: Eryu Guan, linux-ext4
On Tue, Nov 01, 2011 at 11:29:55PM +0100, Jan Kara wrote:
> Thanks. I've fixed-up the style problems pointed out by Andreas and added
> the patch to my tree.
Oops, I grabbed it too. How do you want to resolve this? I can just
carry the jbd2 change, or I can carry both, or I can let you carry
both. Either is fine with me. (And if we both carry it git should do
the right thing anyway. :-)
- Ted
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock()
2011-11-01 23:16 ` Ted Ts'o
@ 2011-11-02 14:24 ` Jan Kara
0 siblings, 0 replies; 6+ messages in thread
From: Jan Kara @ 2011-11-02 14:24 UTC (permalink / raw)
To: Ted Ts'o; +Cc: Jan Kara, Eryu Guan, linux-ext4
On Tue 01-11-11 19:16:27, Ted Tso wrote:
> On Tue, Nov 01, 2011 at 11:29:55PM +0100, Jan Kara wrote:
> > Thanks. I've fixed-up the style problems pointed out by Andreas and added
> > the patch to my tree.
>
> Oops, I grabbed it too. How do you want to resolve this? I can just
> carry the jbd2 change, or I can carry both, or I can let you carry
> both. Either is fine with me. (And if we both carry it git should do
> the right thing anyway. :-)
OK, carry it, I'll remove the patch from my tree.
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-11-02 14:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-01 2:05 [PATCH 1/2] jbd/jbd2: validate sb->s_first in journal_get_superblock() Eryu Guan
2011-11-01 6:55 ` Andreas Dilger
2011-11-01 22:29 ` Jan Kara
2011-11-01 23:16 ` Ted Ts'o
2011-11-02 14:24 ` Jan Kara
2011-11-01 23:06 ` Ted Ts'o
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).