From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Eric Paris <eparis@redhat.com>,
Paul Moore <pmoore@redhat.com>
Subject: [PATCH 3.14 02/23] selinux: correctly label /proc inodes in use before the policy is loaded
Date: Fri, 11 Apr 2014 09:11:51 -0700 [thread overview]
Message-ID: <20140411161200.581057879@linuxfoundation.org> (raw)
In-Reply-To: <20140411161200.236939691@linuxfoundation.org>
3.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Moore <pmoore@redhat.com>
commit f64410ec665479d7b4b77b7519e814253ed0f686 upstream.
This patch is based on an earlier patch by Eric Paris, he describes
the problem below:
"If an inode is accessed before policy load it will get placed on a
list of inodes to be initialized after policy load. After policy
load we call inode_doinit() which calls inode_doinit_with_dentry()
on all inodes accessed before policy load. In the case of inodes
in procfs that means we'll end up at the bottom where it does:
/* Default to the fs superblock SID. */
isec->sid = sbsec->sid;
if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
if (opt_dentry) {
isec->sclass = inode_mode_to_security_class(...)
rc = selinux_proc_get_sid(opt_dentry,
isec->sclass,
&sid);
if (rc)
goto out_unlock;
isec->sid = sid;
}
}
Since opt_dentry is null, we'll never call selinux_proc_get_sid()
and will leave the inode labeled with the label on the superblock.
I believe a fix would be to mimic the behavior of xattrs. Look
for an alias of the inode. If it can't be found, just leave the
inode uninitialized (and pick it up later) if it can be found, we
should be able to call selinux_proc_get_sid() ..."
On a system exhibiting this problem, you will notice a lot of files in
/proc with the generic "proc_t" type (at least the ones that were
accessed early in the boot), for example:
# ls -Z /proc/sys/kernel/shmmax | awk '{ print $4 " " $5 }'
system_u:object_r:proc_t:s0 /proc/sys/kernel/shmmax
However, with this patch in place we see the expected result:
# ls -Z /proc/sys/kernel/shmmax | awk '{ print $4 " " $5 }'
system_u:object_r:sysctl_kernel_t:s0 /proc/sys/kernel/shmmax
Cc: Eric Paris <eparis@redhat.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
security/selinux/hooks.c | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1418,15 +1418,33 @@ static int inode_doinit_with_dentry(stru
isec->sid = sbsec->sid;
if ((sbsec->flags & SE_SBPROC) && !S_ISLNK(inode->i_mode)) {
- if (opt_dentry) {
- isec->sclass = inode_mode_to_security_class(inode->i_mode);
- rc = selinux_proc_get_sid(opt_dentry,
- isec->sclass,
- &sid);
- if (rc)
- goto out_unlock;
- isec->sid = sid;
- }
+ /* We must have a dentry to determine the label on
+ * procfs inodes */
+ if (opt_dentry)
+ /* Called from d_instantiate or
+ * d_splice_alias. */
+ dentry = dget(opt_dentry);
+ else
+ /* Called from selinux_complete_init, try to
+ * find a dentry. */
+ dentry = d_find_alias(inode);
+ /*
+ * This can be hit on boot when a file is accessed
+ * before the policy is loaded. When we load policy we
+ * may find inodes that have no dentry on the
+ * sbsec->isec_head list. No reason to complain as
+ * these will get fixed up the next time we go through
+ * inode_doinit() with a dentry, before these inodes
+ * could be used again by userspace.
+ */
+ if (!dentry)
+ goto out_unlock;
+ isec->sclass = inode_mode_to_security_class(inode->i_mode);
+ rc = selinux_proc_get_sid(dentry, isec->sclass, &sid);
+ dput(dentry);
+ if (rc)
+ goto out_unlock;
+ isec->sid = sid;
}
break;
}
next prev parent reply other threads:[~2014-04-11 16:11 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-11 16:11 [PATCH 3.14 00/23] 3.14.1-stable review Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 01/23] Revert "ALSA: hda - Increment default stream numbers for AMD HDMI controllers" Greg Kroah-Hartman
2014-04-11 16:11 ` Greg Kroah-Hartman [this message]
2014-04-11 16:11 ` [PATCH 3.14 03/23] x86, pageattr: Export page unmapping interface Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 04/23] x86/efi: Make efi virtual runtime map passing more robust Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 05/23] futex: avoid race between requeue and wake Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 06/23] xen-netback: remove pointless clause from if statement Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 07/23] xen-netback: worse-case estimate in xenvif_rx_action is underestimating Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 08/23] xen-netback: BUG_ON in xenvif_rx_action() not catching overflow Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 09/23] ipv6: some ipv6 statistic counters failed to disable bh Greg Kroah-Hartman
2014-04-11 16:11 ` [PATCH 3.14 10/23] netlink: dont compare the nul-termination in nla_strcmp Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 11/23] xen-netback: disable rogue vif in kthread context Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 12/23] Call efx_set_channels() before efx->type->dimension_resources() Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 13/23] net: vxlan: fix crash when interface is created with no group Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 14/23] isdnloop: Validate NUL-terminated strings from user Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 15/23] isdnloop: several buffer overflows Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 16/23] rds: prevent dereference of a NULL device in rds_iw_laddr_check Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 17/23] net/at91_ether: avoid NULL pointer dereference Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 18/23] iwlwifi: mvm: rs: fix search cycle rules Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 19/23] ARC: [nsimosci] Change .dts to use generic 8250 UART Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 20/23] ARC: [nsimosci] Unbork console Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 21/23] futex: Allow architectures to skip futex_atomic_cmpxchg_inatomic() test Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 22/23] m68k: Skip " Greg Kroah-Hartman
2014-04-11 16:12 ` [PATCH 3.14 23/23] crypto: ghash-clmulni-intel - use C implementation for setkey() Greg Kroah-Hartman
2014-04-11 21:49 ` [PATCH 3.14 00/23] 3.14.1-stable review Guenter Roeck
2014-04-12 1:58 ` Greg Kroah-Hartman
2014-04-11 23:46 ` Shuah Khan
2014-04-12 1:59 ` Greg Kroah-Hartman
2014-04-12 5:38 ` Satoru Takeuchi
2014-04-12 15:22 ` Greg Kroah-Hartman
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=20140411161200.581057879@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=eparis@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmoore@redhat.com \
--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).