26
26
#define NAME_TOO_LONG "-4"
27
27
#define PID_TREE_MATEDATA_LEN 32
28
28
29
- static unsigned int ROOT_PID_NS_INUM ;
30
-
31
29
/*
32
30
* macro definitions for legacy kernels
33
31
*/
@@ -55,34 +53,12 @@ static unsigned int ROOT_PID_NS_INUM;
55
53
*/
56
54
extern unsigned long smith_kallsyms_lookup_name (const char * );
57
55
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 );
59
57
60
58
extern u8 * smith_query_sb_uuid (struct super_block * sb );
61
59
62
60
extern uint64_t hash_murmur_OAAT64 (char * s , int len );
63
61
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
-
86
62
#if defined(KGID_STRUCT_CHECK ) && (!defined(KGID_CONFIG_CHECK ) || \
87
63
(defined(KGID_CONFIG_CHECK ) && defined(CONFIG_UIDGID_STRICT_TYPE_CHECKS )))
88
64
/* 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,
284
260
__ret ; \
285
261
})
286
262
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
-
361
263
static inline unsigned int __get_sessionid (void ) {
362
264
unsigned int sessionid = 0 ;
363
265
#ifdef CONFIG_AUDITSYSCALL
@@ -366,32 +268,16 @@ static inline unsigned int __get_sessionid(void) {
366
268
return sessionid ;
367
269
}
368
270
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
+ }
375
274
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 );
393
277
}
394
278
279
+ extern unsigned int ROOT_PID_NS_INUM ;
280
+
395
281
static inline unsigned int __get_pid_ns_inum (void ) {
396
282
unsigned int inum ;
397
283
#if LINUX_VERSION_CODE >= KERNEL_VERSION (3 , 19 , 0 )
@@ -411,12 +297,4 @@ static inline unsigned int __get_pid_ns_inum(void) {
411
297
return inum ;
412
298
}
413
299
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
-
422
300
#endif /* UTIL_H */
0 commit comments