Skip to content

Commit 31f75bf

Browse files
committed
apparmor: make computing policy hashes conditional on kernel parameter
Allow turning off the computation of the policy hashes via the apparmor.hash_policy kernel parameter. Signed-off-by: John Johansen <[email protected]>
1 parent aa9a39a commit 31f75bf

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

security/apparmor/lsm.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,42 +166,42 @@ static int common_perm(const char *op, const struct path *path, u32 mask,
166166
}
167167

168168
/**
169-
* common_perm_dir_dentry - common permission wrapper when path is dir, dentry
169+
* common_perm_cond - common permission wrapper around inode cond
170170
* @op: operation being checked
171-
* @dir: directory of the dentry (NOT NULL)
172-
* @dentry: dentry to check (NOT NULL)
171+
* @path: location to check (NOT NULL)
173172
* @mask: requested permissions mask
174-
* @cond: conditional info for the permission request (NOT NULL)
175173
*
176174
* Returns: %0 else error code if error or permission denied
177175
*/
178-
static int common_perm_dir_dentry(const char *op, const struct path *dir,
179-
struct dentry *dentry, u32 mask,
180-
struct path_cond *cond)
176+
static int common_perm_cond(const char *op, const struct path *path, u32 mask)
181177
{
182-
struct path path = { .mnt = dir->mnt, .dentry = dentry };
178+
struct path_cond cond = { d_backing_inode(path->dentry)->i_uid,
179+
d_backing_inode(path->dentry)->i_mode
180+
};
183181

184-
return common_perm(op, &path, mask, cond);
182+
if (!path_mediated_fs(path->dentry))
183+
return 0;
184+
185+
return common_perm(op, path, mask, &cond);
185186
}
186187

187188
/**
188-
* common_perm_path - common permission wrapper when mnt, dentry
189+
* common_perm_dir_dentry - common permission wrapper when path is dir, dentry
189190
* @op: operation being checked
190-
* @path: location to check (NOT NULL)
191+
* @dir: directory of the dentry (NOT NULL)
192+
* @dentry: dentry to check (NOT NULL)
191193
* @mask: requested permissions mask
194+
* @cond: conditional info for the permission request (NOT NULL)
192195
*
193196
* Returns: %0 else error code if error or permission denied
194197
*/
195-
static inline int common_perm_path(const char *op, const struct path *path,
196-
u32 mask)
198+
static int common_perm_dir_dentry(const char *op, const struct path *dir,
199+
struct dentry *dentry, u32 mask,
200+
struct path_cond *cond)
197201
{
198-
struct path_cond cond = { d_backing_inode(path->dentry)->i_uid,
199-
d_backing_inode(path->dentry)->i_mode
200-
};
201-
if (!path_mediated_fs(path->dentry))
202-
return 0;
202+
struct path path = { .mnt = dir->mnt, .dentry = dentry };
203203

204-
return common_perm(op, path, mask, &cond);
204+
return common_perm(op, &path, mask, cond);
205205
}
206206

207207
/**
@@ -274,7 +274,7 @@ static int apparmor_path_mknod(const struct path *dir, struct dentry *dentry,
274274

275275
static int apparmor_path_truncate(const struct path *path)
276276
{
277-
return common_perm_path(OP_TRUNC, path, MAY_WRITE | AA_MAY_META_WRITE);
277+
return common_perm_cond(OP_TRUNC, path, MAY_WRITE | AA_MAY_META_WRITE);
278278
}
279279

280280
static int apparmor_path_symlink(const struct path *dir, struct dentry *dentry,
@@ -333,17 +333,17 @@ static int apparmor_path_rename(const struct path *old_dir, struct dentry *old_d
333333

334334
static int apparmor_path_chmod(const struct path *path, umode_t mode)
335335
{
336-
return common_perm_path(OP_CHMOD, path, AA_MAY_CHMOD);
336+
return common_perm_cond(OP_CHMOD, path, AA_MAY_CHMOD);
337337
}
338338

339339
static int apparmor_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
340340
{
341-
return common_perm_path(OP_CHOWN, path, AA_MAY_CHOWN);
341+
return common_perm_cond(OP_CHOWN, path, AA_MAY_CHOWN);
342342
}
343343

344344
static int apparmor_inode_getattr(const struct path *path)
345345
{
346-
return common_perm_path(OP_GETATTR, path, AA_MAY_META_READ);
346+
return common_perm_cond(OP_GETATTR, path, AA_MAY_META_READ);
347347
}
348348

349349
static int apparmor_file_open(struct file *file, const struct cred *cred)

security/apparmor/policy_unpack.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
825825
if (error)
826826
goto fail_profile;
827827

828-
error = aa_calc_profile_hash(profile, e.version, start,
828+
if (aa_g_hash_policy)
829+
error = aa_calc_profile_hash(profile, e.version, start,
829830
e.pos - start);
830831
if (error)
831832
goto fail_profile;
@@ -841,11 +842,13 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
841842
list_add_tail(&ent->list, lh);
842843
}
843844
udata->abi = e.version & K_ABI_MASK;
844-
udata->hash = aa_calc_hash(udata->data, udata->size);
845-
if (IS_ERR(udata->hash)) {
846-
error = PTR_ERR(udata->hash);
847-
udata->hash = NULL;
848-
goto fail;
845+
if (aa_g_hash_policy) {
846+
udata->hash = aa_calc_hash(udata->data, udata->size);
847+
if (IS_ERR(udata->hash)) {
848+
error = PTR_ERR(udata->hash);
849+
udata->hash = NULL;
850+
goto fail;
851+
}
849852
}
850853
return 0;
851854

0 commit comments

Comments
 (0)