Skip to content

Commit 4ce1400

Browse files
committed
Report unexpected off flag depths
This is useful for debugging while hopefully not too revealing for attacks. Fixes #424
1 parent c8853a9 commit 4ce1400

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/modules/exploit_detection/p_exploit_detection.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,30 @@ static notrace void p_debug_off_flag_dump_ring_buffer(struct p_ed_process *p_sou
817817
}
818818
#endif
819819

820+
static inline int p_off_depth(long *p_val) {
821+
822+
int p_depth = 0;
823+
824+
while (*p_val > p_global_cnt_cookie) {
825+
*p_val -= p_global_cnt_cookie;
826+
p_depth++;
827+
if (unlikely(*p_val > (p_global_cnt_cookie << 3)))
828+
break;
829+
}
830+
831+
return p_depth;
832+
}
833+
820834
static inline void p_ed_is_off_off(struct p_ed_process *p_source, long p_val, int *p_ret) {
821835

822836
if (unlikely(p_val != p_global_cnt_cookie)) {
823-
p_print_log(P_LOG_ALERT, "DETECT: Task: unexpected 'off' flag for pid %u, name %s",
824-
p_source->p_ed_task.p_pid, p_source->p_ed_task.p_comm);
837+
long p_val_remainder = p_val;
838+
int p_depth = p_off_depth(&p_val_remainder);
839+
if (p_val_remainder != p_global_cnt_cookie)
840+
p_depth = p_val ? 0 : -1;
841+
/* Depths -1 or 1+ are exact, 0 means non-multiple or out of range */
842+
p_print_log(P_LOG_ALERT, "DETECT: Task: unexpected 'off' flag depth %d for pid %u, name %s",
843+
p_depth, p_source->p_ed_task.p_pid, p_source->p_ed_task.p_comm);
825844
#ifdef P_LKRG_TASK_OFF_DEBUG
826845
p_print_log(P_LOG_WATCH, "'off' flag[0x%lx] (normalization via 0x%lx)",
827846
p_val, p_global_cnt_cookie);
@@ -844,11 +863,7 @@ static inline void p_validate_off_flag(struct p_ed_process *p_source, long p_val
844863
if (likely(p_val == p_global_cnt_cookie))
845864
return;
846865

847-
while (p_val > p_global_cnt_cookie) {
848-
p_val -= p_global_cnt_cookie;
849-
if (unlikely(p_val > (p_global_cnt_cookie << 3)))
850-
break;
851-
}
866+
p_off_depth(&p_val);
852867

853868
p_ed_is_off_off(p_source, p_val, p_ret);
854869
}

0 commit comments

Comments
 (0)