From: Salvatore Mesoraca <s.mesoraca16@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-security-module@vger.kernel.org,
kernel-hardening@lists.openwall.com,
Salvatore Mesoraca <s.mesoraca16@gmail.com>,
Brad Spengler <spender@grsecurity.net>,
PaX Team <pageexec@freemail.hu>,
Casey Schaufler <casey@schaufler-ca.com>,
Kees Cook <keescook@chromium.org>,
James Morris <james.l.morris@oracle.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-mm@kvack.org
Subject: [PATCH 05/11] Creation of "check_vmflags" LSM hook
Date: Mon, 12 Jun 2017 18:56:54 +0200 [thread overview]
Message-ID: <1497286620-15027-6-git-send-email-s.mesoraca16@gmail.com> (raw)
In-Reply-To: <1497286620-15027-1-git-send-email-s.mesoraca16@gmail.com>
Creation of a new LSM hook to check if a given configuration of vmflags,
for a new memory allocation request, should be allowed or not.
It's placed in "do_mmap", "do_brk_flags" and "__install_special_mapping".
Signed-off-by: Salvatore Mesoraca <s.mesoraca16@gmail.com>
Cc: linux-mm@kvack.org
---
include/linux/lsm_hooks.h | 6 ++++++
include/linux/security.h | 6 ++++++
mm/mmap.c | 9 +++++++++
security/security.c | 5 +++++
4 files changed, 26 insertions(+)
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index cc0937e..6934cc5 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -483,6 +483,10 @@
* @reqprot contains the protection requested by the application.
* @prot contains the protection that will be applied by the kernel.
* Return 0 if permission is granted.
+ * @check_vmflags:
+ * Check if the requested @vmflags are allowed.
+ * @vmflags contains requested the vmflags.
+ * Return 0 if the operation is allowed to continue.
* @file_lock:
* Check permission before performing file locking operations.
* Note: this hook mediates both flock and fcntl style locks.
@@ -1482,6 +1486,7 @@
unsigned long prot, unsigned long flags);
int (*file_mprotect)(struct vm_area_struct *vma, unsigned long reqprot,
unsigned long prot);
+ int (*check_vmflags)(vm_flags_t vmflags);
int (*file_lock)(struct file *file, unsigned int cmd);
int (*file_fcntl)(struct file *file, unsigned int cmd,
unsigned long arg);
@@ -1753,6 +1758,7 @@ struct security_hook_heads {
struct list_head mmap_addr;
struct list_head mmap_file;
struct list_head file_mprotect;
+ struct list_head check_vmflags;
struct list_head file_lock;
struct list_head file_fcntl;
struct list_head file_set_fowner;
diff --git a/include/linux/security.h b/include/linux/security.h
index 19bc364..67e33b6 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -302,6 +302,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
int security_mmap_addr(unsigned long addr);
int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
unsigned long prot);
+int security_check_vmflags(vm_flags_t vmflags);
int security_file_lock(struct file *file, unsigned int cmd);
int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
void security_file_set_fowner(struct file *file);
@@ -830,6 +831,11 @@ static inline int security_file_mprotect(struct vm_area_struct *vma,
return 0;
}
+static inline int security_check_vmflags(vm_flags_t vmflags)
+{
+ return 0;
+}
+
static inline int security_file_lock(struct file *file, unsigned int cmd)
{
return 0;
diff --git a/mm/mmap.c b/mm/mmap.c
index f82741e..e19f04e 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1363,6 +1363,9 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
vm_flags |= calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) |
mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
+ if (security_check_vmflags(vm_flags))
+ return -EPERM;
+
if (flags & MAP_LOCKED)
if (!can_do_mlock())
return -EPERM;
@@ -2833,6 +2836,9 @@ static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long
return -EINVAL;
flags |= VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
+ if (security_check_vmflags(flags))
+ return -EPERM;
+
error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
if (offset_in_page(error))
return error;
@@ -3208,6 +3214,9 @@ static struct vm_area_struct *__install_special_mapping(
int ret;
struct vm_area_struct *vma;
+ if (security_check_vmflags(vm_flags))
+ return ERR_PTR(-EPERM);
+
vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
if (unlikely(vma == NULL))
return ERR_PTR(-ENOMEM);
diff --git a/security/security.c b/security/security.c
index e390f99..25d58f0 100644
--- a/security/security.c
+++ b/security/security.c
@@ -905,6 +905,11 @@ int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
}
+int security_check_vmflags(vm_flags_t vmflags)
+{
+ return call_int_hook(check_vmflags, 0, vmflags);
+}
+
int security_file_lock(struct file *file, unsigned int cmd)
{
return call_int_hook(file_lock, 0, file, cmd);
--
1.9.1
next prev parent reply other threads:[~2017-06-12 16:58 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-12 16:56 [PATCH 00/11] S.A.R.A. a new stacked LSM Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 01/11] S.A.R.A. Documentation Salvatore Mesoraca
2017-06-12 17:49 ` [kernel-hardening] " Jann Horn
2017-06-13 7:43 ` Salvatore Mesoraca
2017-06-27 22:51 ` Kees Cook
2017-06-27 22:54 ` Kees Cook
2017-07-04 10:12 ` Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 02/11] S.A.R.A. framework creation Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 03/11] Creation of "usb_device_auth" LSM hook Salvatore Mesoraca
2017-06-12 17:35 ` Krzysztof Opasiak
2017-06-13 7:47 ` Salvatore Mesoraca
2017-06-12 19:38 ` Greg Kroah-Hartman
2017-06-13 7:50 ` Salvatore Mesoraca
2017-06-12 21:31 ` Casey Schaufler
2017-06-13 7:51 ` Salvatore Mesoraca
2017-06-13 1:15 ` kbuild test robot
2017-06-13 3:11 ` kbuild test robot
2017-06-12 16:56 ` [PATCH 04/11] S.A.R.A. USB Filtering Salvatore Mesoraca
2017-06-20 7:07 ` Pavel Machek
2017-06-20 7:53 ` Salvatore Mesoraca
2017-06-12 16:56 ` Salvatore Mesoraca [this message]
2017-06-12 21:31 ` [PATCH 05/11] Creation of "check_vmflags" LSM hook Casey Schaufler
2017-06-13 7:55 ` Salvatore Mesoraca
2017-06-13 6:34 ` Christoph Hellwig
2017-06-13 7:52 ` Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 06/11] S.A.R.A. cred blob management Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 07/11] S.A.R.A. WX Protection Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 08/11] Creation of "pagefault_handler_x86" LSM hook Salvatore Mesoraca
2017-06-12 17:32 ` Thomas Gleixner
2017-06-13 7:41 ` Salvatore Mesoraca
2017-06-12 16:56 ` [PATCH 09/11] Trampoline emulation Salvatore Mesoraca
2017-06-13 0:02 ` kbuild test robot
2017-06-12 16:56 ` [PATCH 10/11] Allowing for stacking procattr support in S.A.R.A Salvatore Mesoraca
2017-06-12 16:57 ` [PATCH 11/11] S.A.R.A. WX Protection procattr interface Salvatore Mesoraca
2017-07-09 19:35 ` [kernel-hardening] [PATCH 00/11] S.A.R.A. a new stacked LSM Mickaël Salaün
2017-07-10 7:59 ` Salvatore Mesoraca
2017-07-10 23:40 ` Mickaël Salaün
2017-07-11 16:58 ` Salvatore Mesoraca
2017-07-11 17:49 ` Matt Brown
2017-07-11 19:31 ` Mimi Zohar
2017-07-13 12:39 ` Matt Brown
2017-07-13 15:19 ` Mimi Zohar
2017-07-13 19:51 ` Serge E. Hallyn
2017-07-13 22:33 ` Matt Brown
2017-07-24 0:58 ` Casey Schaufler
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=1497286620-15027-6-git-send-email-s.mesoraca16@gmail.com \
--to=s.mesoraca16@gmail.com \
--cc=casey@schaufler-ca.com \
--cc=james.l.morris@oracle.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=pageexec@freemail.hu \
--cc=serge@hallyn.com \
--cc=spender@grsecurity.net \
/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).