All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: Davidlohr Bueso <davidlohr@hp.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@redhat.com>, Mike Galbraith <efault@gmx.de>,
	sedat.dilek@gmail.com,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] ipc,shm: fix race with selinux
Date: Mon, 16 Sep 2013 11:23:13 +0200	[thread overview]
Message-ID: <5236CE01.8010906@colorfullife.com> (raw)
In-Reply-To: <1379300677-24188-2-git-send-email-davidlohr@hp.com>

On 09/16/2013 05:04 AM, Davidlohr Bueso wrote:
> Currently, we check shm security only under RCU. Since selinux
> can free the security structure, through selinux_sem_free_security(),
> we can run into a use-after-free condition. This bug affects both
> shmctl and shmat syscalls.
>
> The fix is obvious, make sure we hold the kern_ipc_perm.lock while
> performing these security checks.
Actually: either kern_ipc_perm or down_xx(&shm_ids(ns).rwsem) is sufficient.

>
> Reported-by: Manfred Spraul <manfred@colorfullife.com>
> Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
> ---
>   ipc/shm.c | 23 ++++++++++++++---------
>   1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 2821cdf..bc3e897 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -781,18 +781,17 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
>   
>   	shp = container_of(ipcp, struct shmid_kernel, shm_perm);
>   
> +	ipc_lock_object(&shp->shm_perm);
>   	err = security_shm_shmctl(shp, cmd);
>   	if (err)
> -		goto out_unlock1;
> +		goto out_unlock0;
This change is not necessary: down_write(shm_ids(ns).rwsem) already 
synchronizes against another IPC_RMID.
But it doesn't hurt.

> @@ -960,11 +962,12 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
>   		}
>   
>   		audit_ipc_obj(&(shp->shm_perm));
> +
> +		ipc_lock_object(&shp->shm_perm);
>   		err = security_shm_shmctl(shp, cmd);
What about audit_ipc_obj()?
calls __audit_ipc_obj
calls security_ipc_getsecid
calls security_ops->ipc_getsecid, which can be selinux_ipc_getsecid
selinux_ipc_getsecid dereferences ipcp->security

Please: Restart from 3.0.9 (i.e. before the scalability improvement 
project was started)
Every function that is moved from "synchronization with ipc_lock()" to 
"only rcu_read_lock() held" must be checked.

--
     Manfred

  reply	other threads:[~2013-09-16  9:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-16  3:04 [PATCH 0/4] ipc: shm and msg fixes Davidlohr Bueso
2013-09-16  3:04 ` [PATCH 1/4] ipc,shm: fix race with selinux Davidlohr Bueso
2013-09-16  9:23   ` Manfred Spraul [this message]
2013-09-16  3:04 ` [PATCH 2/4] ipc,shm: prevent race with rmid in shmat(2) Davidlohr Bueso
2013-09-27  5:45   ` Manfred Spraul
2013-09-27 23:40     ` Davidlohr Bueso
2013-09-16  3:04 ` [PATCH 3/4] ipc,msg: fix race with selinux Davidlohr Bueso
2013-09-16  3:04 ` [PATCH 4/4] ipc,msg: prevent race with rmid in msgsnd,msgrcv Davidlohr Bueso
2013-09-27  5:50   ` Manfred Spraul
2013-09-19 21:22 ` [PATCH 0/4] ipc: shm and msg fixes Davidlohr Bueso
2013-09-20 18:08   ` Eric Paris
2013-09-21 18:30     ` Davidlohr Bueso
2013-09-21 18:58       ` Linus Torvalds
2013-09-23  6:42         ` Davidlohr Bueso
2013-09-23 16:54           ` Linus Torvalds
2013-09-24  0:04             ` Davidlohr Bueso
2013-09-24  1:22               ` Linus Torvalds
2013-09-24  8:49                 ` Manfred Spraul
2013-09-24  9:05               ` Manfred Spraul

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=5236CE01.8010906@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=akpm@linux-foundation.org \
    --cc=davidlohr@hp.com \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riel@redhat.com \
    --cc=sedat.dilek@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /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.