linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* general protection fault in fuse_ctl_remove_conn
@ 2018-04-27 16:00 syzbot
  2018-04-28  2:29 ` Tetsuo Handa
  0 siblings, 1 reply; 8+ messages in thread
From: syzbot @ 2018-04-27 16:00 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel, miklos, syzkaller-bugs

Hello,

syzbot hit the following crash on upstream commit
0644f186fc9d77bb5bd198369e59fb28927a3692 (Thu Apr 26 23:36:11 2018 +0000)
Merge tag 'for_linus' of  
git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
syzbot dashboard link:  
https://syzkaller.appspot.com/bug?extid=32c236387d66c4516827

So far this crash happened 2 times on upstream.
C reproducer: https://syzkaller.appspot.com/x/repro.c?id=6056306666373120
syzkaller reproducer:  
https://syzkaller.appspot.com/x/repro.syz?id=6559188280934400
Raw console output:  
https://syzkaller.appspot.com/x/log.txt?id=4532195645456384
Kernel config:  
https://syzkaller.appspot.com/x/.config?id=7043958930931867332
compiler: gcc (GCC) 8.0.1 20180413 (experimental)

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+32c236387d66c4516827@syzkaller.appspotmail.com
It will help syzbot understand when the bug is fixed. See footer for  
details.
If you forward the report, please keep this part and the footer.

RBP: 0030656c69662f2e R08: 0000000020000300 R09: 0000000000003833
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe5dea3810
R13: ffffffffffffffff R14: 006c746365737566 R15: 0000000000000044
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: 0 PID: 4504 Comm: syz-executor777 Not tainted 4.17.0-rc2+ #19
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
RIP: 0010:fuse_ctl_remove_conn+0xc8/0x1b0 fs/fuse/control.c:286
RSP: 0018:ffff8801b0ee7968 EFLAGS: 00010202
RAX: 0000000000000075 RBX: ffff8801ac6dc2c0 RCX: ffffffff82645bb7
RDX: 0000000000000000 RSI: ffffffff82645bda RDI: 00000000000003a8
RBP: ffff8801b0ee7990 R08: ffff8801b1cd2740 R09: ffffed003b5c46c2
R10: ffffed003b5c46c2 R11: ffff8801dae23613 R12: 0000000000000001
R13: ffff8801d0bb5410 R14: dffffc0000000000 R15: 0000000000000000
FS:  00000000026bc880(0000) GS:ffff8801dae00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000001471000 CR3: 00000001b1137000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
  fuse_ctl_add_conn+0x261/0x280 fs/fuse/control.c:269
  fuse_ctl_fill_super+0xf7/0x160 fs/fuse/control.c:307
  mount_single+0xfb/0x170 fs/super.c:1236
  fuse_ctl_mount+0x2c/0x40 fs/fuse/control.c:322
  mount_fs+0xae/0x328 fs/super.c:1267
  vfs_kern_mount.part.34+0xd4/0x4d0 fs/namespace.c:1037
  vfs_kern_mount fs/namespace.c:1027 [inline]
  do_new_mount fs/namespace.c:2518 [inline]
  do_mount+0x564/0x3070 fs/namespace.c:2848
  ksys_mount+0x12d/0x140 fs/namespace.c:3064
  __do_sys_mount fs/namespace.c:3078 [inline]
  __se_sys_mount fs/namespace.c:3075 [inline]
  __x64_sys_mount+0xbe/0x150 fs/namespace.c:3075
  do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x440579
RSP: 002b:00007ffe5dea3808 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000440579
RDX: 00000000200002c0 RSI: 0000000020000280 RDI: 0000000020000240
RBP: 0030656c69662f2e R08: 0000000020000300 R09: 0000000000003833
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe5dea3810
R13: ffffffffffffffff R14: 006c746365737566 R15: 0000000000000044
Code: 8b 5d 00 48 8d 7b 58 48 89 f8 48 c1 e8 03 42 80 3c 30 00 0f 85 cc 00  
00 00 4c 8b 7b 58 49 8d bf a8 03 00 00 48 89 f8 48 c1 e8 03 <42> 80 3c 30  
00 0f 85 a5 00 00 00 48 89 df 41 83 ec 01 49 83 ed
RIP: fuse_ctl_remove_conn+0xc8/0x1b0 fs/fuse/control.c:286 RSP:  
ffff8801b0ee7968
---[ end trace d64f1dab46c839a5 ]---


---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to syzkaller@googlegroups.com.

syzbot will keep track of this bug report.
If you forgot to add the Reported-by tag, once the fix for this bug is  
merged
into any tree, please reply to this email with:
#syz fix: exact-commit-title
If you want to test a patch for this bug, please reply with:
#syz test: git://repo/address.git branch
and provide the patch inline or as an attachment.
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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: general protection fault in fuse_ctl_remove_conn
  2018-04-27 16:00 general protection fault in fuse_ctl_remove_conn syzbot
@ 2018-04-28  2:29 ` Tetsuo Handa
  2018-05-09 10:58   ` [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry() Tetsuo Handa
  2018-05-31 14:27   ` general protection fault in fuse_ctl_remove_conn Miklos Szeredi
  0 siblings, 2 replies; 8+ messages in thread
