fsnotify,fanotify: adding flag for execution
Subsystems (3)
PATCH 1/1 fsnotify,fanotify: adding flag for execution
From: Jozef Kralik <[email protected]>
Without this patch the fanotify cannot recognize syscalls "open" from "sys_exec" or "uselib". Patch use one bit for flag executed (FS_OPENEXEC) and it's merged with FS_OPEN_PERM, when file try to open with flag FMODE_EXEC (function fsnotify_perm).
Signed-off-by Jozef Kralik <[email protected]>
---
Example:
if (metadata->mask & FAN_OPEN_PERM)
if (metadata->mask & FAN_OPENEXEC)
printf("file was executed");
else
printf("file was opened");Developed & Tested with kernel: 2.6.37-rc4 with patch: patch-v2.6.37-rc4-next-20101201
Diffstat:
fs/notify/fanotify/fanotify.c | 1 + fs/notify/fsnotify.c | 2 +- include/linux/fanotify.h | 4 +++- include/linux/fsnotify.h | 9 ++++++--- include/linux/fsnotify_backend.h | 4 +++- 5 files changed, 14 insertions(+), 6 deletions(-)
Diff:
fs/notify/fanotify/fanotify.c +1 -0
@@ -131,6 +131,7 @@ static int fanotify_handle_event(structBUILD_BUG_ON (FAN_CLOSE_NOWRITE !=FS_CLOSE_NOWRITE );BUILD_BUG_ON (FAN_CLOSE_WRITE !=FS_CLOSE_WRITE );BUILD_BUG_ON (FAN_OPEN !=FS_OPEN ); +BUILD_BUG_ON (FAN_OPENEXEC !=FS_OPENEXEC );BUILD_BUG_ON (FAN_EVENT_ON_CHILD !=FS_EVENT_ON_CHILD );BUILD_BUG_ON (FAN_Q_OVERFLOW !=FS_Q_OVERFLOW );BUILD_BUG_ON (FAN_OPEN_PERM !=FS_OPEN_PERM );
fs/notify/fsnotify.c +1 -1
@@ -297,7 +297,7 @@ static __init int fsnotify_init(void) {int ret; -BUG_ON (hweight32 (ALL_FSNOTIFY_EVENTS ) !=23 ); +BUG_ON (hweight32 (ALL_FSNOTIFY_EVENTS ) !=24 ); ret =init_srcu_struct (&fsnotify_mark_srcu);if (ret)
include/linux/fanotify.h +3 -1
@@ -9,6 +9,7 @@#define FAN_CLOSE_WRITE 0x00000008/* Writtable file closed */ #define FAN_CLOSE_NOWRITE 0x00000010/* Unwrittable file closed */ #define FAN_OPEN 0x00000020/* File was opened */ +#define FAN_OPENEXEC 0x00001000/* File had exec flag */ #define FAN_Q_OVERFLOW 0x00004000/* Event queued overflowed */
@@ -84,7 +85,8 @@#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ FAN_ALL_PERM_EVENTS |\ - FAN_Q_OVERFLOW) + FAN_Q_OVERFLOW |\ + FAN_OPENEXEC)#define FANOTIFY_METADATA_VERSION 2
include/linux/fsnotify_backend.h +3 -1
@@ -36,6 +36,7 @@#define FS_DELETE 0x00000200/* Subfile was deleted */ #define FS_DELETE_SELF 0x00000400/* Self was deleted */ #define FS_MOVE_SELF 0x00000800/* Self was moved */ +#define FS_OPENEXEC 0x00001000/* File had exec flag */ #define FS_UNMOUNT 0x00002000/* inode on umount fs */ #define FS_Q_OVERFLOW 0x00004000/* Event queued overflowed */
@@ -73,7 +74,8 @@FS_UNMOUNT |FS_Q_OVERFLOW |FS_IN_IGNORED | \FS_OPEN_PERM |FS_ACCESS_PERM |FS_EXCL_UNLINK | \FS_ISDIR |FS_IN_ONESHOT |FS_DN_RENAME | \ - FS_DN_MULTISHOT | FS_EVENT_ON_CHILD) +FS_DN_MULTISHOT |FS_EVENT_ON_CHILD | \ + FS_OPENEXEC) struct fsnotify_group;struct fsnotify_event ;
include/linux/fsnotify.h +6 -3
@@ -46,12 +46,15 @@ static inline int fsnotify_perm(struct freturn 0 ;if (!(mask & (MAY_READ |MAY_OPEN )))return 0 ; -if (mask &MAY_OPEN ) +if (mask &MAY_OPEN ) { fsnotify_mask =FS_OPEN_PERM ; -else if (mask &MAY_READ ) +if (file->f_flags &FMODE_EXEC ) + fsnotify_mask |=FS_OPENEXEC ; + }else if (mask &MAY_READ ) { fsnotify_mask =FS_ACCESS_PERM ; -else + }else {BUG (); + } ret =fsnotify_parent (path,NULL , fsnotify_mask);if (ret)