fanotify: fscking all notify, system wide file access notification
RFC 3/11 fanotify: fscking all notify, system wide file access notification
fanotify: fscking all notify, system wide file access notification
From: Eric Paris <[email protected]>
A new system wide file access notification system.
---
fs/notify/Kconfig | 14 ++ fs/notify/Makefile | 2 fs/notify/fanotify.c | 117 ++++++++++++++++++++ fs/notify/fanotify.h | 87 +++++++++++++++ fs/notify/group.c | 153 ++++++++++++++++++++++++++ fs/notify/group_user.c | 156 +++++++++++++++++++++++++++ fs/notify/notification.c | 167 +++++++++++++++++++++++++++++ fs/notify/notification_user.c | 239 +++++++++++++++++++++++++++++++++++++++++ include/linux/fanotify.h | 53 +++++++++ include/linux/fsnotify.h | 14 ++ include/linux/sched.h | 1 11 files changed, 999 insertions(+), 4 deletions(-) create mode 100644 fs/notify/fanotify.c create mode 100644 fs/notify/fanotify.h create mode 100644 fs/notify/group.c create mode 100644 fs/notify/group_user.c create mode 100644 fs/notify/notification.c create mode 100644 fs/notify/notification_user.c create mode 100644 include/linux/fanotify.h
fs/notify/Kconfig +14 -0
@@ -36,3 +36,17 @@ config INOTIFY_USER For more information, see <file:Documentation/filesystems/inotify.txt> If unsure, say Y. + +config FANOTIFY + bool "Filesystem wide access notification" + select SECURITY + default y + ---help--- + Say Y here to enable fanotify suport. fanotify is a system wide + file access notification interface. Events are read from from a + single open fd and in doing so a fd is created in the reading process + which points to the same data as the one on which the event occured. + + For more information, see <file:Documentation/filesystems/fanotify.txt> + + If unsure, say Y.
fs/notify/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_INOTIFY) += inotify.o obj-$(CONFIG_INOTIFY_USER) += inotify_user.o obj-$(CONFIG_DNOTIFY) += dnotify.o + +obj-$(CONFIG_FANOTIFY) += fanotify.o notification.o notification_user.o group.o group_user.o
fs/notify/fanotify.c new file +117 -0
117 lines not on this page · raw message
fs/notify/fanotify.h new file +87 -0
87 lines not on this page · raw message
fs/notify/group.c new file +153 -0
153 lines not on this page · raw message
fs/notify/group_user.c new file +156 -0
156 lines not on this page · raw message
fs/notify/notification.c new file +167 -0
167 lines not on this page · raw message
fs/notify/notification_user.c new file +239 -0
239 lines not on this page · raw message
include/linux/fanotify.h new file +53 -0
53 lines not on this page · raw message
include/linux/fsnotify.h +10 -4
@@ -13,6 +13,7 @@#include <linux/dnotify.h> #include <linux/inotify.h> +#include <linux/fanotify.h> #include <linux/audit.h> /*
@@ -148,6 +149,7 @@ static inline void fsnotify_access(struct file *file)dnotify_parent (dentry,DN_ACCESS );inotify_dentry_parent_queue_event (dentry, mask,0 , dentry->d_name.name);inotify_inode_queue_event (inode, mask,0 ,NULL ,NULL ); +fanotify (file,FAN_ACCESS ); }/*
@@ -165,6 +167,7 @@ static inline void fsnotify_modify(struct file *file)dnotify_parent (dentry,DN_MODIFY );inotify_dentry_parent_queue_event (dentry, mask,0 , dentry->d_name.name);inotify_inode_queue_event (inode, mask,0 ,NULL ,NULL ); +fanotify (file,FAN_MODIFY ); }/*
@@ -181,6 +184,7 @@ static inline void fsnotify_open(struct file *file)inotify_dentry_parent_queue_event (dentry, mask,0 , dentry->d_name.name);inotify_inode_queue_event (inode, mask,0 ,NULL ,NULL ); +fanotify (file,FAN_OPEN ); }/*
@@ -192,13 +196,15 @@ static inline void fsnotify_close(struct file *file)struct inode *inode = dentry->d_inode;const char *name = dentry->d_name.name;mode_t mode = file->f_mode; -u32 mask = (mode &FMODE_WRITE ) ?IN_CLOSE_WRITE :IN_CLOSE_NOWRITE ; +u32 in_mask = (mode &FMODE_WRITE ) ?IN_CLOSE_WRITE :IN_CLOSE_NOWRITE ; +u32 fan_mask = (mode &FMODE_WRITE ) ?FAN_CLOSE_WRITE :FAN_CLOSE_NOWRITE ;if (S_ISDIR (inode->i_mode)) - mask |=IN_ISDIR ; + in_mask |=IN_ISDIR ; -inotify_dentry_parent_queue_event (dentry, mask,0 , name); -inotify_inode_queue_event (inode, mask,0 ,NULL ,NULL ); +inotify_dentry_parent_queue_event (dentry, in_mask,0 , name); +inotify_inode_queue_event (inode, in_mask,0 ,NULL ,NULL ); +fanotify (file, fan_mask); }/*
include/linux/sched.h +1 -0
@@ -1488,6 +1488,7 @@ extern cputime_t task_gtime(struct task_struct *p);#define PF_EXITING 0x00000004/* getting shut down */ #define PF_EXITPIDONE 0x00000008/* pi exit done on shut down */ #define PF_VCPU 0x00000010/* I'm a virtual CPU */ +#define PF_NOFACCESS 0x00000020/* exclude from all faccesses */ #define PF_FORKNOEXEC 0x00000040/* forked but didn't exec */ #define PF_SUPERPRIV 0x00000100/* used super-user privileges */ #define PF_DUMPCORE 0x00000200/* dumped core */
Quoted 1 line · Eric Paris
fanotify: fscking all notify, system wide file access notification
Userspace api changes/additions need to also cc: the [email protected] list now.
thanks,
greg k-h
Quoted 9 lines · Eric Paris
fs/notify/fanotify.h new file +3
-0@@ -0,0 +1,87 @@ +#ifndef _LINUX_FANOTIFY_PRIVATE_H +#define _LINUX_FANOTIFY_PRIVATE_H +
fs/notify/fanotify.h line 13
Quoted 10 lines
fs/notify/fanotify.h new file +10
-0+#include <linux/fanotify.h> + + +#include <asm/atomic.h> +#include <linux/dcache.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/path.h> +#include <linux/types.h> +#include <linux/wait.h>
<asm/> includes after <linux/> please.
fs/notify/fanotify.h line 79
Quoted 9 lines
fs/notify/fanotify.h new file +9
-0+ +extern int check_notification_queue (struct fanotify_group *group); +extern void get_event (struct fanotify_event *event); +extern void put_event (struct fanotify_event *event); +extern int add_event_to_group_notification (struct fanotify_group *group,struct fanotify_event *event); +extern struct fanotify_event *remove_event_from_group_notification (struct fanotify_group *group); +extern struct fanotify_event *create_event (struct file *file,unsigned int mask); +extern struct fanotify_event_holder *alloc_event_holder (void ); +extern void destroy_event_holder (struct fanotify_event_holder *holder);
Those are some pretty generic global function names (get_event?). Please add a fanotify_ to the front of them to help developers understand them and to not polute the global name space.
fs/notify/fanotify.h line 86
Quoted 7 lines
fs/notify/fanotify.h new file +7
-0+extern __init int fanotify_notification_init (void ); +extern __init int fanotify_notification_uninit (void ); + +extern void fanotify_get_group (struct fanotify_group *group); +extern void fanotify_put_group (struct fanotify_group *group); +extern int fanotify_register_group (char *name,unsigned int mask); +extern int fanotify_unregister_group (char *name,unsigned int mask);
Like you did here nicely :)
fs/notify/fanotify.h line 32
Quoted 3 lines
fs/notify/fanotify.h new file +3
-0+DEFINE_MUTEX (groups_mutex); +struct srcu_struct groups_srcu_struct; +LIST_HEAD (groups);
Again with the generic global symbol names.
thanks,
greg k-h