Skip to content

Commit 5598890

Browse files
committed
FIXME: building errors and warnings resolved for v6.8
Signed-off-by: shenping.matt <shenping.matt@bytedance.com>
1 parent 898122a commit 5598890

File tree

6 files changed

+409
-451
lines changed

6 files changed

+409
-451
lines changed

driver/LKM/include/util.h

Lines changed: 8 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#define NAME_TOO_LONG "-4"
2727
#define PID_TREE_MATEDATA_LEN 32
2828

29-
static unsigned int ROOT_PID_NS_INUM;
30-
3129
/*
3230
* macro definitions for legacy kernels
3331
*/
@@ -55,34 +53,12 @@ static unsigned int ROOT_PID_NS_INUM;
5553
*/
5654
extern unsigned long smith_kallsyms_lookup_name(const char *);
5755

58-
extern char *__dentry_path(struct dentry *dentry, char *buf, int buflen);
56+
extern char *smith_dentry_path(struct dentry *dentry, char *buf, int buflen);
5957

6058
extern u8 *smith_query_sb_uuid(struct super_block *sb);
6159

6260
extern uint64_t hash_murmur_OAAT64(char *s, int len);
6361

64-
static struct task_struct *smith_get_task_struct(struct task_struct *tsk)
65-
{
66-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
67-
if (tsk && refcount_inc_not_zero(&tsk->usage))
68-
#else
69-
if (tsk && atomic_inc_not_zero((atomic_t *)&tsk->usage))
70-
#endif
71-
return tsk;
72-
return NULL;
73-
}
74-
75-
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
76-
extern void (*__smith_put_task_struct)(struct task_struct *t);
77-
static inline void smith_put_task_struct(struct task_struct *t)
78-
{
79-
if (atomic_dec_and_test(&t->usage))
80-
__smith_put_task_struct(t);
81-
}
82-
#else
83-
#define smith_put_task_struct(tsk) put_task_struct(tsk)
84-
#endif
85-
8662
#if defined(KGID_STRUCT_CHECK) && (!defined(KGID_CONFIG_CHECK) || \
8763
(defined(KGID_CONFIG_CHECK) && defined(CONFIG_UIDGID_STRICT_TYPE_CHECKS)))
8864
/* vanilla kernels >= 3.5.0, but ubuntu backported for 3.4 */
@@ -284,80 +260,6 @@ static __always_inline unsigned long __must_check smith_copy_from_user(void *to,
284260
__ret; \
285261
})
286262

