From: Paul Moore <paul@paul-moore.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: shivnandan.k@samsung.com, selinux@tycho.nsa.gov
Subject: Re: [PATCH] selinux: fix inode security list corruption
Date: Mon, 06 Oct 2014 16:31:35 -0400 [thread overview]
Message-ID: <10815679.kovQJLmdnJ@sifl> (raw)
In-Reply-To: <1412269225-3858-1-git-send-email-sds@tycho.nsa.gov>
On Thursday, October 02, 2014 01:00:25 PM Stephen Smalley wrote:
> sb_finish_set_opts() can race with inode_free_security()
> when initializing inode security structures for inodes
> created prior to initial policy load or by the filesystem
> during ->mount(). This appears to have always been
> a possible race, but commit 3dc91d4 ("SELinux: Fix possible
> NULL pointer dereference in selinux_inode_permission()")
> made it more evident by immediately reusing the unioned
> list/rcu element of the inode security structure for call_rcu()
> upon an inode_free_security(). But the underlying issue
> was already present before that commit as a possible use-after-free
> of isec.
>
> Shivnandan Kumar reported the list corruption and proposed
> a patch to split the list and rcu elements out of the union
> as separate fields of the inode_security_struct so that setting
> the rcu element would not affect the list element. However,
> this would merely hide the issue and not truly fix the code.
>
> This patch instead moves up the deletion of the list entry
> prior to dropping the sbsec->isec_lock initially. Then,
> if the inode is dropped subsequently, there will be no further
> references to the isec.
>
> Reported-by: Shivnandan Kumar <shivnandan.k@samsung.com>
> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
> ---
> security/selinux/hooks.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks for taking the time to track this down and submit a patch.
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index b0e9404..e03bad5 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -481,6 +481,7 @@ next_inode:
> list_entry(sbsec->isec_head.next,
> struct inode_security_struct, list);
> struct inode *inode = isec->inode;
> + list_del_init(&isec->list);
> spin_unlock(&sbsec->isec_lock);
> inode = igrab(inode);
> if (inode) {
> @@ -489,7 +490,6 @@ next_inode:
> iput(inode);
> }
> spin_lock(&sbsec->isec_lock);
> - list_del_init(&isec->list);
> goto next_inode;
> }
> spin_unlock(&sbsec->isec_lock);
--
paul moore
www.paul-moore.com
prev parent reply other threads:[~2014-10-06 20:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-02 17:00 [PATCH] selinux: fix inode security list corruption Stephen Smalley
2014-10-06 20:31 ` Paul Moore [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=10815679.kovQJLmdnJ@sifl \
--to=paul@paul-moore.com \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
--cc=shivnandan.k@samsung.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.