From: Tetsuo Handa @ 2018-04-28  2:29 UTC (permalink / raw)
  To: syzbot, miklos, syzkaller-bugs; +Cc: linux-fsdevel, linux-kernel

>From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Sat, 28 Apr 2018 11:24:09 +0900
Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().

syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
than incrementing fc->ctl_ndents when new_inode() failed.

[1] https://syzkaller.appspot.com/bug?id=f396d863067238959c91c0b7cfc10b163638cac6

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot <syzbot+32c236387d66c4516827@syzkaller.appspotmail.com>
Fixes: bafa96541b250a70 ("fuse: add control filesystem")
Cc: Miklos Szeredi <miklos@szeredi.hu>
---
 fs/fuse/control.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index b9ea99c..a651f8e 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -211,10 +211,12 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
 	if (!dentry)
 		return NULL;
 
-	fc->ctl_dentry[fc->ctl_ndents++] = dentry;
 	inode = new_inode(fuse_control_sb);
-	if (!inode)
+	if (!inode) {
+		dput(dentry);
 		return NULL;
+	}
+	fc->ctl_dentry[fc->ctl_ndents++] = dentry;
 
 	inode->i_ino = get_next_ino();
 	inode->i_mode = mode;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
  2018-04-28  2:29 ` Tetsuo Handa
@ 2018-05-09 10:58   ` Tetsuo Handa
  2018-05-10 20:07     ` Al Viro
  2018-05-31 14:27   ` general protection fault in fuse_ctl_remove_conn Miklos Szeredi
  1 sibling, 1 reply; 8+ messages in thread
From: Tetsuo Handa @ 2018-05-09 10:58 UTC (permalink / raw)
  To: miklos; +Cc: syzbot, syzkaller-bugs, linux-fsdevel

>From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Sat, 28 Apr 2018 11:24:09 +0900
Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().

syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
than incrementing fc->ctl_ndents when new_inode() failed.

[1] https://syzkaller.appspot.com/bug?id=f396d863067238959c91c0b7cfc10b163638cac6

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot <syzbot+32c236387d66c4516827@syzkaller.appspotmail.com>
Fixes: bafa96541b250a70 ("fuse: add control filesystem")
Cc: Miklos Szeredi <miklos@szeredi.hu>
---
 fs/fuse/control.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index b9ea99c..a651f8e 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -211,10 +211,12 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
 	if (!dentry)
 		return NULL;
 
-	fc->ctl_dentry[fc->ctl_ndents++] = dentry;
 	inode = new_inode(fuse_control_sb);
