From 4713550a59d9f8845335e6fc085e0fba300f62a6 Mon Sep 17 00:00:00 2001 From: litao Date: Mon, 20 May 2024 15:02:36 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add vendor hook for nanosleep syscall Through this vendor hook, we can get the timing to check current running task for the validation of its credential and nanosleep operations. through this we can filter some app tasks which may fire the nanosleep events storm. Bug: 396244637 Bug: 341618050 Change-Id: I644ac3d217930aa0a50966996e8001e27ce8a501 Signed-off-by: litao (cherry picked from commit 1d9ed15534d4988da3ac56dd7892d37bf5f96847) --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/syscall_check.h | 6 ++++++ kernel/time/hrtimer.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index a426b7c7e6b5..b140bc5bcfd9 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -188,6 +188,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gic_set_affinity); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dc_send_copy); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dc_receive); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_bpf_syscall); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_nanosleep_syscall); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rproc_recovery); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rproc_recovery_set); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_timer_calc_index); diff --git a/include/trace/hooks/syscall_check.h b/include/trace/hooks/syscall_check.h index 56d8267297ca..4710700b0108 100644 --- a/include/trace/hooks/syscall_check.h +++ b/include/trace/hooks/syscall_check.h @@ -12,6 +12,8 @@ */ struct file; union bpf_attr; +struct timespec64; + DECLARE_HOOK(android_vh_check_mmap_file, TP_PROTO(const struct file *file, unsigned long prot, unsigned long flag, unsigned long ret), @@ -25,6 +27,10 @@ DECLARE_HOOK(android_vh_check_bpf_syscall, TP_PROTO(int cmd, const union bpf_attr *attr, unsigned int size), TP_ARGS(cmd, attr, size)); +DECLARE_HOOK(android_vh_check_nanosleep_syscall, + TP_PROTO(struct timespec64 *tu), + TP_ARGS(tu)); + #endif /* _TRACE_HOOK_SYSCALL_CHECK_H */ /* This part must be outside protection */ #include diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 8890c8313f68..8f1ccc0f0a1e 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -46,6 +46,7 @@ #include #include +#include #include "tick-internal.h" @@ -2173,6 +2174,7 @@ SYSCALL_DEFINE2(nanosleep, struct __kernel_timespec __user *, rqtp, if (!timespec64_valid(&tu)) return -EINVAL; + trace_android_vh_check_nanosleep_syscall(&tu); current->restart_block.fn = do_no_restart_syscall; current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; current->restart_block.nanosleep.rmtp = rmtp; @@ -2195,6 +2197,7 @@ SYSCALL_DEFINE2(nanosleep_time32, struct old_timespec32 __user *, rqtp, if (!timespec64_valid(&tu)) return -EINVAL; + trace_android_vh_check_nanosleep_syscall(&tu); current->restart_block.fn = do_no_restart_syscall; current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; current->restart_block.nanosleep.compat_rmtp = rmtp;