Chao Yu
a3dccfacd3
f2fs: fix to do sanity check with secs_per_zone
...
commit 42bf546c1fe3f3654bdf914e977acbc2b80a5be5 upstream.
As Wen Xu reported in below link:
https://bugzilla.kernel.org/show_bug.cgi?id=200183
- Overview
Divide zero in reset_curseg() when mounting a crafted f2fs image
- Reproduce
- Kernel message
[ 588.281510] divide error: 0000 [#1 ] SMP KASAN PTI
[ 588.282701] CPU: 0 PID: 1293 Comm: mount Not tainted 4.18.0-rc1+ #4
[ 588.284000] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014
[ 588.286178] RIP: 0010:reset_curseg+0x94/0x1a0
[ 588.298166] RSP: 0018:ffff8801e88d7940 EFLAGS: 00010246
[ 588.299360] RAX: 0000000000000014 RBX: ffff8801e1d46d00 RCX: ffffffffb88bf60b
[ 588.300809] RDX: 0000000000000000 RSI: dffffc0000000000 RDI: ffff8801e1d46d64
[ 588.305272] R13: 0000000000000000 R14: 0000000000000014 R15: 0000000000000000
[ 588.306822] FS: 00007fad85008840(0000) GS:ffff8801f6e00000(0000) knlGS:0000000000000000
[ 588.308456] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 588.309623] CR2: 0000000001705078 CR3: 00000001f30f8000 CR4: 00000000000006f0
[ 588.311085] Call Trace:
[ 588.311637] f2fs_build_segment_manager+0x103f/0x3410
[ 588.316136] ? f2fs_commit_super+0x1b0/0x1b0
[ 588.317031] ? set_blocksize+0x90/0x140
[ 588.319473] f2fs_mount+0x15/0x20
[ 588.320166] mount_fs+0x60/0x1a0
[ 588.320847] ? alloc_vfsmnt+0x309/0x360
[ 588.321647] vfs_kern_mount+0x6b/0x1a0
[ 588.322432] do_mount+0x34a/0x18c0
[ 588.323175] ? strndup_user+0x46/0x70
[ 588.323937] ? copy_mount_string+0x20/0x20
[ 588.324793] ? memcg_kmem_put_cache+0x1b/0xa0
[ 588.325702] ? kasan_check_write+0x14/0x20
[ 588.326562] ? _copy_from_user+0x6a/0x90
[ 588.327375] ? memdup_user+0x42/0x60
[ 588.328118] ksys_mount+0x83/0xd0
[ 588.328808] __x64_sys_mount+0x67/0x80
[ 588.329607] do_syscall_64+0x78/0x170
[ 588.330400] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 588.331461] RIP: 0033:0x7fad848e8b9a
[ 588.336022] RSP: 002b:00007ffd7c5b6be8 EFLAGS: 00000206 ORIG_RAX: 00000000000000a5
[ 588.337547] RAX: ffffffffffffffda RBX: 00000000016f8030 RCX: 00007fad848e8b9a
[ 588.338999] RDX: 00000000016f8210 RSI: 00000000016f9f30 RDI: 0000000001700ec0
[ 588.340442] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000013
[ 588.341887] R10: 00000000c0ed0000 R11: 0000000000000206 R12: 0000000001700ec0
[ 588.343341] R13: 00000000016f8210 R14: 0000000000000000 R15: 0000000000000003
[ 588.354891] ---[ end trace 4ce02f25ff7d3df5 ]---
[ 588.355862] RIP: 0010:reset_curseg+0x94/0x1a0
[ 588.360742] RSP: 0018:ffff8801e88d7940 EFLAGS: 00010246
[ 588.361812] RAX: 0000000000000014 RBX: ffff8801e1d46d00 RCX: ffffffffb88bf60b
[ 588.363485] RDX: 0000000000000000 RSI: dffffc0000000000 RDI: ffff8801e1d46d64
[ 588.365213] RBP: ffff8801e88d7968 R08: ffffed003c32266f R09: ffffed003c32266f
[ 588.366661] R10: 0000000000000001 R11: ffffed003c32266e R12: ffff8801f0337700
[ 588.368110] R13: 0000000000000000 R14: 0000000000000014 R15: 0000000000000000
[ 588.370057] FS: 00007fad85008840(0000) GS:ffff8801f6e00000(0000) knlGS:0000000000000000
[ 588.372099] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 588.373291] CR2: 0000000001705078 CR3: 00000001f30f8000 CR4: 00000000000006f0
- Location
https://elixir.bootlin.com/linux/latest/source/fs/f2fs/segment.c#L2147
curseg->zone = GET_ZONE_FROM_SEG(sbi, curseg->segno);
If secs_per_zone is corrupted due to fuzzing test, it will cause divide
zero operation when using GET_ZONE_FROM_SEG macro, so we should do more
sanity check with secs_per_zone during mount to avoid this issue.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-08 13:05:14 +01:00
..
2018-12-01 09:44:18 +01:00
2016-10-10 20:16:43 -07:00
2018-05-30 07:50:16 +02:00
2017-12-20 10:07:25 +01:00
2018-09-19 22:47:16 +02:00
2016-10-15 12:09:13 -07:00
2018-12-01 09:44:19 +01:00
2018-12-08 13:05:13 +01:00
2018-11-10 07:43:00 -08:00
2018-12-08 13:05:10 +01:00
2018-11-27 16:09:37 +01:00
2017-11-24 08:33:42 +01:00
2018-11-21 09:26:03 +01:00
2018-11-13 11:17:03 -08:00
2018-08-03 07:55:20 +02:00
2017-08-06 18:59:43 -07:00
2016-10-10 20:16:43 -07:00
2017-09-09 17:39:40 +02:00
2018-05-30 07:50:16 +02:00
2016-10-10 20:16:43 -07:00
2018-11-27 16:09:38 +01:00
2016-10-06 09:07:44 -04:00
2018-12-05 19:42:40 +01:00
2018-11-21 09:26:02 +01:00
2018-12-08 13:05:14 +01:00
2018-11-10 07:42:56 -08:00
2018-09-05 09:20:02 +02:00
2018-11-21 09:26:03 +01:00
2018-12-01 09:44:19 +01:00
2018-11-27 16:09:38 +01:00
2018-11-27 16:09:38 +01:00
2016-10-10 20:16:43 -07:00
2016-10-10 20:16:43 -07:00
2018-12-08 13:05:11 +01:00
2017-11-30 08:39:04 +00:00
2018-11-13 11:16:55 -08:00
2018-11-13 11:16:46 -08:00
2018-08-09 12:18:00 +02:00
2018-12-08 13:05:05 +01:00
2018-11-13 11:17:02 -08:00
2016-10-10 20:16:43 -07:00
2016-10-10 20:16:43 -07:00
2018-03-28 18:39:23 +02:00
2018-11-13 11:17:01 -08:00
2018-02-03 17:05:38 +01:00
2018-11-21 09:26:03 +01:00
2018-05-30 07:50:16 +02:00
2018-04-24 09:34:18 +02:00
2016-10-30 13:09:42 -04:00
2018-11-21 09:26:00 +01:00
2016-10-10 20:16:43 -07:00
2016-09-27 21:06:21 -04:00
2018-11-10 07:42:46 -08:00
2018-04-13 19:48:12 +02:00
2018-10-20 09:51:32 +02:00
2018-09-26 08:36:35 +02:00
2018-09-09 20:01:26 +02:00
2016-10-10 20:16:43 -07:00
2018-11-27 16:09:38 +01:00
2017-06-17 06:41:56 +02:00
2018-09-05 09:20:03 +02:00
2018-09-05 09:20:10 +02:00
2016-10-10 20:16:43 -07:00
2016-09-27 21:06:21 -04:00
2018-10-13 09:18:58 +02:00
2018-12-08 13:05:08 +01:00
2018-11-10 07:42:49 -08:00
2018-11-10 07:43:00 -08:00
2018-06-06 16:44:38 +02:00
2016-10-10 20:16:43 -07:00
2017-01-09 08:32:24 +01:00
2018-09-26 08:36:37 +02:00
2018-06-26 08:08:09 +08:00
2017-10-18 09:35:39 +02:00
2017-06-14 15:06:00 +02:00
2018-02-25 11:05:55 +01:00
2018-04-08 12:12:44 +02:00
2016-09-27 21:20:53 -04:00
2017-07-05 14:40:26 +02:00
2018-02-28 10:18:33 +01:00
2018-09-15 09:42:58 +02:00
2018-12-05 19:42:40 +01:00
2017-09-07 08:35:41 +02:00
2018-07-28 07:49:14 +02:00
2018-01-31 12:55:52 +01:00
2016-09-27 18:47:38 -04:00
2018-05-16 10:08:42 +02:00
2018-07-17 11:37:53 +02:00
2017-09-20 08:20:01 +02:00
2016-09-15 13:29:52 -07:00
2017-09-20 08:19:59 +02:00
2016-10-07 18:46:29 -07:00
2017-12-09 22:01:51 +01:00
2016-10-18 12:21:28 +02:00
2018-02-22 15:43:48 +01:00
2017-07-21 07:42:22 +02:00
2017-10-18 09:35:39 +02:00
2018-12-01 09:44:25 +01:00
2018-11-21 09:26:02 +01:00
2018-02-17 13:21:15 +01:00
2017-07-12 15:01:02 +02:00
2018-02-17 13:21:18 +01:00
2017-07-21 07:42:22 +02:00
2017-03-15 10:02:43 +08:00
2017-01-26 08:24:37 +01:00
2017-10-12 11:51:26 +02:00
2016-10-11 15:06:30 -07:00
2016-10-07 18:46:30 -07:00
2017-02-23 17:44:35 +01:00
2017-06-14 15:06:01 +02:00
2018-03-03 10:23:21 +01:00
2017-05-08 07:47:54 +02:00
2017-12-20 10:07:18 +01:00
2016-10-08 11:06:08 -04:00
2018-10-10 08:53:22 +02:00