Skip to content

Commit 92d0574

Browse files
deepskyblue86jcpittman144
authored andcommitted
fix(kmod): safer ppm_get_mm_exe_file
Leverage `get_file_rcu` being a define to use the safer version of `get_mm_exe_file`. This will allow kernel versions prior to 4.1, but with the fix being backported don't suffer RCU violations. Co-authored-by: Joseph Pittman <[email protected]> Signed-off-by: Angelo Puglisi <[email protected]>
1 parent bd2f9d3 commit 92d0574

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

driver/ppm_fillers.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,18 @@ int f_sys_write_x(struct event_filler_arguments *args)
579579
/*
580580
* get_mm_exe_file is only exported in some kernel versions
581581
*/
582-
583582
struct file *ppm_get_mm_exe_file(struct mm_struct *mm)
584583
{
585584
struct file *exe_file;
586585

587-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
586+
/*
587+
* The following if/else preprocessor directive is to cover for that change:
588+
* https://github.com/torvalds/linux/commit/90f31d0ea88880f780574f3d0bb1a227c4c66ca3#diff-e37b5cb4c23f6ab27741c60ec48674eff0268624a228c9a1cddddb9e4ee2922dL709
589+
* That was introduced in linux 4.1, but it's backported in some distro kernels.
590+
* Luckily enough, `get_file_rcu` is a define, so we can check for it and use
591+
* the safer version.
592+
*/
593+
#if defined(get_file_rcu)
588594
rcu_read_lock();
589595
exe_file = rcu_dereference(mm->exe_file);
590596
if (exe_file && !get_file_rcu(exe_file))

0 commit comments

Comments
 (0)