From: Roland McGrath <roland@hack.frob.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: James Morris <jmorris@namei.org>,
Eric Paris <eparis@parisplace.org>,
Stephen Smalley <sds@tycho.nsa.gov>,
selinux@tycho.nsa.gov,
John Johansen <john.johansen@canonical.com>,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] SELinux: Do not apply MMAP_ZERO check to PROT_NONE mappings
Date: Fri, 21 Oct 2011 14:39:55 -0700 (PDT) [thread overview]
Message-ID: <20111021213955.7A46F2C0BF@topped-with-meat.com> (raw)
In-Reply-To: Roland McGrath's message of Friday, 21 October 2011 14:39:16 -0700 <20111021213916.914462C0A5@topped-with-meat.com>
An mmap with PROT_NONE is done specifically to ensure that an address
will fault. So doing this on addresses below CONFIG_LSM_MMAP_MIN_ADDR
is not seeking a "dangerous" operation. Conversely, it's an attempt
to ensure robustness in case CONFIG_LSM_MMAP_MIN_ADDR or vm.mmap_min_addr
is less restrictive than the user wants to be.
Since we might let a low mapping exist at all without a check, we
add another check to prevent mprotect from granting access to such
a mapping without passing an MMAP_ZERO security check.
Signed-off-by: Roland McGrath <roland@hack.frob.com>
---
security/selinux/hooks.c | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 76e6f04..1e3657b 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3062,7 +3062,8 @@ static int selinux_file_mmap(struct file *file, unsigned long reqprot,
* at bad behaviour/exploit that we always want to get the AVC, even
* if DAC would have also denied the operation.
*/
- if (addr < CONFIG_LSM_MMAP_MIN_ADDR) {
+ if (addr < CONFIG_LSM_MMAP_MIN_ADDR &&
+ (addr_only || prot != PROT_NONE)) {
rc = avc_has_perm(sid, sid, SECCLASS_MEMPROTECT,
MEMPROTECT__MMAP_ZERO, NULL);
if (rc)
@@ -3091,6 +3092,20 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
if (selinux_checkreqprot)
prot = reqprot;
+ /*
+ * Notice that we are intentionally putting the SELinux check before
+ * the secondary cap_file_mprotect check. This is such a likely attempt
+ * at bad behaviour/exploit that we always want to get the AVC, even
+ * if DAC would have also denied the operation.
+ */
+ if (addr < CONFIG_LSM_MMAP_MIN_ADDR && prot != PROT_NONE) {
+ u32 sid = current_sid();
+ rc = avc_has_perm(sid, sid, SECCLASS_MEMPROTECT,
+ MEMPROTECT__MMAP_ZERO, NULL);
+ if (rc)
+ return rc;
+ }
+
/* do DAC check on address space usage */
rc = cap_file_mprotect(vma, reqprot, prot)
if (rc)
next prev parent reply other threads:[~2011-10-21 21:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-21 21:39 [PATCH 1/2] LSM: Do not apply mmap_min_addr " Roland McGrath
2011-10-21 21:39 ` Roland McGrath [this message]
2011-10-22 3:38 ` Linus Torvalds
2011-10-22 17:24 ` Roland McGrath
2011-10-22 18:32 ` Linus Torvalds
2011-10-22 18:41 ` Linus Torvalds
[not found] ` <20111023100835.14682pfbxag3lkao@guarana.org>
[not found] ` <CA+55aFydaGYx2nkeGps2kO2k=eV1m6xcFgH5okeqy1G8H=z+_w@mail.gmail.com>
2011-10-23 5:21 ` Kevin Easton
2011-10-23 18:52 ` Roland McGrath
2011-10-24 15:07 ` Eric Paris
2011-10-24 16:28 ` Roland McGrath
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=20111021213955.7A46F2C0BF@topped-with-meat.com \
--to=roland@hack.frob.com \
--cc=akpm@linux-foundation.org \
--cc=eparis@parisplace.org \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®