[RHEL7,COMMIT] ms/ovl: fix recursive oi->lock in ovl_link()

Submitted by Konstantin Khorenko on Dec. 3, 2018, 3:52 p.m.

Details

Message ID 201812031552.wB3FqT6v000429@finist-ce7.sw.ru
State New
Series "ms/ovl: fix recursive oi->lock in ovl_link()"
Headers show

Commit Message

Konstantin Khorenko Dec. 3, 2018, 3:52 p.m.
The commit is pushed to "branch-rh7-3.10.0-862.20.2.vz7.73.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.20.2.vz7.73.17
------>
commit 92f85553310b4c8d70f9388c1c837aabc3f1e9d6
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Thu Oct 18 09:45:49 2018 +0300

    ms/ovl: fix recursive oi->lock in ovl_link()
    
    linking a non-copied-up file into a non-copied-up parent results in a
    nested call to mutex_lock_interruptible(&oi->lock). Fix this by copying up
    target parent before ovl_nlink_start(), same as done in ovl_rename().
    
    ~/unionmount-testsuite$ ./run --ov -s
    ~/unionmount-testsuite$ ln /mnt/a/foo100 /mnt/a/dir100/
    
     WARNING: possible recursive locking detected
     --------------------------------------------
     ln/1545 is trying to acquire lock:
     00000000bcce7c4c (&ovl_i_lock_key[depth]){+.+.}, at:
         ovl_copy_up_start+0x28/0x7d
     but task is already holding lock:
     0000000026d73d5b (&ovl_i_lock_key[depth]){+.+.}, at:
         ovl_nlink_start+0x3c/0xc1
    
    [SzM: this seems to be a false positive, but doing the copy-up first is
    harmless and removes the lockdep splat]
    
    Reported-by: syzbot+3ef5c0d1a5cb0b21e6be@syzkaller.appspotmail.com
    Fixes: 5f8415d6b87e ("ovl: persistent overlay inode nlink for...")
    Cc: <stable@vger.kernel.org> # v4.13
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
    
    https://pmc.acronis.com/browse/VSTOR-18481
    
    (cherry picked from commit 6cd078702f2f33cb6b19a682de3e9184112f1a46)
    Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/overlayfs/dir.c | 4 ++++
 1 file changed, 4 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 7fb210b2c5dc..8147151a6cac 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -638,6 +638,10 @@  static int ovl_link(struct dentry *old, struct inode *newdir,
 	if (err)
 		goto out_drop_write;
 
+	err = ovl_copy_up(new->d_parent);
+	if (err)
+		goto out_drop_write;
+
 	err = ovl_nlink_start(old, &locked);
 	if (err)
 		goto out_drop_write;