ima: check control characters in policy file path
Subsystems (4)
PATCH 1/1 ima: check control characters in policy file path
When a policy file path contains control characters like '\r' or '\b', invalid error messages can be printed to overwrite system messages:
$ echo -e "/\rtest 12345678" > /sys/kernel/security/ima/policy
This patch rejects policy paths with control characters.
Signed-off-by Tianxing Zhang <[email protected]>
--- security/integrity/ima/ima_fs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
security/integrity/ima/ima_fs.c +9 -0
@@ -316,6 +316,7 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, {char *data;ssize_t result; +int i;if (datalen >=PAGE_SIZE ) datalen =PAGE_SIZE -1 ;
@@ -331,6 +332,14 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, goto out; } +for (i =0 ; data[i] !='\n' && data[i] !='\0' ; i++) { +if (iscntrl (data[i])) { +pr_err_once ("file path with no control characters required\n" ); + result = -EINVAL ; + goto out_free; + } + } + result =mutex_lock_interruptible (&ima_write_mutex);if (result <0 ) goto out_free;
Signature · 1 line
2.25.1
Mimi Zohar
maintainerQuoted 29 lines · Tianxing Zhang
When a policy file path contains control characters like '\r' or '\b', invalid error messages can be printed to overwrite system messages:
$ echo -e "/\rtest 12345678" > /sys/kernel/security/ima/policyThis patch rejects policy paths with control characters.
Signed-off-by Tianxing Zhang <[email protected]>--- security/integrity/ima/ima_fs.c | 9 +++++++++ 1 file changed, 9 insertions(+)security/integrity/ima/ima_fs.c +2
-0@@ -316,6 +316,7 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, {char *data;ssize_t result; +int i;if (datalen >=PAGE_SIZE ) datalen =PAGE_SIZE -1 ;@@ -331,6 +332,14 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, goto out; } +for (i =0 ; data[i] !='\n' && data[i] !='\0' ; i++) {
security/integrity/ima/ima_fs.c static ssize_t ima_write_policy(struct file *file, const char __user *buf, · line 345
Quoted 10 lines
security/integrity/ima/ima_fs.c +7
-0+if (iscntrl (data[i])) { +pr_err_once ("file path with no control characters required\n" ); + result = -EINVAL ; + goto out_free; + } + } + result =mutex_lock_interruptible (&ima_write_mutex);if (result <0 ) goto out_free;
The IMA audit messages already display pathnames via audit_log_untrustedstring(). Shouldn't any change be limited to the ima_policy_read() code path?
thanks,
Mimi