-	if (!inode)
+	if (!inode) {
+		dput(dentry);
 		return NULL;
+	}
+	fc->ctl_dentry[fc->ctl_ndents++] = dentry;
 
 	inode->i_ino = get_next_ino();
 	inode->i_mode = mode;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
  2018-05-09 10:58   ` [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry() Tetsuo Handa
@ 2018-05-10 20:07     ` Al Viro
  2018-05-11  7:55       ` Miklos Szeredi
  0 siblings, 1 reply; 8+ messages in thread
From: Al Viro @ 2018-05-10 20:07 UTC (permalink / raw)
  To: Tetsuo Handa; +Cc: miklos, syzbot, syzkaller-bugs, linux-fsdevel

On Wed, May 09, 2018 at 07:58:58PM +0900, Tetsuo Handa wrote:
> >From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Date: Sat, 28 Apr 2018 11:24:09 +0900
> Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
> 
> syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
> Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
> failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
> clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
> than incrementing fc->ctl_ndents when new_inode() failed.

That looks bloody awful.  Sure, everything that accesses fc->ctl_dentry is
synchronous with this, but it would've been much easier to follow if
shoving dentry into that array happened only after it's been fully set
up.

Incidentally, there's a nasty headache waiting to happen in that code -
consider a twit mounting something on that.  And think what happens when
connection gets shut down...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
  2018-05-10 20:07     ` Al Viro
@ 2018-05-11  7:55       ` Miklos Szeredi
  2018-05-11 10:30         ` Tetsuo Handa
  2018-05-11 22:12         ` Al Viro
  0 siblings, 2 replies; 8+ messages in thread
From: Miklos Szeredi @ 2018-05-11  7:55 UTC (permalink / raw)
  To: Al Viro; +Cc: Tetsuo Handa, syzbot, syzkaller-bugs, linux-fsdevel

On Thu, May 10, 2018 at 10:07 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Wed, May 09, 2018 at 07:58:58PM +0900, Tetsuo Handa wrote:
>> >From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
>> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
>> Date: Sat, 28 Apr 2018 11:24:09 +0900
>> Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
>>
>> syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
>> Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
>> failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
>> clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
>> than incrementing fc->ctl_ndents when new_inode() failed.
>
> That looks bloody awful.  Sure, everything that accesses fc->ctl_dentry is
> synchronous with this, but it would've been much easier to follow if
> shoving dentry into that array happened only after it's been fully set
> up.
>
> Incidentally, there's a nasty headache waiting to happen in that code -
> consider a twit mounting something on that.  And think what happens when
> connection gets shut down...

Need to call d_invalidate() instead of d_drop() in there.  Is that
what you are referring to?

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
  2018-05-11  7:55       ` Miklos Szeredi
@ 2018-05-11 10:30         ` Tetsuo Handa
  2018-05-11 22:12         ` Al Viro
  1 sibling, 0 replies; 8+ messages in thread
From: Tetsuo Handa @ 2018-05-11 10:30 UTC (permalink / raw)
  To: miklos, viro; +Cc: syzbot+32c236387d66c4516827, syzkaller-bugs, linux-fsdevel

Miklos Szeredi wrote:
> On Thu, May 10, 2018 at 10:07 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> > On Wed, May 09, 2018 at 07:58:58PM +0900, Tetsuo Handa wrote:
> >> >From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
> >> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> >> Date: Sat, 28 Apr 2018 11:24:09 +0900
> >> Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
> >>
> >> syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
> >> Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
> >> failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
> >> clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
> >> than incrementing fc->ctl_ndents when new_inode() failed.
> >
> > That looks bloody awful.  Sure, everything that accesses fc->ctl_dentry is
> > synchronous with this, but it would've been much easier to follow if
> > shoving dentry into that array happened only after it's been fully set
> > up.
> >
> > Incidentally, there's a nasty headache waiting to happen in that code -
> > consider a twit mounting something on that.  And think what happens when
> > connection gets shut down...
> 
> Need to call d_invalidate() instead of d_drop() in there.  Is that
> what you are referring to?
> 
> Thanks,
> Miklos
> 
I couldn't catch what Al is worrying about. I assumed that dput() is fine
because proc_setup_thread_self() in fs/proc/thread_self.c is doing dput()
when new_inode_pseudo() failed after d_alloc_name().

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
  2018-05-11  7:55       ` Miklos Szeredi
  2018-05-11 10:30         ` Tetsuo Handa
