From aaae5b9d621bd28f26ab4351588f683379b8b3f0 Mon Sep 17 00:00:00 2001 From: huzhanyuan Date: Tue, 2 Jul 2024 17:19:21 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hook for fsnotify Add hook for fsnotify when file open with write mode. - android_vh_fsnotify_open Bug: 350651631 Change-Id: Ibeada7ce1d5a4a78c49b9a255b1e3a436029b631 Signed-off-by: huzhanyuan Signed-off-by: wengle --- drivers/android/vendor_hooks.c | 2 ++ include/linux/fsnotify.h | 4 ++++ include/trace/hooks/fsnotify.h | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 include/trace/hooks/fsnotify.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 39f651ca61c7..f7af28d625bd 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -69,6 +69,7 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event @@ -466,3 +467,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_alloc_pages_reclaim_cycle_end); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_bd_link_disk_holder); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_new_ref); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_del_ref); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_fsnotify_open); diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 9161264db36c..712f285d7bb7 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -17,6 +17,9 @@ #include #include +#undef CREATE_TRACE_POINTS +#include + /* Are there any inode/mount/sb objects watched with priority prio or above? */ static inline bool fsnotify_sb_has_priority_watchers(struct super_block *sb, int prio) @@ -423,6 +426,7 @@ static inline void fsnotify_open(struct file *file) if (file->f_flags & __FMODE_EXEC) mask |= FS_OPEN_EXEC; + trace_android_vh_fsnotify_open(file, &mask); fsnotify_file(file, mask); } diff --git a/include/trace/hooks/fsnotify.h b/include/trace/hooks/fsnotify.h new file mode 100644 index 000000000000..2909261c3358 --- /dev/null +++ b/include/trace/hooks/fsnotify.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM fsnotify + +#ifdef CREATE_TRACE_POINTS +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH trace/hooks +#define UNDEF_TRACE_INCLUDE_PATH +#endif + +#if !defined(_TRACE_HOOK_FSNOTIFY_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_FSNOTIFY_H + +#include + +DECLARE_HOOK(android_vh_fsnotify_open, + TP_PROTO(struct file *file, __u32 *mask), + TP_ARGS(file, mask)); + +#endif /* _TRACE_HOOK_FSNOTIFY_H */ + +/* This part must be outside protection */ +#include