Skip to contentSkip to conversation

ext4: fixpoint divide exception at ext4_fill_super+0x141c/0x2908

OOPs Nageswara R Sastry 2 participants 4 messages Aug 25, 2009 – Nov 6, 2009 ext4 file system

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Hi,

The following bug exists in 2.6.32-rc* also.

Quoted 3 lines
------------[ 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.

I created the patch from 2.6.32-rc6 code.

Thanks and Regards
R.Nageswara Sastry

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

linux-2.6.32-rc6/fs/ext4/super.c +6 -0
diff -Naurp a/linux-2.6.32-rc6/fs/ext4/super.c b/linux-2.6.32-rc6/fs/ext4/super.c
@@ -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) <<
#2 lore raw

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.

Quoted 7 lines
Quoted 3 lines
------------[ 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.

I created the patch from 2.6.32-rc6 code.

Regards
R.Nageswara Sastry

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

---

linux-2.6.32-rc6/fs/ext4/super.c +6 -0
diff -Naurp a/linux-2.6.32-rc6/fs/ext4/super.c b/linux-2.6.32-rc6/fs/ext4/super.c
@@ -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) <<
maintainer
#3 lore raw
Quoted 10 lines · Nageswara R Sastry

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.

Quoted 6 lines
Quoted 3 lines
------------[ 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

fs/ext4/super.c +4 -3
index d4ca92a..8662b2e 100644
@@ -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;