2009-08-25 05:39:54

by Nageswara R Sastry

[permalink] [raw]
Subject: [OOPs] ext4: fixpoint divide exception at ext4_fill_super+0x141c/0x2908

Hi,

Found kernel bug - fixpoint divide exception
While working with fsfuzzer

Environment: 2.6.31-rc7
Architecture: s390 and ppc64

------------[ cut here ]------------

Kernel BUG at 000003e00429d934 [verbose debug info unavailable]

fixpoint divide exception: 0009 [#1] SMP

Modules linked in: ext4 jbd2 crc16 loop autofs4 lockd sunrpc ipv6
qeth_l2 qeth
q
dio vmur ccwgroup dm_round_robin dm_multipath scsi_dh sd_mod scsi_mod
multipath
dm_snapshot dm_zero dm_mirror dm_region_hash dm_log dm_mod dasd_fba_mod
dasd_eck
d_mod dasd_mod ext3 jbd

CPU: 2 Not tainted 2.6.31-rc6 #1

Process mount (pid: 2675, task: 000000003ed06038, ksp: 0000000036217920)

Krnl PSW : 0704200180000000 000003e00429d934 (ext4_fill_super+0x1478/0x2908
[ext
4])

R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:2 PM:0 EA:3

Krnl GPRS: 0000000000000100 0000000000000100 0000000000000006
000000002fc61800
0000000000000000 0000000000000100 000000002fc61800
000000002fc61800
000000003143a800 00000000000000e0 0000000000000000
000000003eb0d800
000003e00427c000 000003e0042b8958 000003e00429d87c
0000000036217b10
Krnl Code: 000003e00429d928: b9160050 llgfr %r5,%r0

000003e00429d92c: a7490000 lghi %r4,0

000003e00429d930: b987004a dlgr %r4,%r10

>000003e00429d934: b91600a5 llgfr %r10,%r5

000003e00429d938: a53f80d0 llill %r3,32976

000003e00429d93c: a7ad000c mghi %r10,12

000003e00429d940: b904002a lgr %r2,%r10
000003e00429d944: 1895 lr %r9,%r5
Call Trace:
([<000003e00429d87c>] ext4_fill_super+0x13c0/0x2908 [ext4])
[<00000000000f46f2>] get_sb_bdev+0x13e/0x19c
[<000003e00429230e>] ext4_get_sb+0x2e/0x40 [ext4]
[<00000000000f3f98>] vfs_kern_mount+0xc0/0x168
[<00000000000f40ac>] do_kern_mount+0x58/0x114
[<000000000010e558>] do_mount+0x798/0x830
[<000000000010e6a0>] SyS_mount+0xb0/0x100
[<00000000000266be>] sysc_noemu+0x10/0x16
[<0000004e53f234e2>] 0x4e53f234e2
Last Breaking-Event-Address:
[<000003e00429d8d8>] ext4_fill_super+0x141c/0x2908 [ext4]

---[ end trace b5563edf9c0c9b52 ]---

*P.S. If you need any information please let me know. Please cc me as I
am not subscribed to the list.

Thanks and Regards
R.Nageswara Sastry



2009-11-04 12:40:28

by Nageswara R Sastry

[permalink] [raw]
Subject: Re: [OOPs] ext4: fixpoint divide exception at ext4_fill_super+0x141c/0x2908

diff -Naurp a/linux-2.6.32-rc6/fs/ext4/super.c b/linux-2.6.32-rc6/fs/ext4/super.c
--- a/linux-2.6.32-rc6/fs/ext4/super.c 2009-11-03 20:37:49.000000000 +0100
+++ b/linux-2.6.32-rc6/fs/ext4/super.c 2009-11-04 13:21:48.000000000 +0100
@@ -1681,6 +1681,12 @@ static int ext4_fill_flex_info(struct su
sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
groups_per_flex = 1 << sbi->s_log_groups_per_flex;

+ /* There are some situations, after shift the value of 'groups_per_flex'
+ can become zero and division with 0 will result in fixpoint divide exception
+ */
+ if (groups_per_flex == 0)
+ return 1;
+
/* We allocate both existing and potentially added groups */
flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<


Attachments:
ext4_fix_point_division_error.patch (813.00 B)

2009-11-04 13:54:06

by Nageswara R Sastry

[permalink] [raw]
Subject: Re: [OOPs] ext4: fixpoint divide exception at ext4_fill_super+0x141c/0x2908

Though the 'sbi->s_log_groups_per_flex' contains valid data after the shift operation
'groups_per_flex' is becoming zero, which later used as a divisor.
groups_per_flex = 1 << sbi->s_log_groups_per_flex

Signed-off-by: Nageswara R Sastry <[email protected]>
---

diff -Naurp a/linux-2.6.32-rc6/fs/ext4/super.c b/linux-2.6.32-rc6/fs/ext4/super.c
--- a/linux-2.6.32-rc6/fs/ext4/super.c 2009-11-03 20:37:49.000000000 +0100
+++ b/linux-2.6.32-rc6/fs/ext4/super.c 2009-11-04 13:21:48.000000000 +0100
@@ -1681,6 +1681,12 @@ static int ext4_fill_flex_info(struct su
sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
groups_per_flex = 1 << sbi->s_log_groups_per_flex;

+ /* There are some situations, after shift the value of 'groups_per_flex'
+ can become zero and division with 0 will result in fixpoint divide exception
+ */
+ if (groups_per_flex == 0)
+ return 1;
+
/* We allocate both existing and potentially added groups */
flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<


Attachments:
ext4_fix_point_division_error.patch (1.06 kB)

2009-11-06 19:48:47

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [OOPs] ext4: fixpoint divide exception at ext4_fill_super+0x141c/0x2908

On Wed, Nov 04, 2009 at 07:24:04PM +0530, Nageswara R Sastry wrote:
> Seems to be I have a little format related issue with the patch. So
> resending it. Please accept my apologies.
> Sachin thanks for letting me know.
>
>> > ------------[ cut here ]------------
>> > Kernel BUG at 000003e00429d934 [verbose debug info unavailable]
>> > fixpoint divide exception: 0009 [#1] SMP
>>
>> Please find the patch which solves the following 'fixpoint divide
>> exception'. I tested the same and not seeing any KERNEL BUG/exception.

Nageswara,

Thanks for sending this patch. The problem with it is that it leaves
sbi->s_log_groups_per_flex non-zero, but it leaves sbi->s_flex_groups
unallocated. This should lead to number of kernel oops caused by a
null pointer dereference if there is any attempt to allocate blocks or
inodes, or to resize the filesystem.

A better fix is would be:

ext4: Avoid divide by zero when trying to mount a corrupted file system

If s_log_groups_per_flex is greater than 31, then groups_per_flex will
will overflow and cause a divide by zero error. This can cause kernel
BUG if such a file system is mounted.

Thanks to Nageswara R Sastry for analyzing the failure and providing
an initial patch.

http://bugzilla.kernel.org/show_bug.cgi?id=14287

Signed-off-by: "Theodore Ts'o" <[email protected]>
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index d4ca92a..8662b2e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1673,14 +1673,14 @@ static int ext4_fill_flex_info(struct super_block *sb)
size_t size;
int i;

- if (!sbi->s_es->s_log_groups_per_flex) {
+ sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
+ groups_per_flex = 1 << sbi->s_log_groups_per_flex;
+
+ if (groups_per_flex < 2) {
sbi->s_log_groups_per_flex = 0;
return 1;
}

- sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
- groups_per_flex = 1 << sbi->s_log_groups_per_flex;