Skip to content

Commit 05acefb

Browse files
author
Miklos Szeredi
committed
ovl: check permission to open real file
Call inode_permission() on real inode before opening regular file on one of the underlying layers. In some cases ovl_permission() already checks access to an underlying file, but it misses the metacopy case, and possibly other ones as well. Removing the redundant permission check from ovl_permission() should be considered later. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 292f902 commit 05acefb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fs/overlayfs/file.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,22 @@ static struct file *ovl_open_realfile(const struct file *file,
4040
struct file *realfile;
4141
const struct cred *old_cred;
4242
int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY;
43+
int acc_mode = ACC_MODE(flags);
44+
int err;
45+
46+
if (flags & O_APPEND)
47+
acc_mode |= MAY_APPEND;
4348

4449
old_cred = ovl_override_creds(inode->i_sb);
45-
realfile = open_with_fake_path(&file->f_path, flags, realinode,
46-
current_cred());
50+
err = inode_permission(realinode, MAY_OPEN | acc_mode);
51+
if (err) {
52+
realfile = ERR_PTR(err);
53+
} else if (!inode_owner_or_capable(realinode)) {
54+
realfile = ERR_PTR(-EPERM);
55+
} else {
56+
realfile = open_with_fake_path(&file->f_path, flags, realinode,
57+
current_cred());
58+
}
4759
revert_creds(old_cred);
4860

4961
pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",

0 commit comments

Comments
 (0)