[PATCH] dax: general protection fault in dax_alloc_inode

From: Mikulas Patocka
Date: Tue Nov 14 2017 - 10:00:10 EST




On Tue, 14 Nov 2017, syzbot wrote:

> Hello,
>
> syzkaller hit the following crash on e4880bc5dfb1f02b152e62a894b5c6f3e995b3cf
> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
> compiler: gcc (GCC) 7.1.1 20170620
> .config is attached
> Raw console output is attached.
>
> Unfortunately, I don't have any reproducer for this bug yet.
>
>
> RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
> kasan: CONFIG_KASAN_INLINE enabled
> kasan: GPF could be caused by NULL-ptr deref or user memory access
> general protection fault: 0000 [#1] SMP KASAN
> Dumping ftrace buffer:
> (ftrace buffer empty)
> Modules linked in:
> CPU: 1 PID: 31095 Comm: syz-executor3 Not tainted 4.14.0-rc8+ #75
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google
> 01/01/2011
> task: ffff8801cae96000 task.stack: ffff8801d2438000
> RIP: 0010:dax_alloc_inode+0x3b/0x70 drivers/dax/super.c:348
> RSP: 0018:ffff8801d243f8d0 EFLAGS: 00010203
> RAX: 0000000000000010 RBX: 0000000000000000 RCX: 000000000000000b
> RDX: dffffc0000000000 RSI: ffffffff85b34340 RDI: 000000000000005c
> RBP: ffff8801d243f8e0 R08: 0000000000000001 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff83595ba0
> R13: dffffc0000000000 R14: ffff8801cedbc5c0 R15: 0000000064646178
> FS: 0000000000000000(0000) GS:ffff8801db300000(0063) knlGS:00000000f7742b40
> CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033
> CR2: 00000000f778cdb0 CR3: 00000001c5739000 CR4: 00000000001406e0
> DR0: 0000000020000000 DR1: 0000000020000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600
> Call Trace:
> alloc_inode+0x65/0x180 fs/inode.c:208
> new_inode_pseudo+0x69/0x190 fs/inode.c:890
> new_inode+0x1c/0x40 fs/inode.c:919
> mount_pseudo_xattr+0x288/0x560 fs/libfs.c:261
> mount_pseudo include/linux/fs.h:2137 [inline]
> dax_mount+0x2e/0x40 drivers/dax/super.c:388
> mount_fs+0x66/0x2d0 fs/super.c:1223
> vfs_kern_mount.part.26+0xc6/0x4a0 fs/namespace.c:1037
> vfs_kern_mount fs/namespace.c:2509 [inline]
> do_new_mount fs/namespace.c:2512 [inline]
> do_mount+0xea1/0x2bb0 fs/namespace.c:2841
> C_SYSC_mount fs/compat.c:195 [inline]
> compat_SyS_mount+0xd0/0x1070 fs/compat.c:160
> do_syscall_32_irqs_on arch/x86/entry/common.c:329 [inline]
> do_fast_syscall_32+0x3f2/0xf05 arch/x86/entry/common.c:391
> entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:125
> RIP: 0023:0xf7f46c79
> RSP: 002b:00000000f774201c EFLAGS: 00000296 ORIG_RAX: 0000000000000015
> RAX: ffffffffffffffda RBX: 0000000020907ff8 RCX: 0000000020058ffd
> RDX: 0000000020c77ffa RSI: 0000000000000000 RDI: 0000000020de9000
> RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
> Code: 3d eb ad c1 02 be c0 00 40 01 e8 21 d2 48 fe 48 89 c3 48 ba 00 00 00 00
> 00 fc ff df 48 83 c0 10 48 8d 7b 5c 48 89 f9 48 c1 e9 03 <0f> b6 0c 11 48 89
> fa 83 e2 07 83 c2 03 38 ca 7c 04 84 c9 75 0e
> RIP: dax_alloc_inode+0x3b/0x70 drivers/dax/super.c:348 RSP: ffff8801d243f8d0
> ---[ end trace 543b2dab980d72b6 ]---
>
>
> ---
> This bug is generated by a dumb bot. It may contain errors.
> See https://goo.gl/tpsmEJ for details.
> Direct all questions to syzkaller@xxxxxxxxxxxxxxxxx
> Please credit me with: Reported-by: syzbot <syzkaller@xxxxxxxxxxxxxxxx>
>
> syzbot will keep track of this bug report.
> Once a fix for this bug is committed, please reply to this email with:
> #syz fix: exact-commit-title
> To mark this as a duplicate of another syzbot report, please reply with:
> #syz dup: exact-subject-of-another-report
> If it's a one-off invalid bug report, please reply with:
> #syz invalid
> Note: if the crash happens again, it will cause creation of a new bug report.
> Note: all commands must start from beginning of the line in the email body.

Don't crash in case of allocation failure in dax_alloc_inode.

Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx # v4.12+

---
drivers/dax/super.c | 3 +++
1 file changed, 3 insertions(+)

Index: linux-2.6/drivers/dax/super.c
===================================================================
--- linux-2.6.orig/drivers/dax/super.c
+++ linux-2.6/drivers/dax/super.c
@@ -344,6 +344,9 @@ static struct inode *dax_alloc_inode(str
struct inode *inode;

dax_dev = kmem_cache_alloc(dax_cache, GFP_KERNEL);
+ if (!dax_dev)
+ return NULL;
+
inode = &dax_dev->inode;
inode->i_rdev = 0;
return inode;