From: Stephen Smalley <sds@tycho.nsa.gov>
To: Sasha Levin <sashal@kernel.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Paul Moore <paul@paul-moore.com>,
rsiddoji@codeaurora.org, selinux@vger.kernel.org
Subject: Re: [PATCH AUTOSEL 5.5 190/542] selinux: ensure we cleanup the internal AVC counters on error in avc_insert()
Date: Fri, 14 Feb 2020 11:07:37 -0500 [thread overview]
Message-ID: <64b56666-4e4a-10e0-0a1d-60ee28615d23@tycho.nsa.gov> (raw)
In-Reply-To: <20200214154854.6746-190-sashal@kernel.org>
On 2/14/20 10:43 AM, Sasha Levin wrote:
> From: Paul Moore <paul@paul-moore.com>
>
> [ Upstream commit d8db60cb23e49a92cf8cada3297395c7fa50fdf8 ]
>
> Fix avc_insert() to call avc_node_kill() if we've already allocated
> an AVC node and the code fails to insert the node in the cache.
>
> Fixes: fa1aa143ac4a ("selinux: extended permissions for ioctls")
> Reported-by: rsiddoji@codeaurora.org
> Suggested-by: Stephen Smalley <sds@tycho.nsa.gov>
> Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
> Signed-off-by: Paul Moore <paul@paul-moore.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
You should also apply 030b995ad9ece9fa2d218af4429c1c78c2342096
("selinux: ensure we cleanup the internal AVC counters on error in
avc_update()") which fixes one additional instance of the same kind of
bug not addressed by this patch.
> ---
> security/selinux/avc.c | 51 ++++++++++++++++++++----------------------
> 1 file changed, 24 insertions(+), 27 deletions(-)
>
> diff --git a/security/selinux/avc.c b/security/selinux/avc.c
> index 23dc888ae3056..6646300f7ccb2 100644
> --- a/security/selinux/avc.c
> +++ b/security/selinux/avc.c
> @@ -617,40 +617,37 @@ static struct avc_node *avc_insert(struct selinux_avc *avc,
> struct avc_node *pos, *node = NULL;
> int hvalue;
> unsigned long flag;
> + spinlock_t *lock;
> + struct hlist_head *head;
>
> if (avc_latest_notif_update(avc, avd->seqno, 1))
> - goto out;
> + return NULL;
>
> node = avc_alloc_node(avc);
> - if (node) {
> - struct hlist_head *head;
> - spinlock_t *lock;
> - int rc = 0;
> -
> - hvalue = avc_hash(ssid, tsid, tclass);
> - avc_node_populate(node, ssid, tsid, tclass, avd);
> - rc = avc_xperms_populate(node, xp_node);
> - if (rc) {
> - kmem_cache_free(avc_node_cachep, node);
> - return NULL;
> - }
> - head = &avc->avc_cache.slots[hvalue];
> - lock = &avc->avc_cache.slots_lock[hvalue];
> + if (!node)
> + return NULL;
>
> - spin_lock_irqsave(lock, flag);
> - hlist_for_each_entry(pos, head, list) {
> - if (pos->ae.ssid == ssid &&
> - pos->ae.tsid == tsid &&
> - pos->ae.tclass == tclass) {
> - avc_node_replace(avc, node, pos);
> - goto found;
> - }
> + avc_node_populate(node, ssid, tsid, tclass, avd);
> + if (avc_xperms_populate(node, xp_node)) {
> + avc_node_kill(avc, node);
> + return NULL;
> + }
> +
> + hvalue = avc_hash(ssid, tsid, tclass);
> + head = &avc->avc_cache.slots[hvalue];
> + lock = &avc->avc_cache.slots_lock[hvalue];
> + spin_lock_irqsave(lock, flag);
> + hlist_for_each_entry(pos, head, list) {
> + if (pos->ae.ssid == ssid &&
> + pos->ae.tsid == tsid &&
> + pos->ae.tclass == tclass) {
> + avc_node_replace(avc, node, pos);
> + goto found;
> }
> - hlist_add_head_rcu(&node->list, head);
> -found:
> - spin_unlock_irqrestore(lock, flag);
> }
> -out:
> + hlist_add_head_rcu(&node->list, head);
> +found:
> + spin_unlock_irqrestore(lock, flag);
> return node;
> }
>
>
next prev parent reply other threads:[~2020-02-14 17:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200214154854.6746-1-sashal@kernel.org>
2020-02-14 15:42 ` [PATCH AUTOSEL 5.5 181/542] selinux: revert "stop passing MAY_NOT_BLOCK to the AVC upon follow_link" Sasha Levin
2020-02-14 15:42 ` [PATCH AUTOSEL 5.5 182/542] selinux: fall back to ref-walk if audit is required Sasha Levin
2020-02-14 15:43 ` [PATCH AUTOSEL 5.5 190/542] selinux: ensure we cleanup the internal AVC counters on error in avc_insert() Sasha Levin
2020-02-14 16:07 ` Stephen Smalley [this message]
2020-02-20 16:40 ` Sasha Levin
2020-02-14 15:44 ` [PATCH AUTOSEL 5.5 249/542] selinux: ensure we cleanup the internal AVC counters on error in avc_update() Sasha Levin
2020-02-14 15:46 ` [PATCH AUTOSEL 5.5 417/542] selinux: fix regression introduced by move_mount(2) syscall Sasha Levin
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=64b56666-4e4a-10e0-0a1d-60ee28615d23@tycho.nsa.gov \
--to=sds@tycho.nsa.gov \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=rsiddoji@codeaurora.org \
--cc=sashal@kernel.org \
--cc=selinux@vger.kernel.org \
--cc=stable@vger.kernel.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 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).