/
var
/
lib
/
dkms
/
file_protector
/
1.1-1507
/
source
/
File Upload :
llllll
Current File: //var/lib/dkms/file_protector/1.1-1507/source/compat.h
/** @file @brief Support for legacy Linux kernel versions @details Copyright (c) 2018-2021 Acronis International GmbH @author Mikhail Krivtsov (mikhail.krivtsov@acronis.com) @since $Id: $ */ #pragma once #include <linux/cred.h> // current_fsuid_fsgid #include <linux/file.h> #include <linux/fs.h> // vfs_stat #include <linux/mount.h> #include <linux/version.h> #include <linux/namei.h> #include <linux/mm.h> // CentOS/RedHat kernel has many backports // 'LINUX_VERSION_CODE' cannot be trusted on RHEL distros so only 'grep' is used for CentOS and CloudLinux // For 'normal kernels', 'LINUX_VERSION_CODE' should be used #ifndef RHEL_RELEASE_VERSION // 'linux/sched/task.h' appeared in 'stable/v4.11' #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) # ifdef HAVE_SCHED_TASK_H # undef HAVE_SCHED_TASK_H # endif # ifndef HAVE_SCHED_H # define HAVE_SCHED_H # endif #else # ifndef HAVE_SCHED_TASK_H # define HAVE_SCHED_TASK_H # endif # ifdef HAVE_SCHED_H # undef HAVE_SCHED_H # endif #endif // 'get_fs_pwd()' appeared in 'stable/v2.6.36' #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) # ifdef HAVE_GET_FS_ROOT # undef HAVE_GET_FS_ROOT # endif #else # ifndef HAVE_GET_FS_ROOT # define HAVE_GET_FS_ROOT # endif #endif // Second arg of 'vfs_fstatat()' was made 'const' in 'stable/v2.6.36' #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) # ifdef HAVE_VFS_FSTATAT_CONST # undef HAVE_VFS_FSTATAT_CONST # endif #else # ifndef HAVE_VFS_FSTATAT_CONST # define HAVE_VFS_FSTATAT_CONST # endif #endif // 'get_task_exe_file()' appeared in 'stable/v4.8' #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0) # ifdef HAVE_GET_TASK_EXE # undef HAVE_GET_TASK_EXE # endif #else # ifndef HAVE_GET_TASK_EXE # define HAVE_GET_TASK_EXE # endif #endif // 'data' arg was added to 'probe' callback in v.2.6.35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) # ifdef HAVE_TRACEPOINT_PROBE_REGISTER_DATA # undef HAVE_TRACEPOINT_PROBE_REGISTER_DATA # endif #else # ifndef HAVE_TRACEPOINT_PROBE_REGISTER_DATA # define HAVE_TRACEPOINT_PROBE_REGISTER_DATA # endif // registration interface was modified in 'stable/v3.15' # if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0) # ifdef HAVE_TRACEPOINT_PROBE_REGISTER_STRUCT # undef HAVE_TRACEPOINT_PROBE_REGISTER_STRUCT # endif # else # ifndef HAVE_TRACEPOINT_PROBE_REGISTER_STRUCT # define HAVE_TRACEPOINT_PROBE_REGISTER_STRUCT # endif # endif #endif // rbtree postorder iteration functions appeared in 'stable/v3.12' #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0) # ifdef HAVE_RB_FIRST_POSTORDER # undef HAVE_RB_FIRST_POSTORDER # endif # ifdef HAVE_RB_NEXT_POSTORDER # undef HAVE_RB_NEXT_POSTORDER # endif #else # ifndef HAVE_RB_FIRST_POSTORDER # define HAVE_RB_FIRST_POSTORDER # endif # ifndef HAVE_RB_NEXT_POSTORDER # define HAVE_RB_NEXT_POSTORDER # endif #endif // kuid/kgid is used instead uid/gid since 'stable/v3.5.0' #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) # ifdef HAVE_STRUCT_CRED_KUID # undef HAVE_STRUCT_CRED_KUID # endif #else # ifndef HAVE_STRUCT_CRED_KUID # define HAVE_STRUCT_CRED_KUID # endif #endif #endif #ifdef HAVE_SCHED_H #include <linux/sched.h> // put_task_struct() #endif #ifdef HAVE_SCHED_TASK_H #include <linux/sched/task.h> // put_task_struct() #endif #ifndef HAVE_GET_FS_ROOT #include <linux/fs_struct.h> #include <linux/path.h> static inline void get_fs_root(struct fs_struct *fs, struct path *root) { read_lock(&fs->lock); *root = fs->root; path_get(root); read_unlock(&fs->lock); } #endif static inline struct inode *file_inode_compat(const struct file *f) { return f->f_path.dentry->d_inode; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) #define GET_TASK_EXE_NOT_EXPORTED #endif #if !defined(HAVE_GET_TASK_EXE) || defined(GET_TASK_EXE_NOT_EXPORTED) struct file *get_task_exe_file_impl(struct task_struct *task); #endif #ifndef HAVE_PATH_EQUAL static inline int path_equal(const struct path *path1, const struct path *path2) { return path1->mnt == path2->mnt && path1->dentry == path2->dentry; } #endif #define TRACE_CB_NAME(name) trace_##name##_cb #ifndef HAVE_TRACEPOINT_PROBE_REGISTER_DATA #define REGISTER_TRACE(name, probe) register_trace_##name(probe) #define UNREGISTER_TRACE(name, probe) unregister_trace_##name(probe) #define TRACE_CB_PROTO(name, proto) void TRACE_CB_NAME(name)(PARAMS(proto)) #else #ifndef HAVE_TRACEPOINT_PROBE_REGISTER_STRUCT #define REGISTER_TRACE(name, probe) register_trace_##name(probe, NULL) #define UNREGISTER_TRACE(name, probe) unregister_trace_##name(probe, NULL) #else int tracepoint_probe_register_compat(const char *name, void *probe, void *data); #define REGISTER_TRACE(name, probe) \ tracepoint_probe_register_compat(#name, probe, NULL) int tracepoint_probe_unregister_compat(const char *name, void *probe, void *data); #define UNREGISTER_TRACE(name, probe) \ tracepoint_probe_unregister_compat(#name, probe, NULL) #endif #define TRACE_CB_PROTO(name, proto) \ void TRACE_CB_NAME(name)(void *cb_data, PARAMS(proto)) #endif #ifndef HAVE_RB_FIRST_POSTORDER #include <linux/rbtree.h> extern struct rb_node *rb_first_postorder(const struct rb_root *); #endif #ifndef HAVE_RB_NEXT_POSTORDER #include <linux/rbtree.h> extern struct rb_node *rb_next_postorder(const struct rb_node *); #endif static inline void get_current_fsuid_fsgid_compat(uid_t* fsuid, gid_t* fsgid) { #ifndef HAVE_STRUCT_CRED_KUID current_fsuid_fsgid(fsuid, fsgid); #else kuid_t fskuid; kgid_t fskgid; current_fsuid_fsgid(&fskuid, &fskgid); *fsuid = fskuid.val; *fsgid = fskgid.val; #endif } static inline struct file* dentry_open_compat(const struct path* path, int flags) { #ifndef HAVE_PATH_IN_DENTRY_OPEN return dentry_open(dget(path->dentry), mntget(path->mnt), flags, current_cred()); #else return dentry_open(path, flags, current_cred()); #endif } static inline int get_unused_fd_compat(void) { #ifdef HAVE_UNUSED_FD_FLAGS return get_unused_fd_flags(0); #else return get_unused_fd(); #endif } /* 2.6.32-71.el6 unsigned int module_refcount(struct module *mod) linux-3.10.0-123.el7 unsigned long module_refcount(struct module *mod) */ #define module_refcount_compat(m) ((unsigned long)module_refcount(m)) static inline struct file *get_task_exe_file_compat(struct task_struct *task) { #if !defined(HAVE_GET_TASK_EXE) || defined(GET_TASK_EXE_NOT_EXPORTED) return get_task_exe_file_impl(task); #else return get_task_exe_file(task); #endif } int get_kallsyms_on_each_symbol(void); unsigned long compat_kallsyms_lookup_name(const char *name); #ifndef HAVE_FDGET // Backport 'struct fd' to old kernels // Sadly 'fget_light' is not exported so just use 'fget' instead struct compat_fd { struct file *file; }; static inline struct compat_fd compat_fdget(unsigned int fd) { return (struct compat_fd){ fget(fd) }; } static inline void compat_fdput(struct compat_fd fd) { fput(fd.file); } #else #define compat_fd fd #define compat_fdput fdput #define compat_fdget fdget #endif
Copyright ©2k19 -
Hexid
|
Tex7ure