Skip to content

Commit e4e071b

Browse files
stefanbergermimizohar
authored andcommitted
ima: Return error code obtained from securityfs functions
If an error occurs when creating a securityfs file, return the exact error code to the caller. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 18848c7 commit e4e071b

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

security/integrity/ima/ima_fs.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,47 +452,61 @@ static const struct file_operations ima_measure_policy_ops = {
452452

453453
int __init ima_fs_init(void)
454454
{
455+
int ret;
456+
455457
ima_dir = securityfs_create_dir("ima", integrity_dir);
456458
if (IS_ERR(ima_dir))
457-
return -1;
459+
return PTR_ERR(ima_dir);
458460

459461
ima_symlink = securityfs_create_symlink("ima", NULL, "integrity/ima",
460462
NULL);
461-
if (IS_ERR(ima_symlink))
463+
if (IS_ERR(ima_symlink)) {
464+
ret = PTR_ERR(ima_symlink);
462465
goto out;
466+
}
463467

464468
binary_runtime_measurements =
465469
securityfs_create_file("binary_runtime_measurements",
466470
S_IRUSR | S_IRGRP, ima_dir, NULL,
467471
&ima_measurements_ops);
468-
if (IS_ERR(binary_runtime_measurements))
472+
if (IS_ERR(binary_runtime_measurements)) {
473+
ret = PTR_ERR(binary_runtime_measurements);
469474
goto out;
475+
}
470476

471477
ascii_runtime_measurements =
472478
securityfs_create_file("ascii_runtime_measurements",
473479
S_IRUSR | S_IRGRP, ima_dir, NULL,
474480
&ima_ascii_measurements_ops);
475-
if (IS_ERR(ascii_runtime_measurements))
481+
if (IS_ERR(ascii_runtime_measurements)) {
482+
ret = PTR_ERR(ascii_runtime_measurements);
476483
goto out;
484+
}
477485

478486
runtime_measurements_count =
479487
securityfs_create_file("runtime_measurements_count",
480488
S_IRUSR | S_IRGRP, ima_dir, NULL,
481489
&ima_measurements_count_ops);
482-
if (IS_ERR(runtime_measurements_count))
490+
if (IS_ERR(runtime_measurements_count)) {
491+
ret = PTR_ERR(runtime_measurements_count);
483492
goto out;
493+
}
484494

485495
violations =
486496
securityfs_create_file("violations", S_IRUSR | S_IRGRP,
487497
ima_dir, NULL, &ima_htable_violations_ops);
488-
if (IS_ERR(violations))
498+
if (IS_ERR(violations)) {
499+
ret = PTR_ERR(violations);
489500
goto out;
501+
}
490502

491503
ima_policy = securityfs_create_file("policy", POLICY_FILE_FLAGS,
492504
ima_dir, NULL,
493505
&ima_measure_policy_ops);
494-
if (IS_ERR(ima_policy))
506+
if (IS_ERR(ima_policy)) {
507+
ret = PTR_ERR(ima_policy);
495508
goto out;
509+
}
496510

497511
return 0;
498512
out:
@@ -503,5 +517,6 @@ int __init ima_fs_init(void)
503517
securityfs_remove(binary_runtime_measurements);
504518
securityfs_remove(ima_symlink);
505519
securityfs_remove(ima_dir);
506-
return -1;
520+
521+
return ret;
507522
}

0 commit comments

Comments
 (0)