android_kernel_xiaomi_sm7250/fs/ntfs
ChenXiaoSong f8175bd0df ntfs: fix BUG_ON in ntfs_lookup_inode_by_name()
commit 1b513f613731e2afc05550e8070d79fac80c661e upstream.

Syzkaller reported BUG_ON as follows:

------------[ cut here ]------------
kernel BUG at fs/ntfs/dir.c:86!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI
CPU: 3 PID: 758 Comm: a.out Not tainted 5.19.0-next-20220808 #5
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
RIP: 0010:ntfs_lookup_inode_by_name+0xd11/0x2d10
Code: ff e9 b9 01 00 00 e8 1e fe d6 fe 48 8b 7d 98 49 8d 5d 07 e8 91 85 29 ff 48 c7 45 98 00 00 00 00 e9 5a fb ff ff e8 ff fd d6 fe <0f> 0b e8 f8 fd d6 fe 0f 0b e8 f1 fd d6 fe 48 8b b5 50 ff ff ff 4c
RSP: 0018:ffff888079607978 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 0000000000008000 RCX: 0000000000000000
RDX: ffff88807cf10000 RSI: ffffffff82a4a081 RDI: 0000000000000003
RBP: ffff888079607a70 R08: 0000000000000001 R09: ffff88807a6d01d7
R10: ffffed100f4da03a R11: 0000000000000000 R12: ffff88800f0fb110
R13: ffff88800f0ee000 R14: ffff88800f0fb000 R15: 0000000000000001
FS:  00007f33b63c7540(0000) GS:ffff888108580000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f33b635c090 CR3: 000000000f39e005 CR4: 0000000000770ee0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
PKRU: 55555554
Call Trace:
 <TASK>
 load_system_files+0x1f7f/0x3620
 ntfs_fill_super+0xa01/0x1be0
 mount_bdev+0x36a/0x440
 ntfs_mount+0x3a/0x50
 legacy_get_tree+0xfb/0x210
 vfs_get_tree+0x8f/0x2f0
 do_new_mount+0x30a/0x760
 path_mount+0x4de/0x1880
 __x64_sys_mount+0x2b3/0x340
 do_syscall_64+0x38/0x90
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f33b62ff9ea
Code: 48 8b 0d a9 f4 0b 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 76 f4 0b 00 f7 d8 64 89 01 48
RSP: 002b:00007ffd0c471aa8 EFLAGS: 00000202 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f33b62ff9ea
RDX: 0000000020000000 RSI: 0000000020000100 RDI: 00007ffd0c471be0
RBP: 00007ffd0c471c60 R08: 00007ffd0c471ae0 R09: 00007ffd0c471c24
R10: 0000000000000000 R11: 0000000000000202 R12: 000055bac5afc160
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---

Fix this by adding sanity check on extended system files' directory inode
to ensure that it is directory, just like ntfs_extend_init() when mounting
ntfs3.

Link: https://lkml.kernel.org/r/20220809064730.2316892-1-chenxiaosong2@huawei.com
Signed-off-by: ChenXiaoSong <chenxiaosong2@huawei.com>
Cc: Anton Altaparmakov <anton@tuxera.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-10-05 10:36:44 +02:00
..
aops.c ntfs: aops: remove VLA usage 2018-08-17 16:20:27 -07:00
aops.h mm, fs: remove remaining PAGE_CACHE_* and page_cache_{get,release} usage 2016-04-04 10:41:08 -07:00
attrib.c ntfs: fix use-after-free in ntfs_ucsncmp() 2022-08-11 12:48:38 +02:00
attrib.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
bitmap.c mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros 2016-04-04 10:41:08 -07:00
bitmap.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
collate.c Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
collate.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
compress.c ntfs: decompress: remove VLA usage 2018-08-17 16:20:27 -07:00
debug.c ntfs: remove bogus space 2014-10-09 22:25:46 -04:00
debug.h ntfs: logging clean-up 2014-04-07 16:35:49 -07:00
dir.c fs: convert a pile of fsync routines to errseq_t based reporting 2017-08-01 08:39:29 -04:00
dir.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
endian.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
file.c fs: convert a pile of fsync routines to errseq_t based reporting 2017-08-01 08:39:29 -04:00
index.c mm, fs: remove remaining PAGE_CACHE_* and page_cache_{get,release} usage 2016-04-04 10:41:08 -07:00
index.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
inode.c ntfs: add sanity check on allocation size 2022-04-15 14:14:55 +02:00
inode.h fs: cleanup slight list_entry abuse 2015-06-23 18:01:59 -04:00
Kconfig fs/Kconfig: move ntfs out 2009-01-22 13:15:55 +03:00
layout.h Typos: change aditional to additional. 2012-02-21 11:40:36 +01:00
lcnalloc.c mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros 2016-04-04 10:41:08 -07:00
lcnalloc.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
logfile.c block,fs: untangle fs.h and blk_types.h 2016-11-01 09:43:26 -06:00
logfile.h Fix common misspellings 2011-03-31 11:26:23 -03:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
malloc.h NTFS: use kvfree() in ntfs_free() 2015-06-24 17:49:38 -07:00
mft.c ntfs: mft: remove VLA usage 2018-08-17 16:20:27 -07:00
mft.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
mst.c Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
namei.c ntfs: Use ERR_CAST() to avoid cross-structure cast 2017-05-28 10:11:48 -07:00
ntfs.h mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros 2016-04-04 10:41:08 -07:00
quota.c wrappers for ->i_mutex access 2016-01-22 18:04:28 -05:00
quota.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
runlist.c Fix common misspellings 2011-03-31 11:26:23 -03:00
runlist.h NTFS: Add ntfs_rl_punch_nolock() which punches a caller specified hole into a runlist. 2005-09-08 20:26:34 +01:00
super.c ntfs: fix BUG_ON in ntfs_lookup_inode_by_name() 2022-10-05 10:36:44 +02:00
sysctl.c ntfs: convert use of typedef ctl_table to struct ctl_table 2014-06-06 16:08:16 -07:00
sysctl.h Convert files to UTF-8 and some cleanups 2007-10-19 23:21:04 +02:00
time.h fs/ntfs: use timespec64 directly for timestamp conversion 2018-08-17 16:20:27 -07:00
types.h [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
unistr.c [PATCH] slab: remove SLAB_NOFS 2006-12-07 08:39:23 -08:00
upcase.c ntfs: le*_add_cpu conversion 2008-05-24 09:56:08 -07:00
usnjrnl.c [PATCH] fs/ntfs: Conversion to generic boolean 2006-10-01 00:39:19 -07:00
usnjrnl.h ntfs: remove private wrapper of endian helpers 2009-04-01 08:59:18 -07:00
volume.h userns: Convert ntfs to use kuid and kgid where appropriate 2012-09-21 03:13:15 -07:00