From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, malware-list@lists.printk.net
Cc: viro@ZenIV.linux.org.uk, alan@lxorguk.ukuu.org.uk,
arjan@infradead.org, greg@kroah.com, tytso@mit.edu
Subject: [PATCH -v2 11/16] fanotify: give a special access permission check
Date: Tue, 14 Oct 2008 16:52:28 -0400 [thread overview]
Message-ID: <20081014205228.1057.97074.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20081014205009.1057.12041.stgit@paris.rdu.redhat.com>
add a special FANOTIFY_ACCESS_EXEC_PERM check. This will be applied any
place a process tries to access a file with execute permissions. Mainly
sys_execve, sys_uselib, and mmap'ing a file for exec.
Signed-off-by: Eric Paris <eparis@redhat.com>
---
fs/aio.c | 4 ++--
fs/exec.c | 10 ++++++++++
fs/read_write.c | 2 +-
include/linux/fanotify.h | 6 ++++--
mm/mmap.c | 7 +++++++
mm/mprotect.c | 6 ++++++
mm/nommu.c | 7 +++++++
7 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/fs/aio.c b/fs/aio.c
index 008de79..6395403 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1455,7 +1455,7 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb)
ret = security_file_permission(file, MAY_READ);
if (unlikely(ret))
break;
- ret = fanotify(file, FAN_ACCESS_PERM);
+ ret = fanotify(file, FAN_ACCESS_NOEXEC_PERM);
if (unlikely(ret))
break;
ret = aio_setup_single_vector(kiocb);
@@ -1490,7 +1490,7 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb)
ret = security_file_permission(file, MAY_READ);
if (unlikely(ret))
break;
- ret = fanotify(file, FAN_ACCESS_PERM);
+ ret = fanotify(file, FAN_ACCESS_NOEXEC_PERM);
if (unlikely(ret))
break;
ret = aio_setup_vectored_rw(READ, kiocb);
diff --git a/fs/exec.c b/fs/exec.c
index 3612805..ab45d65 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -140,6 +140,11 @@ asmlinkage long sys_uselib(const char __user * library)
goto out;
fsnotify_open_exec(file);
+ error = fanotify(file, FAN_ACCESS_EXEC_PERM);
+ if (error) {
+ fput(file);
+ goto out;
+ }
error = -ENOEXEC;
if(file->f_op) {
@@ -694,6 +699,11 @@ struct file *open_exec(const char *name)
return file;
fsnotify_open_exec(file);
+ err = fanotify(file, FAN_ACCESS_EXEC_PERM);
+ if (err) {
+ fput(file);
+ goto out;
+ }
err = deny_write_access(file);
if (err) {
diff --git a/fs/read_write.c b/fs/read_write.c
index a74cf76..8ab4646 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -203,7 +203,7 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
if (retval)
return retval;
if (read_write == READ) {
- retval = fanotify(file, FAN_ACCESS_PERM);
+ retval = fanotify(file, FAN_ACCESS_NOEXEC_PERM);
if (retval)
return retval;
}
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h
index 0405e4c..07b8e77 100644
--- a/include/linux/fanotify.h
+++ b/include/linux/fanotify.h
@@ -18,8 +18,9 @@
#define FAN_OPEN_EXEC 0x00000020 /* File was opened with the intention of being exec'ed */
/* userspace may also request blocking for permission checks for open and read */
-#define FAN_ACCESS_PERM 0x00000100
-#define FAN_OPEN_PERM 0x00000200
+#define FAN_ACCESS_NOEXEC_PERM 0x00000100
+#define FAN_ACCESS_EXEC_PERM 0x00000200
+#define FAN_OPEN_PERM 0x00000400
/* FIXME currently Q's have no limit.... */
#define FAN_Q_OVERFLOW 0x80000000 /* Event queued overflowed */
@@ -27,6 +28,7 @@
/* helper events */
#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
#define FAN_OPEN (FAN_OPEN_NOEXEC | FAN_OPEN_EXEC) /* open */
+#define FAN_ACCESS_PERM (FAN_ACCESS_NOEXEC_PERM | FAN_ACCESS_EXEC_PERM) /* access perm */
/*
* All of the events - we build the list by hand so that we can add flags in
diff --git a/mm/mmap.c b/mm/mmap.c
index e7a5a68..35d051f 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -18,6 +18,7 @@
#include <linux/init.h>
#include <linux/file.h>
#include <linux/fs.h>
+#include <linux/fanotify.h>
#include <linux/personality.h>
#include <linux/security.h>
#include <linux/hugetlb.h>
@@ -1027,6 +1028,12 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
default:
return -EINVAL;
}
+
+ if (prot & PROT_EXEC) {
+ error = fanotify(file, FAN_ACCESS_EXEC_PERM);
+ if (error)
+ return error;
+ }
} else {
switch (flags & MAP_TYPE) {
case MAP_SHARED:
diff --git a/mm/mprotect.c b/mm/mprotect.c
index fded06f..af1da2d 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -16,6 +16,7 @@
#include <linux/fs.h>
#include <linux/highmem.h>
#include <linux/security.h>
+#include <linux/fanotify.h>
#include <linux/mempolicy.h>
#include <linux/personality.h>
#include <linux/syscalls.h>
@@ -294,6 +295,11 @@ sys_mprotect(unsigned long start, size_t len, unsigned long prot)
if (error)
goto out;
+ if (vma->vm_file && (prot & PROT_EXEC))
+ error = fanotify(vma->vm_file, FAN_ACCESS_EXEC_PERM);
+ if (error)
+ goto out;
+
tmp = vma->vm_end;
if (tmp > end)
tmp = end;
diff --git a/mm/nommu.c b/mm/nommu.c
index ed75bc9..f541693 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -18,6 +18,7 @@
#include <linux/mman.h>
#include <linux/swap.h>
#include <linux/file.h>
+#include <linux/fanotify.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
#include <linux/slab.h>
@@ -709,6 +710,12 @@ static int validate_mmap_request(struct file *file,
/* backing file is not executable, try to copy */
capabilities &= ~BDI_CAP_MAP_DIRECT;
}
+
+ if (prot & PROT_EXEC) {
+ ret = fanotify(file, FAN_ACCESS_EXEC_PERM);
+ if (ret)
+ return ret;
+ }
}
else {
/* anonymous mappings are always memory backed and can be
next prev parent reply other threads:[~2008-10-14 20:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-14 20:51 [PATCH -v2 00/16] fanotify: novel all file access notification and permissions system Eric Paris
2008-10-14 20:51 ` [PATCH -v2 01/16] filesystem notification: create fs/notify to contain all fs notification Eric Paris
2008-10-14 20:51 ` [PATCH -v2 02/16] fsnotify: pass a file instead of an inode to open, read, and write Eric Paris
2008-10-14 20:51 ` [PATCH -v2 03/16] fanotify: fscking all notify, system wide file access notification Eric Paris
2008-10-14 20:51 ` [PATCH -v2 04/16] fsnotify: sys_execve and sys_uselib do not call into fsnotify Eric Paris
2008-10-14 20:51 ` [PATCH -v2 05/16] fanotify: make use of the new fsnotify_open_exec calls Eric Paris
2008-10-14 20:52 ` [PATCH -v2 06/16] fanotify: add a userspace interface for fanotify notifications Eric Paris
2008-10-14 20:52 ` [PATCH -v2 07/16] fanotify: fastpath to ignore certain in core inodes Eric Paris
2008-10-14 20:52 ` [PATCH -v2 08/16] fanotify: add a userspace interface for fastpaths Eric Paris
2008-10-14 20:52 ` [PATCH -v2 09/16] fanotify: add group priorities Eric Paris
2008-10-14 20:52 ` [PATCH -v2 10/16] fanotify: blocking and access granting Eric Paris
2008-10-14 20:52 ` Eric Paris [this message]
2008-10-14 20:52 ` [PATCH -v2 12/16] fanotify: user interface for access decisions Eric Paris
2008-10-14 20:52 ` [PATCH -v2 13/16] fanotify: ability for userspace to delay responses Eric Paris
2008-10-14 20:52 ` [PATCH -v2 14/16] fanotify: send pid with fanotify notification events Eric Paris
2008-10-14 20:52 ` [PATCH -v2 15/16] fanotify: send tgid with notification messages Eric Paris
2008-10-14 20:52 ` [PATCH -v2 16/16] fanotify: send file f_flags along with notifications Eric Paris
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=20081014205228.1057.97074.stgit@paris.rdu.redhat.com \
--to=eparis@redhat.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=malware-list@lists.printk.net \
--cc=tytso@mit.edu \
--cc=viro@ZenIV.linux.org.uk \
/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®