audit: convert audit watches to use fsnotify instead of inotify
Subsystems (4)
Eric Paris
maintainerPATCH 1/7 audit: convert audit watches to use fsnotify instead of inotify
Audit currently uses inotify to pin inodes in core and to detect when watched inodes are deleted or unmounted. This patch uses fsnotify instead of inotify.
---
include/linux/fsnotify_backend.h | 5 + kernel/audit_watch.c | 209 +++++++++++++++++++++++++++----------- 2 files changed, 153 insertions(+), 61 deletions(-)
include/linux/fsnotify_backend.h +4 -1
@@ -58,9 +58,12 @@ FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\ FS_DELETE) +#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) +/* listeners that hard code group numbers near the top */ #define DNOTIFY_GROUP_NUM UINT_MAX -#define INOTIFY_GROUP_NUM (DNOTIFY_GROUP_NUM-1) +#define AUDIT_WATCH_GROUP_NUM (DNOTIFY_GROUP_NUM-1) +#define INOTIFY_GROUP_NUM (AUDIT_WATCH_GROUP_NUM-1)struct fsnotify_group ;struct fsnotify_event ;
kernel/audit_watch.c +149 -60
376 lines not on this page · raw message
Eric Paris
maintainerPATCH 2/7 audit: redo audit watch locking and refcnt in light of fsnotify
fsnotify can handle mutexes to be held across all fsnotify operations since it deals strickly in spinlocks. This can simplify and reduce some of the audit_filter_mutex taking and dropping.
---
kernel/audit_watch.c | 45 +++++---------------------------------------- 1 files changed, 5 insertions(+), 40 deletions(-)
kernel/audit_watch.c +5 -40
@@ -57,7 +57,6 @@ struct audit_parent {struct list_head ilist;/* tmp list used to free parents */ struct list_head watches;/* anchor for audit_watch->wlist */ struct fsnotify_mark_entry mark;/* fsnotify mark on the inode */ -unsigned flags;/* status flags */ };static struct kmem_cache *audit_watch_cache__read_mostly ;
@@ -66,17 +65,6 @@ static struct kmem_cache *audit_parent_cache __read_mostly;/* fsnotify handle. */ struct fsnotify_group *audit_watch_group; -/* -* audit_parent status flags: -* -* AUDIT_PARENT_INVALID - set anytime rules/watches are auto-removed due to -* a filesystem event to ensure we're adding audit watches to a valid parent. -* Technically not needed for FS_DELETE_SELF or FS_UNMOUNT events, as we cannot -* receive them while we have nameidata, but must be used for FS_MOVE_SELF which -* we can receive while holding nameidata. -*/ -#define AUDIT_PARENT_INVALID 0x001 -/* fsnotify events we care about. */ #define AUDIT_FS_WATCH (FS_MOVE | FS_CREATE | FS_DELETE | FS_DELETE_SELF |\ FS_MOVE_SELF | FS_EVENT_ON_CHILD)
@@ -173,12 +161,9 @@ static struct audit_parent *audit_init_parent(struct path *parent_path)return ERR_PTR (-ENOMEM );INIT_LIST_HEAD (&parent->watches); - parent->flags =0 ;fsnotify_init_mark (&parent->mark, audit_watch_free_mark); parent->mark.mask =AUDIT_FS_WATCH ; -/* grab a ref so fsnotify mark hangs around until we take audit_filter_mutex */ -audit_get_parent (parent); ret =fsnotify_add_mark (&parent->mark, audit_watch_group, inode);if (ret <0 ) {audit_free_parent (parent);
@@ -357,7 +342,6 @@ static void audit_remove_parent_watches(struct audit_parent *parent)struct audit_entry *e;mutex_lock (&audit_filter_mutex); - parent->flags |=AUDIT_PARENT_INVALID ;list_for_each_entry_safe (w, nextw, &parent->watches, wlist) {list_for_each_entry_safe (r, nextr, &w->rules, rlist) { e = container_of(r, struct audit_entry, rule);
@@ -471,35 +455,25 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list) goto error; } +mutex_lock (&audit_filter_mutex); +/* update watch filter fields */ if (watch_path.dentry) { watch->dev = watch_path.dentry->d_inode->i_sb->s_dev; watch->ino = watch_path.dentry->d_inode->i_ino; } -/* The audit_filter_mutex must not be held during inotify calls because -* we hold it during inotify event callback processing. If an existing -* inotify watch is found, inotify_find_watch() grabs a reference before -* returning. -*/ +/* either find an old parent or attach a new one */ parent =audit_find_parent (parent_path.dentry->d_inode);if (!parent) { parent =audit_init_parent (&parent_path);if (IS_ERR (parent)) { -/* caller expects mutex locked */ -mutex_lock (&audit_filter_mutex); ret =PTR_ERR (parent); goto error; } } -mutex_lock (&audit_filter_mutex); - -/* parent was moved before we took audit_filter_mutex */ -if (parent->flags &AUDIT_PARENT_INVALID ) - ret = -ENOENT ; -else -audit_add_to_parent (krule, parent); +audit_add_to_parent (krule, parent);/* match get in audit_find_parent or audit_init_parent */ audit_put_parent (parent);
@@ -597,20 +571,11 @@ static int audit_watch_handle_event(struct fsnotify_group *group, struct fsnotifreturn 0 ; } -static void audit_watch_freeing_mark (struct fsnotify_mark_entry *entry,struct fsnotify_group *group) -{ -struct audit_parent *parent; - - parent = container_of(entry, struct audit_parent, mark); -/* taken from audit_handle_ievent & FS_IGNORED please figure out what I match... */ -audit_put_parent (parent); -} -static const struct fsnotify_ops audit_watch_fsnotify_ops = { .should_send_event = audit_watch_should_send_event, .handle_event = audit_watch_handle_event, .free_group_priv =NULL , - .freeing_mark = audit_watch_freeing_mark, + .freeing_mark =NULL , .free_event_priv =NULL , };
Eric Paris
maintainerPATCH 3/7 audit: do not get and put just to free a watch
In reply to Eric Parisdeleting audit watch rules is not currently done under audit_filter_mutex. It was done this way because we could not hold the mutex during inotify manipulation. Since we are using fsnotify we don't need to do the extra get/put pair nor do we need the private list on which to store the parents while they are about to be freed.
---
kernel/audit.h | 3 +-- kernel/audit_watch.c | 27 +++------------------------ kernel/auditfilter.c | 6 +----- 3 files changed, 5 insertions(+), 31 deletions(-)
kernel/audit.h +1 -2
@@ -108,8 +108,7 @@ extern void audit_put_watch(struct audit_watch *watch);extern void audit_get_watch (struct audit_watch *watch);extern int audit_to_watch (struct audit_krule *krule,char *path,int len,u32 op);extern int audit_add_watch (struct audit_krule *krule,struct list_head **list); -extern void audit_remove_watch_rule (struct audit_krule *krule,struct list_head *list); -extern void audit_watch_inotify_unregister (struct list_head *in_list); +extern void audit_remove_watch_rule (struct audit_krule *krule);extern char *audit_watch_path (struct audit_watch *watch);extern int audit_watch_compare (struct audit_watch *watch,unsigned long ino,dev_t dev);extern struct audit_entry *audit_dupe_rule (struct audit_krule *old);
kernel/audit_watch.c +3 -24
@@ -54,7 +54,6 @@ struct audit_watch { };struct audit_parent { -struct list_head ilist;/* tmp list used to free parents */ struct list_head watches;/* anchor for audit_watch->wlist */ struct fsnotify_mark_entry mark;/* fsnotify mark on the inode */ };
@@ -358,20 +357,6 @@ static void audit_remove_parent_watches(struct audit_parent *parent)fsnotify_destroy_mark_by_entry (&parent->mark); } -/* Unregister inotify watches for parents on in_list. -* Generates an FS_IGNORED event. */ -void audit_watch_inotify_unregister (struct list_head *in_list) -{ -struct audit_parent *p, *n; - -list_for_each_entry_safe (p, n, in_list, ilist) { -list_del (&p->ilist); -fsnotify_destroy_mark_by_entry (&p->mark); -/* matches the get in audit_remove_watch_rule() */ -audit_put_parent (p); - } -} -/* Get path information necessary for adding watches. */ static int audit_get_path (const char *path,struct path *parent_path,struct path *watch_path)
@@ -486,7 +471,7 @@ error: } -void audit_remove_watch_rule (struct audit_krule *krule,struct list_head *list) +void audit_remove_watch_rule (struct audit_krule *krule) {struct audit_watch *watch = krule->watch;struct audit_parent *parent = watch->parent;
@@ -497,15 +482,9 @@ void audit_remove_watch_rule(struct audit_krule *krule, struct list_head *list)audit_remove_watch (watch);if (list_empty (&parent->watches)) { -/* Put parent on the un-registration list. -* Grab a reference before releasing -* audit_filter_mutex, to be released in -* audit_watch_inotify_unregister(). -* If filesystem is going away, just leave -* the sucker alone, eviction will take -* care of it. */ audit_get_parent (parent); -list_add (&parent->ilist, list); +fsnotify_destroy_mark_by_entry (&parent->mark); +audit_put_parent (parent); } } }
kernel/auditfilter.c +1 -5
@@ -944,7 +944,6 @@ static inline int audit_del_rule(struct audit_entry *entry)struct audit_watch *watch = entry->rule.watch;struct audit_tree *tree = entry->rule.tree;struct list_head *list; -LIST_HEAD (inotify_unregister_list);int ret =0 ;#ifdef CONFIG_AUDITSYSCALL int dont_count =0 ;
@@ -964,7 +963,7 @@ static inline int audit_del_rule(struct audit_entry *entry) }if (e->rule.watch) -audit_remove_watch_rule (&e->rule, &inotify_unregister_list); +audit_remove_watch_rule (&e->rule);if (e->rule.tree)audit_remove_tree_rule (&e->rule);
@@ -982,9 +981,6 @@ static inline int audit_del_rule(struct audit_entry *entry)#endif mutex_unlock (&audit_filter_mutex); -if (!list_empty (&inotify_unregister_list)) -audit_watch_inotify_unregister (&inotify_unregister_list); - out:if (watch)audit_put_watch (watch);/* match initial get */
Eric Paris
maintainerPATCH 4/7 fsnotify: duplicate fsnotify_mark_entry data between 2 marks
In reply to Eric ParisSimple copy fsnotify information from one mark to another in preparation for the second mark to replace the first.
---
fs/notify/inode_mark.c | 10 +++++++++- include/linux/fsnotify_backend.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletions(-)
fs/notify/inode_mark.c +9 -1
@@ -283,12 +283,20 @@ struct fsnotify_mark_entry *fsnotify_find_mark_entry(struct fsnotify_group *groureturn NULL ; } +void fsnotify_duplicate_mark (struct fsnotify_mark_entry *new,struct fsnotify_mark_entry *old) +{ +assert_spin_locked (&old->lock); + new->inode = old->inode; + new->group = old->group; + new->mask = old->mask; + new->free_mark = old->free_mark; +} +/* * Nothing fancy, just initialize lists and locks and counters. */ void fsnotify_init_mark (struct fsnotify_mark_entry *entry,void (*free_mark)(struct fsnotify_mark_entry *entry)) - {spin_lock_init (&entry->lock);atomic_set (&entry->refcnt,1 );
include/linux/fsnotify_backend.h +2 -0
@@ -342,6 +342,8 @@ extern void fsnotify_recalc_inode_mask(struct inode *inode);extern void fsnotify_init_mark (struct fsnotify_mark_entry *entry,void (*free_mark)(struct fsnotify_mark_entry *entry));/* find (and take a reference) to a mark associated with group and inode */ extern struct fsnotify_mark_entry *fsnotify_find_mark_entry (struct fsnotify_group *group,struct inode *inode); +/* copy the values from old into new */ +extern void fsnotify_duplicate_mark (struct fsnotify_mark_entry *new,struct fsnotify_mark_entry *old);/* attach the mark to both the group and the inode */ extern int fsnotify_add_mark (struct fsnotify_mark_entry *entry,struct fsnotify_group *group,struct inode *inode);/* given a mark, flag it to be freed when all references are dropped */
Eric Paris
maintainerPATCH 5/7 fsnotify: allow addition of duplicate fsnotify marks
In reply to Eric ParisThis patch allows a task to add a second fsnotify mark to an inode for the same group. This mark will be added to the end of the inode's list and
this will never be found by the stand fsnotify_find_mark() function. This
is useful if a user wants to add a new mark before removing the old one.
---
fs/notify/dnotify/dnotify.c | 2 +- fs/notify/inode_mark.c | 8 +++++--- fs/notify/inotify/inotify_user.c | 2 +- include/linux/fsnotify_backend.h | 2 +- kernel/audit_watch.c | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-)
fs/notify/dnotify/dnotify.c +1 -1
@@ -361,7 +361,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) dnentry = container_of(entry, struct dnotify_mark_entry, fsn_entry);spin_lock (&entry->lock); }else { -fsnotify_add_mark (new_entry, dnotify_group, inode); +fsnotify_add_mark (new_entry, dnotify_group, inode,0 );spin_lock (&new_entry->lock); entry = new_entry; dnentry = new_dnentry;
fs/notify/inode_mark.c +5 -3
@@ -313,9 +313,10 @@ void fsnotify_init_mark(struct fsnotify_mark_entry *entry,* event types should be delivered to which group and for which inodes. */ int fsnotify_add_mark (struct fsnotify_mark_entry *entry, -struct fsnotify_group *group,struct inode *inode) +struct fsnotify_group *group,struct inode *inode, +int allow_dups) { -struct fsnotify_mark_entry *lentry; +struct fsnotify_mark_entry *lentry =NULL ;int ret =0 ; inode =igrab (inode);
@@ -335,7 +336,8 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry, entry->group = group; entry->inode = inode; - lentry =fsnotify_find_mark_entry (group, inode); +if (!allow_dups) + lentry =fsnotify_find_mark_entry (group, inode);if (!lentry) {hlist_add_head (&entry->i_list, &inode->i_fsnotify_mark_entries);list_add (&entry->g_list, &group->mark_entries);
fs/notify/inotify/inotify_user.c +1 -1
@@ -467,7 +467,7 @@ find_entry: goto out_err; } - ret =fsnotify_add_mark (&ientry->fsn_entry, group, inode); + ret =fsnotify_add_mark (&ientry->fsn_entry, group, inode,0 );if (ret == -EEXIST ) goto find_entry;else if (ret)
include/linux/fsnotify_backend.h +1 -1
@@ -345,7 +345,7 @@ extern struct fsnotify_mark_entry *fsnotify_find_mark_entry(struct fsnotify_grou/* copy the values from old into new */ extern void fsnotify_duplicate_mark (struct fsnotify_mark_entry *new,struct fsnotify_mark_entry *old);/* attach the mark to both the group and the inode */ -extern int fsnotify_add_mark (struct fsnotify_mark_entry *entry,struct fsnotify_group *group,struct inode *inode); +extern int fsnotify_add_mark (struct fsnotify_mark_entry *entry,struct fsnotify_group *group,struct inode *inode,int allow_dups);/* given a mark, flag it to be freed when all references are dropped */ extern void fsnotify_destroy_mark_by_entry (struct fsnotify_mark_entry *entry);/* run all the marks in a group, and flag them to be freed */
kernel/audit_watch.c +1 -1
@@ -163,7 +163,7 @@ static struct audit_parent *audit_init_parent(struct path *parent_path)fsnotify_init_mark (&parent->mark, audit_watch_free_mark); parent->mark.mask =AUDIT_FS_WATCH ; - ret =fsnotify_add_mark (&parent->mark, audit_watch_group, inode); + ret =fsnotify_add_mark (&parent->mark, audit_watch_group, inode,0 );if (ret <0 ) {audit_free_parent (parent);return ERR_PTR (ret);
Eric Paris
maintainerPATCH 6/7 audit: reimplement audit_trees using fsnotify rather than inotify
In reply to Eric ParisSimply switch audit_trees from using inotify to using fsnotify for it's inode pinning and disappearing act information.
---
include/linux/fsnotify_backend.h | 5 + init/Kconfig | 2 kernel/audit_tree.c | 223 +++++++++++++++++++++----------------- kernel/auditsc.c | 4 - 4 files changed, 130 insertions(+), 104 deletions(-)
include/linux/fsnotify_backend.h +3 -2
@@ -62,8 +62,9 @@/* listeners that hard code group numbers near the top */ #define DNOTIFY_GROUP_NUM UINT_MAX -#define AUDIT_WATCH_GROUP_NUM (DNOTIFY_GROUP_NUM-1) -#define INOTIFY_GROUP_NUM (AUDIT_WATCH_GROUP_NUM-1) +#define AUDIT_WATCH_GROUP_NUM (DNOTIFY_GROUP_NUM-1) +#define AUDIT_TREE_GROUP_NUM (AUDIT_WATCH_GROUP_NUM-1) +#define INOTIFY_GROUP_NUM (AUDIT_TREE_GROUP_NUM-1)struct fsnotify_group ;struct fsnotify_event ;
init/Kconfig +1 -1
@@ -303,7 +303,7 @@ config AUDITSYSCALL config AUDIT_TREE def_bool y depends on AUDITSYSCALL - select INOTIFY + select FSNOTIFY menu "RCU Subsystem"
kernel/audit_tree.c +124 -99
391 lines not on this page · raw message
kernel/auditsc.c +2 -2
@@ -1718,7 +1718,7 @@ static inline void handle_one(const struct inode *inode)struct audit_tree_refs *p;struct audit_chunk *chunk;int count; -if (likely (list_empty (&inode->inotify_watches))) +if (likely (hlist_empty (&inode->i_fsnotify_mark_entries)))return ; context = current->audit_context; p = context->trees;
@@ -1761,7 +1761,7 @@ retry: seq =read_seqbegin (&rename_lock);for (;;) {struct inode *inode = d->d_inode; -if (inode &&unlikely (!list_empty (&inode->inotify_watches))) { +if (inode &&unlikely (!hlist_empty (&inode->i_fsnotify_mark_entries))) {struct audit_chunk *chunk; chunk =audit_tree_lookup (inode);if (chunk) {
Eric Paris
maintainerPATCH 7/7 audit: move audit to a subdirectory
In reply to Eric ParisThe audit subsystem currently has 5 files in kernel/ and soon to be 6. Simply move them into an easily organized subdir for cleanup and move the audit Kconfig from init/Kconfig into kernel/audit/Kconfig to make it easier to maintain.
---
MAINTAINERS | 2 init/Kconfig | 24 kernel/Makefile | 4 kernel/audit.c | 1521 --------------------------- kernel/audit.h | 158 --- kernel/audit/Kconfig | 23 kernel/audit/Makefile | 7 kernel/audit/audit.c | 1521 +++++++++++++++++++++++++++ kernel/audit/audit.h | 158 +++ kernel/audit/audit_tree.c | 942 ++++++++++++++++ kernel/audit/audit_watch.c | 574 ++++++++++ kernel/audit/auditfilter.c | 1366 ++++++++++++++++++++++++ kernel/audit/auditsc.c | 2522 ++++++++++++++++++++++++++++++++++++++++++++ kernel/audit_tree.c | 942 ---------------- kernel/audit_watch.c | 574 ---------- kernel/auditfilter.c | 1366 ------------------------ kernel/auditsc.c | 2522 -------------------------------------------- kernel/signal.c | 2 18 files changed, 7117 insertions(+), 7111 deletions(-) delete mode 100644 kernel/audit.c delete mode 100644 kernel/audit.h create mode 100644 kernel/audit/Kconfig create mode 100644 kernel/audit/Makefile create mode 100644 kernel/audit/audit.c create mode 100644 kernel/audit/audit.h create mode 100644 kernel/audit/audit_tree.c create mode 100644 kernel/audit/audit_watch.c create mode 100644 kernel/audit/auditfilter.c create mode 100644 kernel/audit/auditsc.c delete mode 100644 kernel/audit_tree.c delete mode 100644 kernel/audit_watch.c delete mode 100644 kernel/auditfilter.c delete mode 100644 kernel/auditsc.c
MAINTAINERS +1 -1
@@ -1058,7 +1058,7 @@ W: http://people.redhat.com/sgrubb/audit/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current.git S: Maintained F: include/linux/audit.h -F: kernel/audit* +F: kernel/audit/ AUXILIARY DISPLAY DRIVERS P: Miguel Ojeda Sandonis
init/Kconfig +1 -23
@@ -281,29 +281,7 @@ config TASK_IO_ACCOUNTING Say N if unsure. -config AUDIT - bool "Auditing support" - depends on NET - help - Enable auditing infrastructure that can be used with another - kernel subsystem, such as SELinux (which requires this for - logging of avc messages output). Does not do system-call - auditing without CONFIG_AUDITSYSCALL. - -config AUDITSYSCALL - bool "Enable system-call auditing support" - depends on AUDIT && (X86 || PPC || PPC64 || S390 || IA64 || UML || SPARC64|| SUPERH) - default y if SECURITY_SELINUX - help - Enable low-overhead system-call auditing infrastructure that - can be used independently or with another kernel subsystem, - such as SELinux. To use audit's filesystem watch feature, please - ensure that INOTIFY is configured. - -config AUDIT_TREE - def_bool y - depends on AUDITSYSCALL - select FSNOTIFY +source "kernel/audit/Kconfig" menu "RCU Subsystem"
kernel/Makefile +1 -3
@@ -68,9 +68,7 @@ obj-$(CONFIG_IKCONFIG) += configs.o obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o obj-$(CONFIG_STOP_MACHINE) += stop_machine.o obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o -obj-$(CONFIG_AUDIT) += audit.o auditfilter.o -obj-$(CONFIG_AUDITSYSCALL) += auditsc.o audit_watch.o -obj-$(CONFIG_AUDIT_TREE) += audit_tree.o +obj-y += audit/ obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
kernel/audit/Kconfig new file +23 -0
@@ -0,0 +1,23 @@ +config AUDIT + bool "Auditing support" + depends on NET + help + Enable auditing infrastructure that can be used with another + kernel subsystem, such as SELinux (which requires this for + logging of avc messages output). Does not do system-call + auditing without CONFIG_AUDITSYSCALL. + +config AUDITSYSCALL + bool "Enable system-call auditing support" + depends on AUDIT && (X86 || PPC || PPC64 || S390 || IA64 || UML || SPARC64|| SUPERH) + default y if SECURITY_SELINUX + help + Enable low-overhead system-call auditing infrastructure that + can be used independently or with another kernel subsystem, + such as SELinux. To use audit's filesystem watch feature, please + ensure that FSNOTIFY is configured. + +config AUDIT_TREE + def_bool y + depends on AUDITSYSCALL + select FSNOTIFY
kernel/audit/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for audit +# + +obj-$(CONFIG_AUDIT) += audit.o auditfilter.o +obj-$(CONFIG_AUDITSYSCALL) += auditsc.o audit_watch.o +obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
kernel/audit/audit.c renamed from kernel/audit.c +0 -0
kernel/audit/audit.h renamed from kernel/audit.h +0 -0
kernel/audit/audit_tree.c renamed from kernel/audit_tree.c +0 -0
kernel/audit/audit_watch.c renamed from kernel/audit_watch.c +0 -0
kernel/audit/auditfilter.c renamed from kernel/auditfilter.c +0 -0
kernel/audit/auditsc.c renamed from kernel/auditsc.c +0 -0
kernel/signal.c +1 -1
@@ -33,7 +33,7 @@#include <asm/uaccess.h> #include <asm/unistd.h> #include <asm/siginfo.h> -#include "audit.h" /* audit_signal_info() */ +#include "audit/audit.h" /* audit_signal_info() */ /* * SLAB caches for signal bits.
Quoted 5 lines · Eric Paris
Audit currently uses inotify to pin inodes in core and to detect when watched inodes are deleted or unmounted. This patch uses fsnotify instead of inotify.
Signed-off-by Eric Paris <[email protected]>
Sorry for being lazy and not googling around, but what changes between inotify and fsnotify, specially in terms of filesystem auditing? Is there any performance/features/usability changes?
Thanks,
-Klaus
Signature · 2 lines
Klaus Heinrich Kiwi <[email protected]> Linux Security Development, IBM Linux Technology Center
Eric Paris
maintainerQuoted 10 lines · Klaus Heinrich Kiwi
Quoted 5 lines · Eric Paris
Audit currently uses inotify to pin inodes in core and to detect when watched inodes are deleted or unmounted. This patch uses fsnotify instead of inotify.
Signed-off-by Eric Paris <[email protected]>Sorry for being lazy and not googling around, but what changes between inotify and fsnotify, specially in terms of filesystem auditing? Is there any performance/features/usability changes?
Basically, none. fsnotify is a new infrastructure on which inotify and dnotify have been implemented. It is generic, much like the inotify.c (as opposed to inotify_user.c) was supposed to be. But fsnotify is more generic and better thought out.
The main drivers for fsnotify are:
1. smaller struct inode
2. equal performance (actually slightly better since we don't have to run inotify and dnotify every time)
3. significantly better locking and object lifetime (see how much more simple the audit watch locking gets with fsnotify in the next couple patches?)
Note that audit watches don't use inotify to do any of the actual auditing. They just use inotify to discover the watched files were created or removed. So we weren't using much of the inotify feature set.
So this patch does little but get me one step closing to kicking inotify.c out of the kernel
-Eric
Quoted 4 lines · Eric Paris
Note that audit watches don't use inotify to do any of the actual auditing. They just use inotify to discover the watched files were created or removed. So we weren't using much of the inotify feature set.
Eric,
thanks for the thorough explanation.
It's been a while since I last looked, but the file watches are being audited at the syscall level, right? So inotify/fsnotify is used to associate a filename to an inode when the file is created, or to deassociate when it is removed. Is the rename/mv also covered by those or differently? I remember that moving a file around doesn't invalidate it's rule (the file's inode is still the same), but auditctl -l doesn't follow the name around, for example.
But that's also probably the right thing to do in that case, I'm not sure.
-Klaus
Signature · 2 lines
Klaus Heinrich Kiwi <[email protected]> Linux Security Development, IBM Linux Technology Center
Eric Paris
maintainerQuoted 18 lines · Klaus Heinrich Kiwi
Quoted 4 lines · Eric Paris
Note that audit watches don't use inotify to do any of the actual auditing. They just use inotify to discover the watched files were created or removed. So we weren't using much of the inotify feature set.
Eric,
thanks for the thorough explanation.
It's been a while since I last looked, but the file watches are being audited at the syscall level, right? So inotify/fsnotify is used to associate a filename to an inode when the file is created, or to deassociate when it is removed. Is the rename/mv also covered by those or differently? I remember that moving a file around doesn't invalidate it's rule (the file's inode is still the same), but auditctl -l doesn't follow the name around, for example.
Quoted 2 lines
But that's also probably the right thing to do in that case, I'm not sure.
So fsnotify and inotify are the same in these regards. Basically a watch is really on a "directory inode + a name" it's easiest to explain what goes on in examples.
-F path=/tmp/dir1/file1 so the inotify/fsnotify watch is attached to the /tmp/dir1 inode. We also maintain that what we care about is "file1"
If you mv /tmp/dir1 to /tmp/dir2 the rule is deleted from the system (and an audit config change record is written in the logs)
If instead you create /tmp/dir1/file1 we get a notification, update the lists with the new inode number for /tmp/dir1/file1 and at syscall exit will output a record if the /tmp/dir1/file1 was accessed.
If you delete /tmp/dir1/file1 or move it to /tmp/dir1/file2 we will update the lists with the fact that there is no inode
for /tmp/dir1/file1 and so when a syscall exits it will not obviously not find that it needs to output a record.
So we handle add/remove/mv of the actual file of a watch as would be expected. If the file this syscall accessed was called [blah] at syscall exit we will emit a watch. If the file wasn't called [blah] we won't. The only thing interested is removing or moving the parent directory, which actually removes the whole rule never to return.
-Eric