287-
static __always_inline char *smith_d_path(const struct path *path, char *buf, int buflen)
288-
{
289-
char *name = DEFAULT_RET_STR;
290-
if (buf) {
291-
name = d_path(path, buf, buflen);
292-
if (IS_ERR(name))
293-
name = NAME_TOO_LONG;
294-
}
295-
return name;
296-
}
297-
298-
/*
299-
* query task's executable image file, with mmap lock avoided, just because
300-
* mmput() could lead resched() (since it's calling might_sleep() interally)
301-
*
302-
* there could be races on mm->exe_file, but we could assure we can always
303-
* get a valid filp or NULL
304-
*/
305-
static inline struct file *smith_get_task_exe_file(struct task_struct *task)
306-
{
307-
struct file *exe = NULL;
308-
309-
/*
310-
* get_task_mm/mmput must be avoided here
311-
*
312-
* mmput would put current task to sleep, which violates kprobe. or
313-
* use mmput_async instead, but it's only available for after 4.7.0
314-
* (and CONFIG_MMU is enabled)
315-
*/
316-
task_lock(task);
317-
if (task->mm && task->mm->exe_file) {
318-
exe = task->mm->exe_file;
319-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
320-
if (!get_file_rcu(exe))
321-
exe = NULL;
322-
#else
323-
/* only inc f_count when it's not 0 to avoid races upon exe_file */
324-
if (!atomic_long_inc_not_zero(&exe->f_count))
325-
exe = NULL;
326-
#endif
327-
}
328-
task_unlock(task);
329-
330-
return exe;
331-
}
332-
333-
// get full path of current task's executable image
334-
static __always_inline char *smith_get_exe_file(char *buffer, int size)
335-
{
336-
char *exe_file_str = DEFAULT_RET_STR;
337-
struct file *exe;
338-
339-
if (!buffer || !current->mm)
340-
return exe_file_str;
341-
342-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0)
343-
/*
344-
* 1) performance improvement for kernels >=4.1: use get_mm_exe_file instead
345-
* get_mm_exe_file internally uses rcu lock (with semaphore locks killed)
346-
* 2) it's safe to directly access current->mm under current's own context
347-
* 3) get_mm_exe_file() is no longer exported after kernel 5.15
348-
*/
349-
exe = get_mm_exe_file(current->mm);
350-
#else
351-
exe = smith_get_task_exe_file(current);
352-
#endif
353-
if (exe) {
354-
exe_file_str = smith_d_path(&exe->f_path, buffer, size);
355-
fput(exe);
356-
}
357-
358-
return exe_file_str;
359-
}
360-
361263
static inline unsigned int __get_sessionid(void) {
362264
unsigned int sessionid = 0;
363265
#ifdef CONFIG_AUDITSYSCALL
@@ -366,32 +268,16 @@ static inline unsigned int __get_sessionid(void) {
366268
return sessionid;
367269
}
368270

369-
static inline void __init_root_pid_ns_inum(void) {
370-
struct pid *pid_struct;
371-
struct task_struct *task;
372-
373-
pid_struct = find_get_pid(1);
374-
task = pid_task(pid_struct,PIDTYPE_PID);
271+
static inline int __get_pgid(void) {
272+
return task_pgrp_nr_ns(current, &init_pid_ns);
273+
}
375274

376-
smith_get_task_struct(task);
377-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
378-
ROOT_PID_NS_INUM = task->nsproxy->pid_ns_for_children->ns.inum;
379-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)
380-
ROOT_PID_NS_INUM = task->nsproxy->pid_ns_for_children->proc_inum;
381-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
382-
ROOT_PID_NS_INUM = task->nsproxy->pid_ns->proc_inum;
383-
#else
384-
/*
385-
* For kernels < 3.8.0, id for pid namespaces isn't defined.
386-
* So here we are using fixed values, no emulating any more,
387-
* previously we were using image file's inode number.
388-
*/
389-
ROOT_PID_NS_INUM = 0xEFFFFFFCU /* PROC_PID_INIT_INO */;
390-
#endif
391-
smith_put_task_struct(task);
392-
put_pid(pid_struct);
275+
static inline int __get_sid(void) {
276+
return task_session_nr_ns(current, &init_pid_ns);
393277
}
394278

279+
extern unsigned int ROOT_PID_NS_INUM;
280+
395281
static inline unsigned int __get_pid_ns_inum(void) {
396282
unsigned int inum;
397283
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
@@ -411,12 +297,4 @@ static inline unsigned int __get_pid_ns_inum(void) {
411297
return inum;
412298
}
413299

414-
static inline int __get_pgid(void) {
415-
return task_pgrp_nr_ns(current, &init_pid_ns);
416-
}
417-
418-
static inline int __get_sid(void) {
419-
return task_session_nr_ns(current, &init_pid_ns);
420-
}
421-
422300
#endif /* UTIL_H */

driver/LKM/src/filter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ static struct class *filter_class;
2727
static int filter_major;
2828
static char *sh_mem = NULL;
2929

30-
struct rb_root execve_exe_allowlist = RB_ROOT;
31-
32-
struct rb_root execve_argv_allowlist = RB_ROOT;
30+
static struct rb_root execve_exe_allowlist = RB_ROOT;
31+
static struct rb_root execve_argv_allowlist = RB_ROOT;
3332

3433
static int execve_exe_allowlist_limit = 0;
3534

0 commit comments

Comments
 (0)