nsfs: validate file handle type in nsfs_fh_to_dentry()
PATCH 1/1 nsfs: validate file handle type in nsfs_fh_to_dentry()
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
Add early validation of file handle type in nsfs_fh_to_dentry() to prevent processing of handles with incorrect types. This fixes a warning triggered when open_by_handle_at() is called with non-nsfs handle types on nsfs files.
The issue occurs when a user provides a file handle with a type like FILEID_INO32_GEN_PARENT (0xf1) instead of FILEID_NSFS when calling open_by_handle_at() on an nsfs file. The generic export code routes this to nsfs_fh_to_dentry(), which then processes the incorrectly formatted handle data, leading to validation warnings.
--- fs/nsfs.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nsfs.c +2 -0
@@ -461,6 +461,8 @@ static int nsfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,static struct dentry *nsfs_fh_to_dentry (struct super_block *sb,struct fid *fh,int fh_len,int fh_type) { +if (fh_type !=FILEID_NSFS ) +return ERR_PTR (-EINVAL ); struct path path __free(path_put) = {};struct nsfs_file_handle *fid = (struct nsfs_file_handle *)fh;struct user_namespace *owning_ns =NULL ;
Signature · 1 line
2.43.0
syzbot
syzbotRe: [syzbot] [nfs?] WARNING in nsfs_fh_to_dentry
syzbot has tested the proposed patch but the reproducer is still triggering an issue: WARNING in nsfs_fh_to_dentry
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in nsfs_fh_to_dentry
------------[ cut here ]------------ WARNING: fs/nsfs.c:495 at nsfs_fh_to_dentry+0xc56/0xd60 fs/nsfs.c:495, CPU#0: syz.0.17/6508 Modules linked in: CPU: 0 UID: 0 PID: 6508 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025 RIP: 0010:nsfs_fh_to_dentry+0xc56/0xd60 fs/nsfs.c:495 Code: 5c 24 60 e9 28 f8 ff ff e8 b7 01 79 ff 90 0f 0b 90 e9 1d f6 ff ff e8 a9 01 79 ff 90 0f 0b 90 e9 96 f6 ff ff e8 9b 01 79 ff 90 <0f> 0b 90 e9 ea f6 ff ff e8 8d 01 79 ff 31 db 4c 8d 74 24 70 e9 ed RSP: 0018:ffffc90003b3fa20 EFLAGS: 00010293 RAX: ffffffff82471785 RBX: 00000000effffffd RCX: ffff88807de45ac0 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000effffffd RBP: ffffc90003b3fb10 R08: ffffffff8fe4db77 R09: 1ffffffff1fc9b6e R10: dffffc0000000000 R11: fffffbfff1fc9b6f R12: 1ffff92000767f4c R13: ffff88802e1605d4 R14: ffffc90003b3fa90 R15: 0000000000000000 FS: 00007fccf554a6c0(0000) GS:ffff8881257a2000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b2cd63fff CR3: 00000000334e0000 CR4: 00000000003526f0 Call Trace: <TASK> exportfs_decode_fh_raw+0x178/0x6e0 fs/exportfs/expfs.c:456 do_handle_to_path+0xa4/0x1a0 fs/fhandle.c:276 handle_to_path fs/fhandle.c:400 [inline] do_handle_open+0x6b4/0x8f0 fs/fhandle.c:415 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fccf478ec29 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fccf554a038 EFLAGS: 00000246 ORIG_RAX: 0000000000000130 RAX: ffffffffffffffda RBX: 00007fccf49d5fa0 RCX: 00007fccf478ec29 RDX: 0000000000400040 RSI: 0000200000000000 RDI: 0000000000000003 RBP: 00007fccf4811e41 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fccf49d6038 R14: 00007fccf49d5fa0 R15: 00007ffd8bdc2758 </TASK>
Tested on:
commit: 846bd222 Add linux-next specific files for 20250919 git tree: linux-next console output: https://syzkaller.appspot.com/x/log.txt?x=17f8dc7c580000 kernel config: https://syzkaller.appspot.com/x/.config?x=135377594f35b576 dashboard link: https://syzkaller.appspot.com/bug?extid=9eefe09bedd093f156c2 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 patch: https://syzkaller.appspot.com/x/patch.diff?x=147e4d04580000