Skip to content

Commit da5fbaa

Browse files
Kyriakos IspoglouTreehugger Robot
authored andcommitted
ANDROID: SPED: Add vendor hooks in Scheduler
SPED (Scheduler-based Privilege Elevation Detection) a Kernel protection that blocks privilege elevation attacks. Before scheduling a task for execution, it checks if there is a transition to uid/euid 0 (root) and if so, it blocks the execution. We need to register 3 vendor hooks: * When a task is created in copy_process() * Before a task is selected for execution in __pick_next_task() * When a task is terminated in __put_task_struct() The rationale on why we are using these functions can be found in the "Understanding the Linux Scheduler" tab of go/sped-cookbook NOTE: There is already the trace_task_newtask() hook in copy_process() so we will reuse it for process creation. Therefore we will add only 2 new hooks. 1p: go/hyp-sched-lpe-detection design (detailed): go/sped-bluedoc Bug: 403623944 Test: None Change-Id: Iae0f223488e8c9c5050f69f11d8930ad9b14871f Signed-off-by: Kyriakos Ispoglou <ispo@google.com>
1 parent 315d114 commit da5fbaa

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

include/trace/hooks/sched.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ DECLARE_HOOK(android_vh_dump_dl_server,
539539
TP_PROTO(struct sched_dl_entity *dl_se, struct task_struct *p),
540540
TP_ARGS(dl_se, p));
541541

542+
DECLARE_HOOK(android_vh_chk_task,
543+
TP_PROTO(struct task_struct **pp, struct rq *rq),
544+
TP_ARGS(pp, rq));
545+
546+
DECLARE_HOOK(android_vh_put_task,
547+
TP_PROTO(struct task_struct *p),
548+
TP_ARGS(p));
549+
542550
/* macro versions of hooks are no longer required */
543551

544552
#endif /* _TRACE_HOOK_SCHED_H */

kernel/fork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ void __put_task_struct(struct task_struct *tsk)
962962
WARN_ON(refcount_read(&tsk->usage));
963963
WARN_ON(tsk == current);
964964

965+
trace_android_vh_put_task(tsk);
965966
sched_ext_free(tsk);
966967
io_uring_free(tsk);
967968
cgroup_free(tsk);

kernel/sched/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6606,6 +6606,8 @@ __pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
66066606
if (unlikely(p == RETRY_TASK))
66076607
goto restart;
66086608

6609+
trace_android_vh_chk_task(&p, rq);
6610+
66096611
/* Assume the next prioritized class is idle_sched_class */
66106612
if (!p) {
66116613
p = pick_task_idle(rq);
@@ -6621,10 +6623,12 @@ __pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
66216623
for_each_active_class(class) {
66226624
if (class->pick_next_task) {
66236625
p = class->pick_next_task(rq, prev);
6626+
trace_android_vh_chk_task(&p, rq);
66246627
if (p)
66256628
return p;
66266629
} else {
66276630
p = class->pick_task(rq);
6631+
trace_android_vh_chk_task(&p, rq);
66286632
if (p) {
66296633
put_prev_set_next_task(rq, prev, p);
66306634
return p;

kernel/sched/vendor_hooks.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_util_fits_cpu);
138138
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_before_pick_task_fair);
139139
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_balance_fair);
140140
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dump_dl_server);
141+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_chk_task);
142+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_put_task);

0 commit comments

Comments
 (0)