]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.1/ovl-relax-warn_on-for-overlapping-layers-use-case.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.1 / ovl-relax-warn_on-for-overlapping-layers-use-case.patch
1 From acf3062a7e1ccf67c6f7e7c28671a6708fde63b0 Mon Sep 17 00:00:00 2001
2 From: Amir Goldstein <amir73il@gmail.com>
3 Date: Thu, 28 Mar 2019 17:38:29 +0200
4 Subject: ovl: relax WARN_ON() for overlapping layers use case
5
6 From: Amir Goldstein <amir73il@gmail.com>
7
8 commit acf3062a7e1ccf67c6f7e7c28671a6708fde63b0 upstream.
9
10 This nasty little syzbot repro:
11 https://syzkaller.appspot.com/x/repro.syz?x=12c7a94f400000
12
13 Creates overlay mounts where the same directory is both in upper and lower
14 layers. Simplified example:
15
16 mkdir foo work
17 mount -t overlay none foo -o"lowerdir=.,upperdir=foo,workdir=work"
18
19 The repro runs several threads in parallel that attempt to chdir into foo
20 and attempt to symlink/rename/exec/mkdir the file bar.
21
22 The repro hits a WARN_ON() I placed in ovl_instantiate(), which suggests
23 that an overlay inode already exists in cache and is hashed by the pointer
24 of the real upper dentry that ovl_create_real() has just created. At the
25 point of the WARN_ON(), for overlay dir inode lock is held and upper dir
26 inode lock, so at first, I did not see how this was possible.
27
28 On a closer look, I see that after ovl_create_real(), because of the
29 overlapping upper and lower layers, a lookup by another thread can find the
30 file foo/bar that was just created in upper layer, at overlay path
31 foo/foo/bar and hash the an overlay inode with the new real dentry as lower
32 dentry. This is possible because the overlay directory foo/foo is not
33 locked and the upper dentry foo/bar is in dcache, so ovl_lookup() can find
34 it without taking upper dir inode shared lock.
35
36 Overlapping layers is considered a wrong setup which would result in
37 unexpected behavior, but it shouldn't crash the kernel and it shouldn't
38 trigger WARN_ON() either, so relax this WARN_ON() and leave a pr_warn()
39 instead to cover all cases of failure to get an overlay inode.
40
41 The error returned from failure to insert new inode to cache with
42 inode_insert5() was changed to -EEXIST, to distinguish from the error
43 -ENOMEM returned on failure to get/allocate inode with iget5_locked().
44
45 Reported-by: syzbot+9c69c282adc4edd2b540@syzkaller.appspotmail.com
46 Fixes: 01b39dcc9568 ("ovl: use inode_insert5() to hash a newly...")
47 Signed-off-by: Amir Goldstein <amir73il@gmail.com>
48 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
49 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
50
51 ---
52 fs/overlayfs/dir.c | 2 +-
53 fs/overlayfs/inode.c | 3 ++-
54 2 files changed, 3 insertions(+), 2 deletions(-)
55
56 --- a/fs/overlayfs/dir.c
57 +++ b/fs/overlayfs/dir.c
58 @@ -260,7 +260,7 @@ static int ovl_instantiate(struct dentry
59 * hashed directory inode aliases.
60 */
61 inode = ovl_get_inode(dentry->d_sb, &oip);
62 - if (WARN_ON(IS_ERR(inode)))
63 + if (IS_ERR(inode))
64 return PTR_ERR(inode);
65 } else {
66 WARN_ON(ovl_inode_real(inode) != d_inode(newdentry));
67 --- a/fs/overlayfs/inode.c
68 +++ b/fs/overlayfs/inode.c
69 @@ -832,7 +832,7 @@ struct inode *ovl_get_inode(struct super
70 int fsid = bylower ? oip->lowerpath->layer->fsid : 0;
71 bool is_dir, metacopy = false;
72 unsigned long ino = 0;
73 - int err = -ENOMEM;
74 + int err = oip->newinode ? -EEXIST : -ENOMEM;
75
76 if (!realinode)
77 realinode = d_inode(lowerdentry);
78 @@ -917,6 +917,7 @@ out:
79 return inode;
80
81 out_err:
82 + pr_warn_ratelimited("overlayfs: failed to get inode (%i)\n", err);
83 inode = ERR_PTR(err);
84 goto out;
85 }