Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(driver): fix potential deadlock #1629

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 24 additions & 8 deletions driver/ppm_fillers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,15 +1391,23 @@ int f_proc_startupdate(struct event_filler_arguments *args)
{
/* Support exe_writable */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
exe_writable |= (file_permission(exe_file, MAY_WRITE) == 0);
exe_writable |= (file_permission(exe_file, MAY_WRITE | MAY_NOT_BLOCK) == 0);
exe_writable |= inode_owner_or_capable(file_mnt_idmap(exe_file), file_inode(exe_file));
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
exe_writable |= (inode_permission(current_user_ns(), file_inode(exe_file), MAY_WRITE) == 0);
exe_writable |= (inode_permission(current_user_ns(), file_inode(exe_file), MAY_WRITE | MAY_NOT_BLOCK) == 0);
exe_writable |= inode_owner_or_capable(current_user_ns(), file_inode(exe_file));
#else
exe_writable |= (inode_permission(file_inode(exe_file), MAY_WRITE) == 0);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
exe_writable |= (inode_permission(file_inode(exe_file), MAY_WRITE | MAY_NOT_BLOCK) == 0);
exe_writable |= inode_owner_or_capable(file_inode(exe_file));
#endif
/*
* Kernels < 3.1.0 doesn't support the exe_writable flags due to the MAY_NOT_BLOCK not being
* available. This limitation is related to the fact that this function (f_sched_prog_exec)
* is in a RCU critical section: this means that this function (and its callee) MUST NOT
* call functions that can yield the processor (e.g. inode_permission that deep down in its
* call stack calls a down_read()). This is addressed after the Kernel 3.1.0 where the
* MAY_OT_BLOCK flag is introduced and avoids the processor to being yield.
*/

/* Support exe_upper_layer */
exe_upper_layer = ppm_is_upper_layer(exe_file);
Expand Down Expand Up @@ -7416,15 +7424,23 @@ int f_sched_prog_exec(struct event_filler_arguments *args)
{
/* Support exe_writable */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
exe_writable |= (file_permission(exe_file, MAY_WRITE) == 0);
exe_writable |= (file_permission(exe_file, MAY_WRITE | MAY_NOT_BLOCK) == 0);
exe_writable |= inode_owner_or_capable(file_mnt_idmap(exe_file), file_inode(exe_file));
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
exe_writable |= (inode_permission(current_user_ns(), file_inode(exe_file), MAY_WRITE) == 0);
exe_writable |= (inode_permission(current_user_ns(), file_inode(exe_file), MAY_WRITE | MAY_NOT_BLOCK) == 0);
exe_writable |= inode_owner_or_capable(current_user_ns(), file_inode(exe_file));
#else
exe_writable |= (inode_permission(file_inode(exe_file), MAY_WRITE) == 0);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
exe_writable |= (inode_permission(file_inode(exe_file), MAY_WRITE | MAY_NOT_BLOCK) == 0);
exe_writable |= inode_owner_or_capable(file_inode(exe_file));
#endif
/*
* Kernels < 3.1.0 doesn't support the exe_writable flags due to the MAY_NOT_BLOCK not being
* available. This limitation is related to the fact that this function (f_sched_prog_exec)
* is in a RCU critical section: this means that this function (and its callee) MUST NOT
* call functions that can yield the processor (e.g. inode_permission that deep down in its
* call stack calls a down_read()). This is addressed after the Kernel 3.1.0 where the
* MAY_OT_BLOCK flag is introduced and avoids the processor to being yield.
*/

/* Support exe_upper_layer */
exe_upper_layer = ppm_is_upper_layer(exe_file);
Expand Down