linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* WARNING: lock held when returning to user space in ovl_write_iter
@ 2020-03-01 19:13 syzbot
  2020-03-12 15:30 ` Miklos Szeredi
  2020-03-13  8:53 ` Miklos Szeredi
  0 siblings, 2 replies; 4+ messages in thread
From: syzbot @ 2020-03-01 19:13 UTC (permalink / raw)
  To: jiufei.xue, linux-kernel, linux-unionfs, miklos, mszeredi,
	syzkaller-bugs

Hello,

syzbot found the following crash on:

HEAD commit:    bdc5461b Add linux-next specific files for 20200224
git tree:       linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=10deee65e00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=8402e437f1eeea92
dashboard link: https://syzkaller.appspot.com/bug?extid=9331a354f4f624a52a55
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=1571d22de00000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=175192c3e00000

The bug was bisected to:

commit 2406a307ac7ddfd7effeeaff6947149ec6a95b4e
Author: Jiufei Xue <jiufei.xue@linux.alibaba.com>
Date:   Wed Nov 20 09:45:26 2019 +0000

    ovl: implement async IO routines

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=113c6d29e00000
final crash:    https://syzkaller.appspot.com/x/report.txt?x=133c6d29e00000
console output: https://syzkaller.appspot.com/x/log.txt?x=153c6d29e00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+9331a354f4f624a52a55@syzkaller.appspotmail.com
Fixes: 2406a307ac7d ("ovl: implement async IO routines")

================================================
WARNING: lock held when returning to user space!
5.6.0-rc2-next-20200224-syzkaller #0 Not tainted
------------------------------------------------
syz-executor184/10029 is leaving the kernel with locks still held!
1 lock held by syz-executor184/10029:
 #0: ffff88809987c418 (sb_writers#3){.+.+}, at: file_start_write include/linux/fs.h:2903 [inline]
 #0: ffff88809987c418 (sb_writers#3){.+.+}, at: ovl_write_iter+0xcc1/0x1090 fs/overlayfs/file.c:348


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

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

* Re: WARNING: lock held when returning to user space in ovl_write_iter
  2020-03-01 19:13 WARNING: lock held when returning to user space in ovl_write_iter syzbot
@ 2020-03-12 15:30 ` Miklos Szeredi
  2020-03-12 18:35   ` syzbot
  2020-03-13  8:53 ` Miklos Szeredi
  1 sibling, 1 reply; 4+ messages in thread
From: Miklos Szeredi @ 2020-03-12 15:30 UTC (permalink / raw)
  To: syzbot
  Cc: Jiufei Xue, linux-kernel, overlayfs, Miklos Szeredi, syzkaller-bugs

[-- Attachment #1: Type: text/plain, Size: 85 bytes --]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
63623fd4

[-- Attachment #2: ovl-fix-lockdep-warning-for-async-write.patch --]
[-- Type: text/x-patch, Size: 1410 bytes --]

---
 fs/overlayfs/file.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -243,7 +243,11 @@ static void ovl_aio_cleanup_handler(stru
 
 	if (iocb->ki_flags & IOCB_WRITE) {
 		struct inode *inode = file_inode(orig_iocb->ki_filp);
+		struct inode *real_inode = ovl_inode_real(inode);
 
+		WARN_ON(real_inode != file_inode(iocb->ki_filp));
+		/* See aio_complete_rw() */
+		__sb_writers_acquired(real_inode->i_sb, SB_FREEZE_WRITE);
 		file_end_write(iocb->ki_filp);
 		ovl_copyattr(ovl_inode_real(inode), inode);
 	}
@@ -311,6 +315,7 @@ static ssize_t ovl_write_iter(struct kio
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file_inode(file);
+	struct inode *real_inode = ovl_inode_real(inode);
 	struct fd real;
 	const struct cred *old_cred;
 	ssize_t ret;
@@ -320,7 +325,7 @@ static ssize_t ovl_write_iter(struct kio
 
 	inode_lock(inode);
 	/* Update mode */
-	ovl_copyattr(ovl_inode_real(inode), inode);
+	ovl_copyattr(real_inode, inode);
 	ret = file_remove_privs(file);
 	if (ret)
 		goto out_unlock;
@@ -346,6 +351,9 @@ static ssize_t ovl_write_iter(struct kio
 			goto out;
 
 		file_start_write(real.file);
+		WARN_ON(real_inode != file_inode(real.file));
+		/* See aio_write() */
+		__sb_writers_release(real_inode->i_sb, SB_FREEZE_WRITE);
 		aio_req->fd = real;
 		real.flags = 0;
 		aio_req->orig_iocb = iocb;

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

* Re: WARNING: lock held when returning to user space in ovl_write_iter
  2020-03-12 15:30 ` Miklos Szeredi
@ 2020-03-12 18:35   ` syzbot
  0 siblings, 0 replies; 4+ messages in thread
From: syzbot @ 2020-03-12 18:35 UTC (permalink / raw)
  To: jiufei.xue, linux-kernel, linux-unionfs, miklos, mszeredi,
	syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger crash:

Reported-and-tested-by: syzbot+9331a354f4f624a52a55@syzkaller.appspotmail.com

Tested on:

commit:         63623fd4 Merge tag 'for-linus' of git://git.kernel.org/pub..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel config:  https://syzkaller.appspot.com/x/.config?x=9833e26bab355358
dashboard link: https://syzkaller.appspot.com/bug?extid=9331a354f4f624a52a55
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=134ceef9e00000

Note: testing is done by a robot and is best-effort only.

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

* Re: WARNING: lock held when returning to user space in ovl_write_iter
  2020-03-01 19:13 WARNING: lock held when returning to user space in ovl_write_iter syzbot
  2020-03-12 15:30 ` Miklos Szeredi
@ 2020-03-13  8:53 ` Miklos Szeredi
  1 sibling, 0 replies; 4+ messages in thread
From: Miklos Szeredi @ 2020-03-13  8:53 UTC (permalink / raw)
  To: syzbot
  Cc: Jiufei Xue, linux-kernel, overlayfs, Miklos Szeredi, syzkaller-bugs

[-- Attachment #1: Type: text/plain, Size: 85 bytes --]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
63623fd4

[-- Attachment #2: ovl-fix-lockdep-warning-for-async-write.patch --]
[-- Type: text/x-patch, Size: 822 bytes --]

---
 fs/overlayfs/file.c |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -244,6 +244,9 @@ static void ovl_aio_cleanup_handler(stru
 	if (iocb->ki_flags & IOCB_WRITE) {
 		struct inode *inode = file_inode(orig_iocb->ki_filp);
 
+		/* Actually acquired in ovl_write_iter() */
+		__sb_writers_acquired(file_inode(iocb->ki_filp)->i_sb,
+				      SB_FREEZE_WRITE);
 		file_end_write(iocb->ki_filp);
 		ovl_copyattr(ovl_inode_real(inode), inode);
 	}
@@ -346,6 +349,9 @@ static ssize_t ovl_write_iter(struct kio
 			goto out;
 
 		file_start_write(real.file);
+		/* Pacify lockdep, same trick as done in aio_write() */
+		__sb_writers_release(file_inode(real.file)->i_sb,
+				     SB_FREEZE_WRITE);
 		aio_req->fd = real;
 		real.flags = 0;
 		aio_req->orig_iocb = iocb;

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

end of thread, other threads:[~2020-03-13  8:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-01 19:13 WARNING: lock held when returning to user space in ovl_write_iter syzbot
2020-03-12 15:30 ` Miklos Szeredi
2020-03-12 18:35   ` syzbot
2020-03-13  8:53 ` 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).