diff options
Diffstat (limited to 'fs/attr.c')
| -rw-r--r-- | fs/attr.c | 88 |
1 files changed, 38 insertions, 50 deletions
| @@ -14,35 +14,53 @@ | |||
| 14 | #include <linux/fcntl.h> | 14 | #include <linux/fcntl.h> |
| 15 | #include <linux/security.h> | 15 | #include <linux/security.h> |
| 16 | 16 | ||
| 17 | /* Taken over from the old code... */ | 17 | /** |
| 18 | 18 | * inode_change_ok - check if attribute changes to an inode are allowed | |
| 19 | /* POSIX UID/GID verification for setting inode attributes. */ | 19 | * @inode: inode to check |
| 20 | * @attr: attributes to change | ||
| 21 | * | ||
| 22 | * Check if we are allowed to change the attributes contained in @attr | ||
| 23 | * in the given inode. This includes the normal unix access permission | ||
| 24 | * checks, as well as checks for rlimits and others. | ||
| 25 | * | ||
| 26 | * Should be called as the first thing in ->setattr implementations, | ||
| 27 | * possibly after taking additional locks. | ||
| 28 | */ | ||
| 20 | int inode_change_ok(const struct inode *inode, struct iattr *attr) | 29 | int inode_change_ok(const struct inode *inode, struct iattr *attr) |
| 21 | { | 30 | { |
| 22 | int retval = -EPERM; | ||
| 23 | unsigned int ia_valid = attr->ia_valid; | 31 | unsigned int ia_valid = attr->ia_valid; |
| 24 | 32 | ||
| 33 | /* | ||
| 34 | * First check size constraints. These can't be overriden using | ||
| 35 | * ATTR_FORCE. | ||
| 36 | */ | ||
| 37 | if (ia_valid & ATTR_SIZE) { | ||
| 38 | int error = inode_newsize_ok(inode, attr->ia_size); | ||
| 39 | if (error) | ||
| 40 | return error; | ||
| 41 | } | ||
| 42 | |||
| 25 | /* If force is set do it anyway. */ | 43 | /* If force is set do it anyway. */ |
| 26 | if (ia_valid & ATTR_FORCE) | 44 | if (ia_valid & ATTR_FORCE) |
| 27 | goto fine; | 45 | return 0; |
| 28 | 46 | ||
| 29 | /* Make sure a caller can chown. */ | 47 | /* Make sure a caller can chown. */ |
| 30 | if ((ia_valid & ATTR_UID) && | 48 | if ((ia_valid & ATTR_UID) && |
| 31 | (current_fsuid() != inode->i_uid || | 49 | (current_fsuid() != inode->i_uid || |
| 32 | attr->ia_uid != inode->i_uid) && !capable(CAP_CHOWN)) | 50 | attr->ia_uid != inode->i_uid) && !capable(CAP_CHOWN)) |
| 33 | goto error; | 51 | return -EPERM; |
| 34 | 52 | ||
| 35 | /* Make sure caller can chgrp. */ | 53 | /* Make sure caller can chgrp. */ |
| 36 | if ((ia_valid & ATTR_GID) && | 54 | if ((ia_valid & ATTR_GID) && |
| 37 | (current_fsuid() != inode->i_uid || | 55 | (current_fsuid() != inode->i_uid || |
| 38 | (!in_group_p(attr->ia_gid) && attr->ia_gid != inode->i_gid)) && | 56 | (!in_group_p(attr->ia_gid) && attr->ia_gid != inode->i_gid)) && |
| 39 | !capable(CAP_CHOWN)) | 57 | !capable(CAP_CHOWN)) |
| 40 | goto error; | 58 | return -EPERM; |
| 41 | 59 | ||
| 42 | /* Make sure a caller can chmod. */ | 60 | /* Make sure a caller can chmod. */ |
| 43 | if (ia_valid & ATTR_MODE) { | 61 | if (ia_valid & ATTR_MODE) { |
| 44 | if (!is_owner_or_cap(inode)) | 62 | if (!is_owner_or_cap(inode)) |
| 45 | goto error; | 63 | return -EPERM; |
| 46 | /* Also check the setgid bit! */ | 64 | /* Also check the setgid bit! */ |
| 47 | if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid : | 65 | if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid : |
| 48 | inode->i_gid) && !capable(CAP_FSETID)) | 66 | inode->i_gid) && !capable(CAP_FSETID)) |
| @@ -52,12 +70,10 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr) | |||
| 52 | /* Check for setting the inode time. */ | 70 | /* Check for setting the inode time. */ |
| 53 | if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) { | 71 | if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) { |
| 54 | if (!is_owner_or_cap(inode)) | 72 | if (!is_owner_or_cap(inode)) |
| 55 | goto error; | 73 | return -EPERM; |
| 56 | } | 74 | } |
| 57 | fine: | 75 | |
| 58 | retval = 0; | 76 | return 0; |
| 59 | error: | ||
| 60 | return retval; | ||
| 61 | } | 77 | } |
| 62 | EXPORT_SYMBOL(inode_change_ok); | 78 | EXPORT_SYMBOL(inode_change_ok); |
| 63 | 79 | ||
| @@ -105,21 +121,21 @@ out_big: | |||
| 105 | EXPORT_SYMBOL(inode_newsize_ok); | 121 | EXPORT_SYMBOL(inode_newsize_ok); |
| 106 | 122 | ||
| 107 | /** | 123 | /** |
| 108 | * generic_setattr - copy simple metadata updates into the generic inode | 124 | * setattr_copy - copy simple metadata updates into the generic inode |
| 109 | * @inode: the inode to be updated | 125 | * @inode: the inode to be updated |
| 110 | * @attr: the new attributes | 126 | * @attr: the new attributes |
| 111 | * | 127 | * |
| 112 | * generic_setattr must be called with i_mutex held. | 128 | * setattr_copy must be called with i_mutex held. |
| 113 | * | 129 | * |
| 114 | * generic_setattr updates the inode's metadata with that specified | 130 | * setattr_copy updates the inode's metadata with that specified |
| 115 | * in attr. Noticably missing is inode size update, which is more complex | 131 | * in attr. Noticably missing is inode size update, which is more complex |
| 116 | * as it requires pagecache updates. See simple_setsize. | 132 | * as it requires pagecache updates. |
| 117 | * | 133 | * |
| 118 | * The inode is not marked as dirty after this operation. The rationale is | 134 | * The inode is not marked as dirty after this operation. The rationale is |
| 119 | * that for "simple" filesystems, the struct inode is the inode storage. | 135 | * that for "simple" filesystems, the struct inode is the inode storage. |
| 120 | * The caller is free to mark the inode dirty afterwards if needed. | 136 | * The caller is free to mark the inode dirty afterwards if needed. |
| 121 | */ | 137 | */ |
| 122 | void generic_setattr(struct inode *inode, const struct iattr *attr) | 138 | void setattr_copy(struct inode *inode, const struct iattr *attr) |
| 123 | { | 139 | { |
| 124 | unsigned int ia_valid = attr->ia_valid; | 140 | unsigned int ia_valid = attr->ia_valid; |
| 125 | 141 | ||
| @@ -144,32 +160,7 @@ void generic_setattr(struct inode *inode, const struct iattr *attr) | |||
| 144 | inode->i_mode = mode; | 160 | inode->i_mode = mode; |
| 145 | } | 161 | } |
| 146 | } | 162 | } |
| 147 | EXPORT_SYMBOL(generic_setattr); | 163 | EXPORT_SYMBOL(setattr_copy); |
| 148 | |||
| 149 | /* | ||
| 150 | * note this function is deprecated, the new truncate sequence should be | ||
| 151 | * used instead -- see eg. simple_setsize, generic_setattr. | ||
| 152 | */ | ||
| 153 | int inode_setattr(struct inode *inode, const struct iattr *attr) | ||
| 154 | { | ||
| 155 | unsigned int ia_valid = attr->ia_valid; | ||
| 156 | |||
| 157 | if (ia_valid & ATTR_SIZE && | ||
| 158 | attr->ia_size != i_size_read(inode)) { | ||
| 159 | int error; | ||
| 160 | |||
| 161 | error = vmtruncate(inode, attr->ia_size); | ||
| 162 | if (error) | ||
| 163 | return error; | ||
| 164 | } | ||
| 165 | |||
| 166 | generic_setattr(inode, attr); | ||
| 167 | |||
| 168 | mark_inode_dirty(inode); | ||
| 169 | |||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | EXPORT_SYMBOL(inode_setattr); | ||
| 173 | 164 | ||
| 174 | int notify_change(struct dentry * dentry, struct iattr * attr) | 165 | int notify_change(struct dentry * dentry, struct iattr * attr) |
| 175 | { | 166 | { |
| @@ -237,13 +228,10 @@ int notify_change(struct dentry * dentry, struct iattr * attr) | |||
| 237 | if (ia_valid & ATTR_SIZE) | 228 | if (ia_valid & ATTR_SIZE) |
| 238 | down_write(&dentry->d_inode->i_alloc_sem); | 229 | down_write(&dentry->d_inode->i_alloc_sem); |
| 239 | 230 | ||
| 240 | if (inode->i_op && inode->i_op->setattr) { | 231 | if (inode->i_op->setattr) |
| 241 | error = inode->i_op->setattr(dentry, attr); | 232 | error = inode->i_op->setattr(dentry, attr); |
| 242 | } else { | 233 | else |
| 243 | error = inode_change_ok(inode, attr); | 234 | error = simple_setattr(dentry, attr); |
| 244 | if (!error) | ||
| 245 | error = inode_setattr(inode, attr); | ||
| 246 | } | ||
| 247 | 235 | ||
| 248 | if (ia_valid & ATTR_SIZE) | 236 | if (ia_valid & ATTR_SIZE) |
| 249 | up_write(&dentry->d_inode->i_alloc_sem); | 237 | up_write(&dentry->d_inode->i_alloc_sem); |
