linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Topi Miettinen <toiwoton@gmail.com>,
	Paul Moore <paul@paul-moore.com>,
	Eric Paris <eparis@parisplace.org>,
	James Morris <james.l.morris@oracle.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"moderated list:SELINUX SECURITY MODULE" <selinux@tycho.nsa.gov>,
	"open list:SECURITY SUBSYSTEM" 
	<linux-security-module@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: selinux: should execmem disable shmat(..., SHM_EXEC)?
Date: Thu, 27 Oct 2016 09:01:35 -0400	[thread overview]
Message-ID: <732d3c0d-a7d1-22b3-d468-b0d399ba56ff@tycho.nsa.gov> (raw)
In-Reply-To: <3f453e5e-e70c-f00d-9b5b-f09addd04ada@gmail.com>

On 10/26/2016 04:31 PM, Topi Miettinen wrote:
> Hi,
> 
> Maybe this is a stupid question and I didn't test this with SELinux, but
> it looks to me that SELinux execmem does not prevent process from
> getting writable and executable memory mappings by using shmat(...,
> SHM_EXEC). Shouldn't this be blocked by execmem, I suppose it is there
> to prevent this kind of memory access?
> 
> Here's a test program:
> #include <sys/ipc.h>
> #include <sys/shm.h>
> 
> int main(void) {
>         int shmid;
>         char *execmem;
>         void (*fn)(void);
> 
>         shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0777);
>         execmem = shmat(shmid, 0, SHM_EXEC);
>         shmctl(shmid, IPC_RMID, 0);
>         *execmem = 0xc3; // retq
>         fn = (void (*)(void))execmem;
>         fn();
>         shmdt(execmem);
> }
> 
> -Topi
> 

The test program fails with a seg fault and a SELinux avc denial for
execmem permission when run in a domain that lacks execmem permission.
Thanks though for the test; I'll add it to the selinux testsuite to
ensure we don't regress in this area.

      reply	other threads:[~2016-10-27 14:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26 20:31 selinux: should execmem disable shmat(..., SHM_EXEC)? Topi Miettinen
2016-10-27 13:01 ` Stephen Smalley [this message]

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=732d3c0d-a7d1-22b3-d468-b0d399ba56ff@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=eparis@parisplace.org \
    --cc=james.l.morris@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=selinux@tycho.nsa.gov \
    --cc=serge@hallyn.com \
    --cc=toiwoton@gmail.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 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).