Skip to content

Commit 9c630eb

Browse files
author
Miklos Szeredi
committed
ovl: simplify permission checking
The fact that we always do permission checking on the overlay inode and clear MAY_WRITE for checking access to the lower inode allows cruft to be removed from ovl_permission(). 1) "default_permissions" option effectively did generic_permission() on the overlay inode with i_mode, i_uid and i_gid updated from underlying filesystem. This is what we do by default now. It did the update using vfs_getattr() but that's only needed if the underlying filesystem can change (which is not allowed). We may later introduce a "paranoia_mode" that verifies that mode/uid/gid are not changed. 2) splitting out the IS_RDONLY() check from inode_permission() also becomes unnecessary once we remove the MAY_WRITE from the lower inode check. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 754f8cb commit 9c630eb

File tree

3 files changed

+1
-53
lines changed

3 files changed

+1
-53
lines changed

fs/overlayfs/inode.c

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -124,57 +124,13 @@ int ovl_permission(struct inode *inode, int mask)
124124
const struct cred *old_cred;
125125
int err;
126126

127-
if (ovl_is_default_permissions(inode)) {
128-
struct kstat stat;
129-
struct path realpath = { .dentry = realdentry };
130-
131-
if (mask & MAY_NOT_BLOCK)
132-
return -ECHILD;
133-
134-
realpath.mnt = ovl_entry_mnt_real(oe, inode, is_upper);
135-
136-
err = vfs_getattr(&realpath, &stat);
137-
if (err)
138-
return err;
139-
140-
if ((stat.mode ^ inode->i_mode) & S_IFMT)
141-
return -ESTALE;
142-
143-
inode->i_mode = stat.mode;
144-
inode->i_uid = stat.uid;
145-
inode->i_gid = stat.gid;
146-
147-
return generic_permission(inode, mask);
148-
}
149-
150127
/* Careful in RCU walk mode */
151128
realinode = d_inode_rcu(realdentry);
152129
if (!realinode) {
153130
WARN_ON(!(mask & MAY_NOT_BLOCK));
154131
return -ENOENT;
155132
}
156133

157-
if (mask & MAY_WRITE) {
158-
umode_t mode = realinode->i_mode;
159-
160-
/*
161-
* Writes will always be redirected to upper layer, so
162-
* ignore lower layer being read-only.
163-
*
164-
* If the overlay itself is read-only then proceed
165-
* with the permission check, don't return EROFS.
166-
* This will only happen if this is the lower layer of
167-
* another overlayfs.
168-
*
169-
* If upper fs becomes read-only after the overlay was
170-
* constructed return EROFS to prevent modification of
171-
* upper layer.
172-
*/
173-
if (is_upper && !IS_RDONLY(inode) && IS_RDONLY(realinode) &&
174-
(S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
175-
return -EROFS;
176-
}
177-
178134
/*
179135
* Check overlay inode with the creds of task and underlying inode
180136
* with creds of mounter
@@ -186,7 +142,7 @@ int ovl_permission(struct inode *inode, int mask)
186142
old_cred = ovl_override_creds(inode->i_sb);
187143
if (!is_upper)
188144
mask &= ~(MAY_WRITE | MAY_APPEND);
189-
err = __inode_permission(realinode, mask);
145+
err = inode_permission(realinode, mask);
190146
revert_creds(old_cred);
191147

192148
return err;

fs/overlayfs/overlayfs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ struct inode *ovl_inode_real(struct inode *inode);
146146
struct vfsmount *ovl_entry_mnt_real(struct ovl_entry *oe, struct inode *inode,
147147
bool is_upper);
148148
struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry);
149-
bool ovl_is_default_permissions(struct inode *inode);
150149
void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache);
151150
struct dentry *ovl_workdir(struct dentry *dentry);
152151
int ovl_want_write(struct dentry *dentry);

fs/overlayfs/super.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,6 @@ struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry)
185185
return oe->cache;
186186
}
187187

188-
bool ovl_is_default_permissions(struct inode *inode)
189-
{
190-
struct ovl_fs *ofs = inode->i_sb->s_fs_info;
191-
192-
return ofs->config.default_permissions;
193-
}
194-
195188
void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache)
196189
{
197190
struct ovl_entry *oe = dentry->d_fsdata;

0 commit comments

Comments
 (0)