aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/fs/namei.c b/fs/namei.c
index a4dfac650c3c..d0066e17d45d 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -183,6 +183,9 @@ static int acl_permission_check(struct inode *inode, int mask, unsigned int flag
183 183
184 mask &= MAY_READ | MAY_WRITE | MAY_EXEC; 184 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
185 185
186 if (current_user_ns() != inode_userns(inode))
187 goto other_perms;
188
186 if (current_fsuid() == inode->i_uid) 189 if (current_fsuid() == inode->i_uid)
187 mode >>= 6; 190 mode >>= 6;
188 else { 191 else {
@@ -196,6 +199,7 @@ static int acl_permission_check(struct inode *inode, int mask, unsigned int flag
196 mode >>= 3; 199 mode >>= 3;
197 } 200 }
198 201
202other_perms:
199 /* 203 /*
200 * If the DACs are ok we don't need any capability check. 204 * If the DACs are ok we don't need any capability check.
201 */ 205 */
@@ -237,7 +241,7 @@ int generic_permission(struct inode *inode, int mask, unsigned int flags,
237 * Executable DACs are overridable if at least one exec bit is set. 241 * Executable DACs are overridable if at least one exec bit is set.
238 */ 242 */
239 if (!(mask & MAY_EXEC) || execute_ok(inode)) 243 if (!(mask & MAY_EXEC) || execute_ok(inode))
240 if (capable(CAP_DAC_OVERRIDE)) 244 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
241 return 0; 245 return 0;
242 246
243 /* 247 /*
@@ -245,7 +249,7 @@ int generic_permission(struct inode *inode, int mask, unsigned int flags,
245 */ 249 */
246 mask &= MAY_READ | MAY_WRITE | MAY_EXEC; 250 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
247 if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) 251 if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
248 if (capable(CAP_DAC_READ_SEARCH)) 252 if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
249 return 0; 253 return 0;
250 254
251 return -EACCES; 255 return -EACCES;
@@ -654,6 +658,7 @@ static inline int handle_reval_path(struct nameidata *nd)
654static inline int exec_permission(struct inode *inode, unsigned int flags) 658static inline int exec_permission(struct inode *inode, unsigned int flags)
655{ 659{
656 int ret; 660 int ret;
661 struct user_namespace *ns = inode_userns(inode);
657 662
658 if (inode->i_op->permission) { 663 if (inode->i_op->permission) {
659 ret = inode->i_op->permission(inode, MAY_EXEC, flags); 664 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
@@ -666,7 +671,8 @@ static inline int exec_permission(struct inode *inode, unsigned int flags)
666 if (ret == -ECHILD) 671 if (ret == -ECHILD)
667 return ret; 672 return ret;
668 673
669 if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH)) 674 if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
675 ns_capable(ns, CAP_DAC_READ_SEARCH))
670 goto ok; 676 goto ok;
671 677
672 return ret; 678 return ret;
@@ -1845,11 +1851,15 @@ static inline int check_sticky(struct inode *dir, struct inode *inode)
1845 1851
1846 if (!(dir->i_mode & S_ISVTX)) 1852 if (!(dir->i_mode & S_ISVTX))
1847 return 0; 1853 return 0;
1854 if (current_user_ns() != inode_userns(inode))
1855 goto other_userns;
1848 if (inode->i_uid == fsuid) 1856 if (inode->i_uid == fsuid)
1849 return 0; 1857 return 0;
1850 if (dir->i_uid == fsuid) 1858 if (dir->i_uid == fsuid)
1851 return 0; 1859 return 0;
1852 return !capable(CAP_FOWNER); 1860
1861other_userns:
1862 return !ns_capable(inode_userns(inode), CAP_FOWNER);
1853} 1863}
1854 1864
1855/* 1865/*
@@ -2029,7 +2039,7 @@ static int may_open(struct path *path, int acc_mode, int flag)
2029 } 2039 }
2030 2040
2031 /* O_NOATIME can only be set by the owner or superuser */ 2041 /* O_NOATIME can only be set by the owner or superuser */
2032 if (flag & O_NOATIME && !is_owner_or_cap(inode)) 2042 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
2033 return -EPERM; 2043 return -EPERM;
2034 2044
2035 /* 2045 /*
@@ -2443,7 +2453,8 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
2443 if (error) 2453 if (error)
2444 return error; 2454 return error;
2445 2455
2446 if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD)) 2456 if ((S_ISCHR(mode) || S_ISBLK(mode)) &&
2457 !ns_capable(inode_userns(dir), CAP_MKNOD))
2447 return -EPERM; 2458 return -EPERM;
2448 2459
2449 if (!dir->i_op->mknod) 2460 if (!dir->i_op->mknod)