kernelsu: pkg_observer: Add backward compatibility
Co-authored-by: TwinbornPlate75 <42514046+TwinbornPlate75@users.noreply.github.com> Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/namei.h>
|
||||
#include <linux/fsnotify_backend.h>
|
||||
#include <linux/fsnotify.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/rculist.h>
|
||||
#include <linux/version.h>
|
||||
#include "klog.h" // IWYU pragma: keep
|
||||
@@ -21,16 +22,14 @@ struct watch_dir {
|
||||
|
||||
static struct fsnotify_group *g;
|
||||
|
||||
static int ksu_handle_inode_event(struct fsnotify_mark *mark, u32 mask,
|
||||
struct inode *inode, struct inode *dir,
|
||||
const struct qstr *file_name, u32 cookie)
|
||||
#include "pkg_observer_defs.h" // KSU_DECL_FSNOTIFY_OPS
|
||||
static KSU_DECL_FSNOTIFY_OPS(ksu_handle_generic_event)
|
||||
{
|
||||
if (!file_name)
|
||||
if (!file_name || (mask & FS_ISDIR))
|
||||
return 0;
|
||||
if (mask & FS_ISDIR)
|
||||
return 0;
|
||||
if (file_name->len == 13 &&
|
||||
!memcmp(file_name->name, "packages.list", 13)) {
|
||||
|
||||
if (ksu_fname_len(file_name) == 13 &&
|
||||
!memcmp(ksu_fname_arg(file_name), "packages.list", 13)) {
|
||||
pr_info("packages.list detected: %d\n", mask);
|
||||
track_throne();
|
||||
}
|
||||
@@ -38,25 +37,49 @@ static int ksu_handle_inode_event(struct fsnotify_mark *mark, u32 mask,
|
||||
}
|
||||
|
||||
static const struct fsnotify_ops ksu_ops = {
|
||||
.handle_inode_event = ksu_handle_inode_event,
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
|
||||
.handle_inode_event = ksu_handle_generic_event,
|
||||
#else
|
||||
.handle_event = ksu_handle_generic_event,
|
||||
#endif
|
||||
};
|
||||
|
||||
static void __maybe_unused m_free(struct fsnotify_mark *m)
|
||||
{
|
||||
if (m) {
|
||||
kfree(m);
|
||||
}
|
||||
}
|
||||
|
||||
static int add_mark_on_inode(struct inode *inode, u32 mask,
|
||||
struct fsnotify_mark **out)
|
||||
{
|
||||
struct fsnotify_mark *m;
|
||||
int ret;
|
||||
|
||||
m = kzalloc(sizeof(*m), GFP_KERNEL);
|
||||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
|
||||
fsnotify_init_mark(m, m_free);
|
||||
m->mask = mask;
|
||||
ret = fsnotify_add_mark(m, g, inode, NULL, 0);
|
||||
#else
|
||||
fsnotify_init_mark(m, g);
|
||||
m->mask = mask;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
|
||||
ret = fsnotify_add_inode_mark(m, inode, 0);
|
||||
#else
|
||||
ret = fsnotify_add_mark(m, inode, NULL, 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (fsnotify_add_inode_mark(m, inode, 0)) {
|
||||
if (ret < 0) {
|
||||
fsnotify_put_mark(m);
|
||||
return -EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
*out = m;
|
||||
return 0;
|
||||
}
|
||||
@@ -116,7 +139,7 @@ int ksu_observer_init(void)
|
||||
return PTR_ERR(g);
|
||||
|
||||
ret = watch_one_dir(&g_watch);
|
||||
pr_info("observer init done\n");
|
||||
pr_info("%s done.\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -124,5 +147,5 @@ void ksu_observer_exit(void)
|
||||
{
|
||||
unwatch_one_dir(&g_watch);
|
||||
fsnotify_put_group(g);
|
||||
pr_info("observer exit done\n");
|
||||
pr_info("%s: done.\n", __func__);
|
||||
}
|
||||
|
||||
42
drivers/kernelsu/pkg_observer_defs.h
Normal file
42
drivers/kernelsu/pkg_observer_defs.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// This header should not be used outside of pkg_observer.c!
|
||||
|
||||
#include <linux/version.h>
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
|
||||
typedef const struct qstr *ksu_fname_t;
|
||||
#define ksu_fname_len(f) ((f)->len)
|
||||
#define ksu_fname_arg(f) ((f)->name)
|
||||
#else
|
||||
typedef const unsigned char *ksu_fname_t;
|
||||
#define ksu_fname_len(f) (strlen(f))
|
||||
#define ksu_fname_arg(f) (f)
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
|
||||
#define KSU_DECL_FSNOTIFY_OPS(name) \
|
||||
int name(struct fsnotify_mark *mark, u32 mask, struct inode *inode, \
|
||||
struct inode *dir, const struct qstr *file_name, u32 cookie)
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
|
||||
#define KSU_DECL_FSNOTIFY_OPS(name) \
|
||||
int name(struct fsnotify_group *group, struct inode *inode, u32 mask, \
|
||||
const void *data, int data_type, ksu_fname_t file_name, \
|
||||
u32 cookie, struct fsnotify_iter_info *iter_info)
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
|
||||
#define KSU_DECL_FSNOTIFY_OPS(name) \
|
||||
int name(struct fsnotify_group *group, struct inode *inode, u32 mask, \
|
||||
const void *data, int data_type, ksu_fname_t file_name, \
|
||||
u32 cookie, struct fsnotify_iter_info *iter_info)
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
||||
#define KSU_DECL_FSNOTIFY_OPS(name) \
|
||||
int name(struct fsnotify_group *group, struct inode *inode, \
|
||||
struct fsnotify_mark *inode_mark, \
|
||||
struct fsnotify_mark *vfsmount_mark, u32 mask, \
|
||||
const void *data, int data_type, ksu_fname_t file_name, \
|
||||
u32 cookie, struct fsnotify_iter_info *iter_info)
|
||||
#else
|
||||
#define KSU_DECL_FSNOTIFY_OPS(name) \
|
||||
int name(struct fsnotify_group *group, struct inode *inode, \
|
||||
struct fsnotify_mark *inode_mark, \
|
||||
struct fsnotify_mark *vfsmount_mark, u32 mask, void *data, \
|
||||
int data_type, ksu_fname_t file_name, u32 cookie)
|
||||
#endif
|
||||
Reference in New Issue
Block a user