@ 2018-05-11 22:12         ` Al Viro
  1 sibling, 0 replies; 8+ messages in thread
From: Al Viro @ 2018-05-11 22:12 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: Tetsuo Handa, syzbot, syzkaller-bugs, linux-fsdevel

On Fri, May 11, 2018 at 09:55:00AM +0200, Miklos Szeredi wrote:
> On Thu, May 10, 2018 at 10:07 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> > On Wed, May 09, 2018 at 07:58:58PM +0900, Tetsuo Handa wrote:
> >> >From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
> >> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> >> Date: Sat, 28 Apr 2018 11:24:09 +0900
> >> Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
> >>
> >> syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
> >> Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
> >> failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
> >> clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
> >> than incrementing fc->ctl_ndents when new_inode() failed.
> >
> > That looks bloody awful.  Sure, everything that accesses fc->ctl_dentry is
> > synchronous with this, but it would've been much easier to follow if
> > shoving dentry into that array happened only after it's been fully set
> > up.
> >
> > Incidentally, there's a nasty headache waiting to happen in that code -
> > consider a twit mounting something on that.  And think what happens when
> > connection gets shut down...
> 
> Need to call d_invalidate() instead of d_drop() in there.  Is that
> what you are referring to?

Yes, and do that once on the entire subdirectory...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: general protection fault in fuse_ctl_remove_conn
  2018-04-28  2:29 ` Tetsuo Handa
  2018-05-09 10:58   ` [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry() Tetsuo Handa
@ 2018-05-31 14:27   ` Miklos Szeredi
  1 sibling, 0 replies; 8+ messages in thread
From: Miklos Szeredi @ 2018-05-31 14:27 UTC (permalink / raw)
  To: Tetsuo Handa; +Cc: syzbot, syzkaller-bugs, linux-fsdevel, linux-kernel

On Sat, Apr 28, 2018 at 4:29 AM, Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
> From 9f41081f8bd6762a6f629e5e23e6d07a62bba69c Mon Sep 17 00:00:00 2001
> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Date: Sat, 28 Apr 2018 11:24:09 +0900
> Subject: [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry().
>
> syzbot is reporting NULL pointer dereference at fuse_ctl_remove_conn() [1].
> Since fc->ctl_ndents is incremented by fuse_ctl_add_conn() when new_inode()
> failed, fuse_ctl_remove_conn() reaches an inode-less dentry and tries to
> clear d_inode(dentry)->i_private field. Fix this by calling dput() rather
> than incrementing fc->ctl_ndents when new_inode() failed.
>
> [1] https://syzkaller.appspot.com/bug?id=f396d863067238959c91c0b7cfc10b163638cac6

Slightly different fix pushed to:

  git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git for-next

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-31 14:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 16:00 general protection fault in fuse_ctl_remove_conn syzbot
2018-04-28  2:29 ` Tetsuo Handa
2018-05-09 10:58   ` [PATCH] fuse: don't keep inode-less dentry at fuse_ctl_add_dentry() Tetsuo Handa
2018-05-10 20:07     ` Al Viro
2018-05-11  7:55       ` Miklos Szeredi
2018-05-11 10:30         ` Tetsuo Handa
2018-05-11 22:12         ` Al Viro
2018-05-31 14:27   ` general protection fault in fuse_ctl_remove_conn Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).