linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tianxing Zhang <anakinzhang96@gmail.com>
To: zohar@linux.ibm.com
Cc: linux-integrity@vger.kernel.org
Subject: [RFC] ima: check ima-policy's path
Date: Tue, 29 Jun 2021 14:38:43 +0800	[thread overview]
Message-ID: <20210629063843.18499-1-anakinzhang96@gmail.com> (raw)

Hi, I was reading the function ima_write_policy in ima/ima_fs.c when I find the issue:

> static ssize_t ima_write_policy(struct file *file, const char __user *buf,
>                                              size_t datalen, loff_t *ppos)
> {
>         ...
>
>         if (data[0] == '/') {
>                 result = ima_read_policy(data);
>         } else if (ima_appraise & IMA_APPRAISE_POLICY) {
>                 pr_err("signed policy file (specified as an absolute pathname) required\n");
>                 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
>                                              "policy_update", "signed policy required",
>                                              1, 0);
>         ...
>         return result;
> }

For the absolute path written by the user, we only check the prefix "/". Actually, we can echo an illegal path to the /sys/kernel/security/ima/policy, e.g. "/\rtest: ddddddddddddddddddd" to inject some logs into dmesg.

Then ima_read_policy is called to return error:

> static ssize_t ima_read_policy(char *path)
> {
>         ...
>         rc = kernel_read_file_from_path(path, 0, &data, INT_MAX, NULL,
>                                                       READING_POLICY);
>         if (rc < 0) {
>                 pr_err("Unable to open file: %s (%d)", path, rc);
>                 return rc;
>         }
>         ...
> }

In ima_read_policy, the illegal path would be logged into dmesg like this:

> ...
> test: ddddddddddddddddddd (-2)/
> test: ddddddddddddddddddd (-2)/
> test: ddddddddddddddddddd (-2)/
> test: ddddddddddddddddddd (-2)/

I suggest that we should check the path in ima_write_policy to make sure it's a valid one, at least literally.

thanks,

Tianxing

             reply	other threads:[~2021-06-29  6:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29  6:38 Tianxing Zhang [this message]
2021-06-29 11:55 ` Mimi Zohar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210629063843.18499-1-anakinzhang96@gmail.com \
    --to=anakinzhang96@gmail.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=zohar@linux.ibm.com \
    --subject='Re: [RFC] ima: check ima-policy'\''s path' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).