mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
ima: Write the policy filename into IMA's sysfs policy file (#4766)
IMA validates file signatures based on the security.ima xattr. As of Linux-4.7, instead of copying the IMA policy into the securityfs policy, the IMA policy pathname can be written, allowing the IMA policy file signature to be validated. This patch modifies the existing code to first attempt to write the pathname, but on failure falls back to copying the IMA policy contents.
This commit is contained in:
parent
664e7984f8
commit
e8e42b31c5
@ -44,6 +44,22 @@ int ima_setup(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (access(IMA_SECFS_POLICY, W_OK) < 0) {
|
||||||
|
log_warning("Another IMA custom policy has already been loaded, ignoring.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
imafd = open(IMA_SECFS_POLICY, O_WRONLY|O_CLOEXEC);
|
||||||
|
if (imafd < 0) {
|
||||||
|
log_error_errno(errno, "Failed to open the IMA kernel interface "IMA_SECFS_POLICY", ignoring: %m");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* attempt to write the name of the policy file into sysfs file */
|
||||||
|
if (write(imafd, IMA_POLICY_PATH, strlen(IMA_POLICY_PATH)) > 0)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
/* fall back to copying the policy line-by-line */
|
||||||
input = fopen(IMA_POLICY_PATH, "re");
|
input = fopen(IMA_POLICY_PATH, "re");
|
||||||
if (!input) {
|
if (!input) {
|
||||||
log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, errno,
|
log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, errno,
|
||||||
@ -51,10 +67,7 @@ int ima_setup(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(IMA_SECFS_POLICY, F_OK) < 0) {
|
close(imafd);
|
||||||
log_warning("Another IMA custom policy has already been loaded, ignoring.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
imafd = open(IMA_SECFS_POLICY, O_WRONLY|O_CLOEXEC);
|
imafd = open(IMA_SECFS_POLICY, O_WRONLY|O_CLOEXEC);
|
||||||
if (imafd < 0) {
|
if (imafd < 0) {
|
||||||
@ -74,6 +87,7 @@ int ima_setup(void) {
|
|||||||
lineno);
|
lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
log_info("Successfully loaded the IMA custom policy "IMA_POLICY_PATH".");
|
log_info("Successfully loaded the IMA custom policy "IMA_POLICY_PATH".");
|
||||||
#endif /* HAVE_IMA */
|
#endif /* HAVE_IMA */
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user