diff options
author | Dmitry Kasatkin <d.kasatkin@samsung.com> | 2014-08-19 09:48:39 -0400 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2014-09-09 10:28:52 -0400 |
commit | 17f4bad3abc7c09f42987d89ccccab02c03455a9 (patch) | |
tree | 308b64c40ab744ab7d65419bbd6df73cc559365c /security/integrity | |
parent | 86f2bc024966d962d4d7575468e226e2269d198c (diff) |
ima: remove usage of filename parameter
In all cases except ima_bprm_check() the filename was not defined
and ima_d_path() was used to find the full path. Unfortunately,
the bprm filename is a relative pathname (eg. ./<dir>/filename).
ima_bprm_check() selects between bprm->interp and bprm->filename.
The following dump demonstrates the differences between using
filename and interp.
bprm->filename
filename: ./foo.sh, pathname: /root/bin/foo.sh
filename: ./foo.sh, pathname: /bin/dash
bprm->interp
filename: ./foo.sh, pathname: /root/bin/foo.sh
filename: /bin/sh, pathname: /bin/dash
In both cases the pathnames are currently the same. This patch
removes usage of filename and interp in favor of d_absolute_path.
Changes v3:
- 11 extra bytes for "deleted" not needed (Mimi)
- purpose "replace relative bprm filename with full pathname" (Mimi)
Changes v2:
- use d_absolute_path() instead of d_path to work in chroot environments.
Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security/integrity')
-rw-r--r-- | security/integrity/ima/ima_api.c | 5 | ||||
-rw-r--r-- | security/integrity/ima/ima_main.c | 19 |
2 files changed, 10 insertions, 14 deletions
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index d9cd5ce14d2b..65c41a968cc1 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c | |||
@@ -330,10 +330,9 @@ const char *ima_d_path(struct path *path, char **pathbuf) | |||
330 | { | 330 | { |
331 | char *pathname = NULL; | 331 | char *pathname = NULL; |
332 | 332 | ||
333 | /* We will allow 11 spaces for ' (deleted)' to be appended */ | 333 | *pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); |
334 | *pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL); | ||
335 | if (*pathbuf) { | 334 | if (*pathbuf) { |
336 | pathname = d_path(path, *pathbuf, PATH_MAX + 11); | 335 | pathname = d_absolute_path(path, *pathbuf, PATH_MAX); |
337 | if (IS_ERR(pathname)) { | 336 | if (IS_ERR(pathname)) { |
338 | kfree(*pathbuf); | 337 | kfree(*pathbuf); |
339 | *pathbuf = NULL; | 338 | *pathbuf = NULL; |
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index aaf5552e808d..673a37e92ba3 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c | |||
@@ -156,8 +156,8 @@ void ima_file_free(struct file *file) | |||
156 | ima_check_last_writer(iint, inode, file); | 156 | ima_check_last_writer(iint, inode, file); |
157 | } | 157 | } |
158 | 158 | ||
159 | static int process_measurement(struct file *file, const char *filename, | 159 | static int process_measurement(struct file *file, int mask, int function, |
160 | int mask, int function, int opened) | 160 | int opened) |
161 | { | 161 | { |
162 | struct inode *inode = file_inode(file); | 162 | struct inode *inode = file_inode(file); |
163 | struct integrity_iint_cache *iint; | 163 | struct integrity_iint_cache *iint; |
@@ -218,7 +218,7 @@ static int process_measurement(struct file *file, const char *filename, | |||
218 | goto out_digsig; | 218 | goto out_digsig; |
219 | } | 219 | } |
220 | 220 | ||
221 | pathname = filename ?: ima_d_path(&file->f_path, &pathbuf); | 221 | pathname = ima_d_path(&file->f_path, &pathbuf); |
222 | 222 | ||
223 | if (action & IMA_MEASURE) | 223 | if (action & IMA_MEASURE) |
224 | ima_store_measurement(iint, file, pathname, | 224 | ima_store_measurement(iint, file, pathname, |
@@ -254,7 +254,7 @@ out: | |||
254 | int ima_file_mmap(struct file *file, unsigned long prot) | 254 | int ima_file_mmap(struct file *file, unsigned long prot) |
255 | { | 255 | { |
256 | if (file && (prot & PROT_EXEC)) | 256 | if (file && (prot & PROT_EXEC)) |
257 | return process_measurement(file, NULL, MAY_EXEC, MMAP_CHECK, 0); | 257 | return process_measurement(file, MAY_EXEC, MMAP_CHECK, 0); |
258 | return 0; | 258 | return 0; |
259 | } | 259 | } |
260 | 260 | ||
@@ -273,10 +273,7 @@ int ima_file_mmap(struct file *file, unsigned long prot) | |||
273 | */ | 273 | */ |
274 | int ima_bprm_check(struct linux_binprm *bprm) | 274 | int ima_bprm_check(struct linux_binprm *bprm) |
275 | { | 275 | { |
276 | return process_measurement(bprm->file, | 276 | return process_measurement(bprm->file, MAY_EXEC, BPRM_CHECK, 0); |
277 | (strcmp(bprm->filename, bprm->interp) == 0) ? | ||
278 | bprm->filename : bprm->interp, | ||
279 | MAY_EXEC, BPRM_CHECK, 0); | ||
280 | } | 277 | } |
281 | 278 | ||
282 | /** | 279 | /** |
@@ -292,7 +289,7 @@ int ima_bprm_check(struct linux_binprm *bprm) | |||
292 | int ima_file_check(struct file *file, int mask, int opened) | 289 | int ima_file_check(struct file *file, int mask, int opened) |
293 | { | 290 | { |
294 | ima_rdwr_violation_check(file); | 291 | ima_rdwr_violation_check(file); |
295 | return process_measurement(file, NULL, | 292 | return process_measurement(file, |
296 | mask & (MAY_READ | MAY_WRITE | MAY_EXEC), | 293 | mask & (MAY_READ | MAY_WRITE | MAY_EXEC), |
297 | FILE_CHECK, opened); | 294 | FILE_CHECK, opened); |
298 | } | 295 | } |
@@ -317,7 +314,7 @@ int ima_module_check(struct file *file) | |||
317 | #endif | 314 | #endif |
318 | return 0; /* We rely on module signature checking */ | 315 | return 0; /* We rely on module signature checking */ |
319 | } | 316 | } |
320 | return process_measurement(file, NULL, MAY_EXEC, MODULE_CHECK, 0); | 317 | return process_measurement(file, MAY_EXEC, MODULE_CHECK, 0); |
321 | } | 318 | } |
322 | 319 | ||
323 | int ima_fw_from_file(struct file *file, char *buf, size_t size) | 320 | int ima_fw_from_file(struct file *file, char *buf, size_t size) |
@@ -328,7 +325,7 @@ int ima_fw_from_file(struct file *file, char *buf, size_t size) | |||
328 | return -EACCES; /* INTEGRITY_UNKNOWN */ | 325 | return -EACCES; /* INTEGRITY_UNKNOWN */ |
329 | return 0; | 326 | return 0; |
330 | } | 327 | } |
331 | return process_measurement(file, NULL, MAY_EXEC, FIRMWARE_CHECK, 0); | 328 | return process_measurement(file, MAY_EXEC, FIRMWARE_CHECK, 0); |
332 | } | 329 | } |
333 | 330 | ||
334 | static int __init init_ima(void) | 331 | static int __init init_ima(void) |