All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Zhbanov <i.zhbanov@omprussia.ru>
To: Mimi Zohar <zohar@linux.ibm.com>, linux-integrity@vger.kernel.org
Subject: Re: Should mprotect(..., PROT_EXEC) be checked by IMA?
Date: Tue, 19 Mar 2019 10:50:30 +0300	[thread overview]
Message-ID: <452752df-98f9-c361-878a-5df84ab36847@omprussia.ru> (raw)
In-Reply-To: <1552945715.8658.299.camel@linux.ibm.com>

Hi Mimi,

I guess similar to SELinux function:
---8<------------------------------------------------------------------------
static int selinux_file_mprotect(struct vm_area_struct *vma,
                                  unsigned long reqprot,
                                  unsigned long prot)
{
         const struct cred *cred = current_cred();
         u32 sid = cred_sid(cred);

         if (selinux_state.checkreqprot)
                 prot = reqprot;

         if (default_noexec &&
             (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
                 int rc = 0;
                 if (vma->vm_start >= vma->vm_mm->start_brk &&
                     vma->vm_end <= vma->vm_mm->brk) {
                         rc = avc_has_perm(&selinux_state,
                                           sid, sid, SECCLASS_PROCESS,
                                           PROCESS__EXECHEAP, NULL);
                 } else if (!vma->vm_file &&
                            ((vma->vm_start <= vma->vm_mm->start_stack &&
                              vma->vm_end >= vma->vm_mm->start_stack) ||
                             vma_is_stack_for_current(vma))) {
                         rc = avc_has_perm(&selinux_state,
                                           sid, sid, SECCLASS_PROCESS,
                                           PROCESS__EXECSTACK, NULL);
                 } else if (vma->vm_file && vma->anon_vma) {
                         /*
                          * We are making executable a file mapping that has
                          * had some COW done. Since pages might have been
                          * written, check ability to execute the possibly
                          * modified content.  This typically should only
                          * occur for text relocations.
                          */
                         rc = file_has_perm(cred, vma->vm_file, FILE__EXECMOD);
                 }
                 if (rc)
                         return rc;
         }

         return file_map_prot_check(vma->vm_file, prot, vma->vm_flags&VM_SHARED);
}
---8<------------------------------------------------------------------------

The structure vm_area_struct has a pointer vm_file pointing to mapped file
so it could be used what file's xattrs to check.

Thanks.

On 19.03.2019 0:48, Mimi Zohar wrote:
> On Mon, 2019-03-18 at 18:18 +0300, Igor Zhbanov wrote:
>> Hello!
>>
>> I've found that IMA checks for executable mmap()s but not for the
>> combination of mmap(..., PROT_READ, ...) + mprotect(..., PROT_EXEC).
>>
>> So it looks like is possible to load arbitrary executable code
>> by rewriting dlopen() and dlsym() functions to map all ELF segments
>> read-only first then making them executable with mprotect().
>>
>> So should security_file_mprotect() be changed similarly
>> to security_mmap_file() to call IMA security hook?
> 
> How?  security_mmap_file() is passed a file descriptor and the signature,
> stored as an xattr, can be verified.
> 
> Mimi

-- 
Игорь Жбанов
зам. тех. директора по технологиям
ООО «Открытая мобильная платформа»
Тел.: +7 495 269-07-79, доб. 606
Моб.: +7 903 001-98-55
E-mail: i.zhbanov@omprussia.ru

  reply	other threads:[~2019-03-19  7:50 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18 15:18 Should mprotect(..., PROT_EXEC) be checked by IMA? Igor Zhbanov
2019-03-18 21:48 ` Mimi Zohar
2019-03-19  7:50   ` Igor Zhbanov [this message]
2019-03-19 11:22     ` Mimi Zohar
2019-03-19 12:19       ` Igor Zhbanov
2019-03-19 17:05         ` Mimi Zohar
2019-03-20  8:11           ` Igor Zhbanov
2019-03-20 17:23             ` Matthew Garrett
2019-03-20 18:08               ` Igor Zhbanov
2019-03-21 11:21               ` Mimi Zohar
2019-03-21 11:48                 ` Igor Zhbanov
2019-03-21 18:04                   ` Matthew Garrett
2019-03-22  7:59                     ` Igor Zhbanov
2019-03-28 17:17                       ` Mimi Zohar
2019-03-29 10:00                         ` Igor Zhbanov
2019-03-29 10:59                           ` Mimi Zohar
2019-03-29 11:51                             ` Jordan Glover
2019-03-29 12:28                             ` Stephen Smalley
2019-03-29 12:50                               ` Igor Zhbanov
2019-04-02 22:31                                 ` Matthew Garrett
2019-04-03  9:59                                   ` Igor Zhbanov
2019-04-03 16:58                                     ` Matthew Garrett
2019-04-03 17:31                                       ` Igor Zhbanov
2019-04-03 18:19                                         ` Matthew Garrett
2019-04-03 18:47                                           ` Igor Zhbanov
2019-04-03 19:25                                             ` Matthew Garrett
2019-04-04 11:44                                               ` Igor Zhbanov
2019-04-03 12:11                                   ` Mimi Zohar
2019-04-03 13:18                                     ` Perez Yves-Alexis
2019-04-03 11:57                                 ` Mimi Zohar
2019-04-03 13:10                                   ` Stephen Smalley
2019-04-03 14:33                                     ` Mimi Zohar
2019-04-03 14:33                                       ` Stephen Smalley
2019-04-03 16:21                                         ` Mimi Zohar
2019-03-21 18:13                 ` Matthew Garrett
2019-03-19 17:07         ` Matthew Garrett

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=452752df-98f9-c361-878a-5df84ab36847@omprussia.ru \
    --to=i.zhbanov@omprussia.ru \
    --cc=linux-integrity@vger.kernel.org \
    --cc=zohar@linux.ibm.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.