aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2016-03-25 15:04:36 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2016-03-28 00:47:25 -0400
commit741aca71d61c3485d1e9db3bcea00d4509cf2301 (patch)
tree3d8f7af9abb176907a1fbdfe35f1c93a7176b491 /security
parentbe01f9f28e66fa846f02196eb047c6bc445642db (diff)
apparmor: new helper - common_path_perm()
was open-coded in several places... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'security')
-rw-r--r--security/apparmor/lsm.c47
1 files changed, 12 insertions, 35 deletions
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 8d19615dcb73..ead56bfaa056 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -182,23 +182,22 @@ static int common_perm_dir_dentry(int op, struct path *dir,
182} 182}
183 183
184/** 184/**
185 * common_perm_mnt_dentry - common permission wrapper when mnt, dentry 185 * common_perm_path - common permission wrapper when mnt, dentry
186 * @op: operation being checked 186 * @op: operation being checked
187 * @mnt: mount point of dentry (NOT NULL) 187 * @path: location to check (NOT NULL)
188 * @dentry: dentry to check (NOT NULL)
189 * @mask: requested permissions mask 188 * @mask: requested permissions mask
190 * 189 *
191 * Returns: %0 else error code if error or permission denied 190 * Returns: %0 else error code if error or permission denied
192 */ 191 */
193static int common_perm_mnt_dentry(int op, struct vfsmount *mnt, 192static inline int common_perm_path(int op, const struct path *path, u32 mask)
194 struct dentry *dentry, u32 mask)
195{ 193{
196 struct path path = { mnt, dentry }; 194 struct path_cond cond = { d_backing_inode(path->dentry)->i_uid,
197 struct path_cond cond = { d_backing_inode(dentry)->i_uid, 195 d_backing_inode(path->dentry)->i_mode
198 d_backing_inode(dentry)->i_mode
199 }; 196 };
197 if (!mediated_filesystem(path->dentry))
198 return 0;
200 199
201 return common_perm(op, &path, mask, &cond); 200 return common_perm(op, path, mask, &cond);
202} 201}
203 202
204/** 203/**
@@ -271,15 +270,7 @@ static int apparmor_path_mknod(struct path *dir, struct dentry *dentry,
271 270
272static int apparmor_path_truncate(const struct path *path) 271static int apparmor_path_truncate(const struct path *path)
273{ 272{
274 struct path_cond cond = { d_backing_inode(path->dentry)->i_uid, 273 return common_perm_path(OP_TRUNC, path, MAY_WRITE | AA_MAY_META_WRITE);
275 d_backing_inode(path->dentry)->i_mode
276 };
277
278 if (!mediated_filesystem(path->dentry))
279 return 0;
280
281 return common_perm(OP_TRUNC, path, MAY_WRITE | AA_MAY_META_WRITE,
282 &cond);
283} 274}
284 275
285static int apparmor_path_symlink(struct path *dir, struct dentry *dentry, 276static int apparmor_path_symlink(struct path *dir, struct dentry *dentry,
@@ -336,31 +327,17 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
336 327
337static int apparmor_path_chmod(const struct path *path, umode_t mode) 328static int apparmor_path_chmod(const struct path *path, umode_t mode)
338{ 329{
339 if (!mediated_filesystem(path->dentry)) 330 return common_perm_path(OP_CHMOD, path, AA_MAY_CHMOD);
340 return 0;
341
342 return common_perm_mnt_dentry(OP_CHMOD, path->mnt, path->dentry, AA_MAY_CHMOD);
343} 331}
344 332
345static int apparmor_path_chown(const struct path *path, kuid_t uid, kgid_t gid) 333static int apparmor_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
346{ 334{
347 struct path_cond cond = { d_backing_inode(path->dentry)->i_uid, 335 return common_perm_path(OP_CHOWN, path, AA_MAY_CHOWN);
348 d_backing_inode(path->dentry)->i_mode
349 };
350
351 if (!mediated_filesystem(path->dentry))
352 return 0;
353
354 return common_perm(OP_CHOWN, path, AA_MAY_CHOWN, &cond);
355} 336}
356 337
357static int apparmor_inode_getattr(const struct path *path) 338static int apparmor_inode_getattr(const struct path *path)
358{ 339{
359 if (!mediated_filesystem(path->dentry)) 340 return common_perm_path(OP_GETATTR, path, AA_MAY_META_READ);
360 return 0;
361
362 return common_perm_mnt_dentry(OP_GETATTR, path->mnt, path->dentry,
363 AA_MAY_META_READ);
364} 341}
365 342
366static int apparmor_file_open(struct file *file, const struct cred *cred) 343static int apparmor_file_open(struct file *file, const struct cred *cred)