| @@ -2,6 +2,10 @@ | |||||
| /o6h-memory-guard | /o6h-memory-guard | ||||
| /test-guard | /test-guard | ||||
| /test-runtime | /test-runtime | ||||
| /test-validation | |||||
| /test-prepare | |||||
| /test-sanitize-prepare | |||||
| /test-sanitize-validation | |||||
| /test-sanitize-guard | /test-sanitize-guard | ||||
| /test-sanitize-runtime | /test-sanitize-runtime | ||||
| *.o | *.o | ||||
| @@ -1,5 +1,23 @@ | |||||
| # Changelog | # Changelog | ||||
| ## 1.0.8 — 2026-09-23 — Bounded preparation and exact syscall results | |||||
| - Auditado FLOOR486: v1.0.7 usa write(PCKILL), repite validación y puede devolver | |||||
| EAGAIN antes de señalizar. La causa histórica sigue sin quedar probada. | |||||
| - Preparación en 16 trabajadores fijos; espera 250/100/50 ms para | |||||
| CRITICAL/EMERGENCY/FLOOR y fallback por caché. Trabajos abandonados nunca | |||||
| señalizan; limpieza y cierre permanecen en el trabajador. | |||||
| - Eliminada segunda validación de identidad y muestreo completo anterior a PCKILL; | |||||
| el trabajador sólo refresca freemem con kstat propio. | |||||
| - Captura inmediata de errno tras write, retorno en bytes, errno_name, attempted | |||||
| y syscall/operación explícitos; sin timestamps fabricados. | |||||
| - Instrumentación por subpasos, rechazos y resultados tardíos descartados. | |||||
| Dispatch mide decisión → retorno, incluyendo validación y syscall, sin logging. | |||||
| - Fixture FLOOR486, tests de errno, espera real 1283 ms, saturación del pool y | |||||
| pruebas del código nativo con I/O simulado. | |||||
| - PASS real del aislamiento del logger; ranking, política, thresholds, budgets, | |||||
| warmup, allow/protect y dry-run conservados. Source-only, sin despliegue. | |||||
| ## 1.0.7 — 2026-09-22 — Non-blocking panic32 rescue path | ## 1.0.7 — 2026-09-22 — Non-blocking panic32 rescue path | ||||
| - Reordenada toda acción real a validación O(1), señal, actualización en memoria | - Reordenada toda acción real a validación O(1), señal, actualización en memoria | ||||
| @@ -789,3 +789,25 @@ descartarse sólo por edad. Se conservan thresholds, ranking y budgets. | |||||
| La evidencia confirmada, las hipótesis aún abiertas y el fixture están en | La evidencia confirmada, las hipótesis aún abiertas y el fixture están en | ||||
| `INCIDENT_PAGEOUT_DEADMAN_PANIC32_2026_09_22.md` y | `INCIDENT_PAGEOUT_DEADMAN_PANIC32_2026_09_22.md` y | ||||
| `tests/fixtures/panic32_daemon_stall_2026_09_22.csv`. | `tests/fixtures/panic32_daemon_stall_2026_09_22.csv`. | ||||
| ## 21. Addendum v1.0.8 — FLOOR486, preparación acotada y errno | |||||
| El 2026-09-23 se observaron 486 páginas libres, nscan=1548386, salto | |||||
| NORMAL→EMERGENCY, validación de 1283,513 ms y SIGKILL failed errno=11. | |||||
| clamd PID17321 siguió vivo; la memoria se recuperó por otra vía, sin panic. | |||||
| Las escrituras de log de hasta 6655 ms no bloquearon de igual modo rescate: | |||||
| PASS real del aislamiento del logger. No se cambian ranking ni políticas. | |||||
| La auditoría confirma transporte write(PCKILL) y una salida EAGAIN anterior | |||||
| a la syscall por recuperación/error de muestra. v1.0.7 inventaba timestamps | |||||
| cuando no existían, así que la traza no prueba un fallo de kill(2). | |||||
| v1.0.8 captura errno inmediatamente y separa rechazos de resultados reales. | |||||
| Preparación única en 16 trabajadores fijos; espera de 250/100/50 ms, abandono | |||||
| y fallback. Los trabajadores nunca señalizan; resultados tardíos se descartan. | |||||
| Freemem se comprueba sin ARC/swap/CPU, con kstat independiente. Se instrumentan | |||||
| subpasos y se mantienen descriptor anclado, PID/inicio/UUID/generación/protecciones. | |||||
| Informe: `INCIDENT_FLOOR_KILL_FAILED_2026_09_23.md`. | |||||
| Fixture: `tests/fixtures/floor_free_pages_486_2026_09_23.csv`. | |||||
| La suite añade esperas reales de 1283 ms, saturación, errno y código nativo con | |||||
| I/O simulado. Source-only; validación nativa pendiente, sin despliegue. | |||||
| @@ -0,0 +1,112 @@ | |||||
| # FLOOR y resultado ambiguo de SIGKILL — 2026-09-23 | |||||
| Fuente: traza y observaciones suministradas por el operador para v1.0.7. | |||||
| No se inspeccionó el nodo desde esta tarea ni se enviaron señales reales. | |||||
| ## Evidencia | |||||
| La memoria descendió desde unas 175.000 páginas hasta `free_pages=486`, con | |||||
| `lotsfree=130875`, `desfree=65437`, `minfree=49077`, `nscan=1548386` y `floor=1`. | |||||
| Hubo salto NORMAL → EMERGENCY con PRE-PRESSURE, PRESSURE y CRITICAL omitidos. | |||||
| El candidato rank 1 era `clamd`, PID 17321, UUID | |||||
| `be9a7015-33ae-461b-d4e7-dab81ffc3c26`, alias `sailandfun.bz2`. | |||||
| ```text | |||||
| candidate_age_ms=1000.0 | |||||
| candidate_validate_latency_ms=1283.513 | |||||
| decision_mono=70417.548969 | |||||
| kill_attempt_mono=70418.832630 | |||||
| kill_return_mono=70418.832630 | |||||
| action_dispatch_latency_ms=1283.661 | |||||
| kill_latency_ms=0.000 | |||||
| log_enqueue_latency_ms=0.021 | |||||
| result=failed errno=11 | |||||
| ``` | |||||
| Un segundo después había 214.354 páginas libres y estado RECOVERY. El operador | |||||
| comprobó que el mismo PID y start time seguían vivos: esa recuperación no puede | |||||
| atribuirse al SIGKILL registrado. No hubo panic en esta traza. El scanner estaba | |||||
| degradado. El logger registró escrituras de aproximadamente 1990, 2208, 3162 y | |||||
| 6655 ms sin un bloqueo equivalente del hilo de rescate: PASS real del aislamiento | |||||
| de v1.0.7, dentro de lo observable en esta traza. | |||||
| `clamd` es una víctima potencial grande; los `php-cgi` crecientes pueden explicar | |||||
| el crecimiento explosivo. Selección de víctima y atribución de causa son | |||||
| preguntas diferentes. No se modifica el ranking. | |||||
| ## Confirmado | |||||
| La validación duró aproximadamente 1,28 s, la acción se registró fallida con | |||||
| errno 11, el proceso siguió vivo y el host recuperó memoria por otra vía. | |||||
| El logger asíncrono permaneció aislado. | |||||
| ## Pendiente de demostrar | |||||
| La operación concreta que tardó 1,28 s y el origen exacto de errno 11. | |||||
| El código acota posibilidades; la traza antigua no distingue entre ellas. | |||||
| No se afirma que kill(2) devolviera EAGAIN. | |||||
| ## Call graph exacto de v1.0.7 | |||||
| ```text | |||||
| main → act → platform_sample (refresco completo) → action_plan | |||||
| → platform_signal(real=0) | |||||
| open(/proc/PID) → openat(psinfo) → pread | |||||
| → zone_read [nombre, UNIQID, INITPID] → convert → protecciones → close | |||||
| → platform_signal(real=1) | |||||
| open(/proc/PID) → openat(psinfo) → openat(ctl, O_EXCL) | |||||
| → pread → zone_read → convert → protecciones | |||||
| → platform_sample [system_pages, ARC, swap, CPU/pageout] | |||||
| → si error/muestra antigua/free >= ceiling: errno=EAGAIN; return -1 | |||||
| → write(ctl, {PCKILL, SIGKILL}) | |||||
| → monotime → captura tardía de errno → close | |||||
| → si faltan timestamps, act los rellena con monotime | |||||
| → action_commit → enqueue action_decision/action_result | |||||
| ``` | |||||
| No se llama a kill(2). Se escribe PCKILL en el descriptor de control del proceso. | |||||
| `action_decision` se encolaba después del intento; su timestamp interno marcaba | |||||
| el comienzo de validación. Ambas llamadas repetían I/O de identidad. | |||||
| Una cancelación por recuperación explica EAGAIN con marcas iguales rellenadas | |||||
| por el llamador y es compatible con la recuperación posterior; no es prueba | |||||
| causal. También cabe EAGAIN de `/proc` tras ciertos exec que invalidan | |||||
| descriptores, o contaminación entre write y la captura de errno. | |||||
| [proc(5)](https://smartos.org/man/5/proc) documenta PCKILL e invalidación de | |||||
| descriptores. Se conserva el transporte anclado al descriptor para no introducir | |||||
| una nueva carrera de reutilización del número PID. | |||||
| ## Ruta v1.0.8 | |||||
| ```text | |||||
| act → action_plan → validation_acquire (250/100/50 ms) | |||||
| → trabajador: platform_prepare | |||||
| política → psinfo/ctl anclados → identidad/protecciones | |||||
| → sólo freemem con kstat propio → resultado preparado | |||||
| → deadline: abandonar sin facultad de señalizar → siguiente candidato | |||||
| → resultado válido: platform_dispatch → write(PCKILL) | |||||
| errno=0 → write → saved_errno=errno → reloj | |||||
| → release asíncrono → counters → enqueue | |||||
| ``` | |||||
| Hay 16 trabajadores fijos. Un resultado tardío se descarta y el descriptor se | |||||
| cierra en el trabajador. Un pool agotado falla cerrado con EBUSY; no genera más | |||||
| hilos. No hay pthread_cancel, alarmas ni joins en rescate. O_NONBLOCK por sí solo | |||||
| no garantiza que `/proc` no duerma; el límite lo impone abandonar la espera. | |||||
| `action_result` identifica `syscall=write operation=PCKILL attempted=1`, retorno | |||||
| en bytes, errno exacto y nombre. Dos long completos son éxito. Una escritura | |||||
| parcial es `transport_status=short_write`, errno 0, sin reintento ambiguo. | |||||
| Rechazos llevan `syscall=none attempted=0 errno_origin=validation`; no se | |||||
| inventan marcas de entrada/retorno de una syscall nunca ejecutada. | |||||
| Se miden PID/inicio/zona/generación/política/protecciones/cooldown, open/read/parse, | |||||
| memoria y total. `validation_late_result discarded=1` informa las medidas de una | |||||
| preparación expirada cuando retorna. Un subpaso sin retorno no tiene duración | |||||
| final conocida. Dispatch es decisión → retorno, sin logging; incluye espera, | |||||
| preparación, entrega/planificación y syscall. Kill mide sólo la syscall. | |||||
| Las pruebas inyectan una espera real de 1283 ms y prueban abandono con presupuesto | |||||
| FLOOR y fallback. Userland no pasa a ser tiempo real: desprogramación, muestreo | |||||
| inicial y PCKILL siguen dependiendo del kernel. Se requiere validación nativa | |||||
| SmartOS antes de desplegar. Esta entrega no modifica el nodo ni su configuración. | |||||
| @@ -3,7 +3,7 @@ CC = gcc | |||||
| CPPFLAGS = -D__EXTENSIONS__ -D_POSIX_C_SOURCE=200809L -Isrc | CPPFLAGS = -D__EXTENSIONS__ -D_POSIX_C_SOURCE=200809L -Isrc | ||||
| CFLAGS = -std=c99 -m64 -O2 -Wall -Wextra -Werror -Wformat=2 | CFLAGS = -std=c99 -m64 -O2 -Wall -Wextra -Werror -Wformat=2 | ||||
| LDLIBS = -lkstat -lrt -lpthread | LDLIBS = -lkstat -lrt -lpthread | ||||
| SOURCES = src/main.c src/core.c src/config.c src/support.c src/illumos.c | |||||
| SOURCES = src/main.c src/core.c src/config.c src/support.c src/illumos.c src/validation.c src/result.c src/signal.c | |||||
| TESTFLAGS = -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread | TESTFLAGS = -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread | ||||
| .PHONY: all native-check test test-distribution test-sanitize portability clean | .PHONY: all native-check test test-distribution test-sanitize portability clean | ||||
| @@ -18,21 +18,33 @@ o6h-memory-guard: $(SOURCES) src/guard.h | native-check | |||||
| test-guard: tests/test_guard.c tests/fixtures/pageout_deadman_real_incident_2026_09.csv tests/fixtures/successful_pageout_deadman_avoidance_2026_09_21.csv src/core.c src/config.c src/guard.h | test-guard: tests/test_guard.c tests/fixtures/pageout_deadman_real_incident_2026_09.csv tests/fixtures/successful_pageout_deadman_avoidance_2026_09_21.csv src/core.c src/config.c src/guard.h | ||||
| $(CC) $(TESTFLAGS) -o $@ tests/test_guard.c src/core.c src/config.c | $(CC) $(TESTFLAGS) -o $@ tests/test_guard.c src/core.c src/config.c | ||||
| test-runtime: tests/test_runtime.c tests/fixtures/global_victim_ranking_smartos_2026_09.csv tests/fixtures/panic32_daemon_stall_2026_09_22.csv src/main.c src/core.c src/config.c src/guard.h | |||||
| $(CC) $(TESTFLAGS) -o $@ tests/test_runtime.c src/core.c src/config.c | |||||
| test-runtime: tests/test_runtime.c tests/fixtures/global_victim_ranking_smartos_2026_09.csv tests/fixtures/panic32_daemon_stall_2026_09_22.csv tests/fixtures/floor_free_pages_486_2026_09_23.csv src/main.c src/core.c src/config.c src/result.c src/guard.h | |||||
| $(CC) $(TESTFLAGS) -o $@ tests/test_runtime.c src/core.c src/config.c src/result.c | |||||
| test-distribution: tests/test_distribution.sh smf/o6h-memory-guard.xml etc/o6h-memory-guard.conf src/main.c | test-distribution: tests/test_distribution.sh smf/o6h-memory-guard.xml etc/o6h-memory-guard.conf src/main.c | ||||
| sh tests/test_distribution.sh | sh tests/test_distribution.sh | ||||
| test: test-guard test-runtime test-distribution | |||||
| test-validation: tests/test_validation.c src/validation.c src/signal.c src/guard.h | |||||
| $(CC) $(TESTFLAGS) -Itests/api-sketch -o $@ tests/test_validation.c | |||||
| test-prepare: tests/test_prepare.c src/illumos.c src/core.c src/config.c src/guard.h | |||||
| $(CC) $(TESTFLAGS) -Itests/api-sketch -o $@ tests/test_prepare.c src/core.c src/config.c | |||||
| test: test-guard test-runtime test-validation test-prepare test-distribution | |||||
| ./test-guard | ./test-guard | ||||
| ./test-runtime | ./test-runtime | ||||
| ./test-validation | |||||
| ./test-prepare | |||||
| test-sanitize: | test-sanitize: | ||||
| $(CC) $(TESTFLAGS) -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-guard tests/test_guard.c src/core.c src/config.c | $(CC) $(TESTFLAGS) -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-guard tests/test_guard.c src/core.c src/config.c | ||||
| ./test-sanitize-guard | ./test-sanitize-guard | ||||
| $(CC) $(TESTFLAGS) -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-runtime tests/test_runtime.c src/core.c src/config.c | |||||
| $(CC) $(TESTFLAGS) -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-runtime tests/test_runtime.c src/core.c src/config.c src/result.c | |||||
| ./test-sanitize-runtime | ./test-sanitize-runtime | ||||
| $(CC) $(TESTFLAGS) -Itests/api-sketch -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-validation tests/test_validation.c | |||||
| ./test-sanitize-validation | |||||
| $(CC) $(TESTFLAGS) -Itests/api-sketch -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-prepare tests/test_prepare.c src/core.c src/config.c | |||||
| ./test-sanitize-prepare | |||||
| # Local API sketches only: NOT real illumos headers, ABI, linking or runtime validation. | # Local API sketches only: NOT real illumos headers, ABI, linking or runtime validation. | ||||
| portability: | portability: | ||||
| @@ -42,4 +54,4 @@ portability: | |||||
| xmllint --nonet --noout smf/o6h-memory-guard.xml | xmllint --nonet --noout smf/o6h-memory-guard.xml | ||||
| clean: | clean: | ||||
| rm -f o6h-memory-guard test-guard test-runtime test-sanitize-guard test-sanitize-runtime | |||||
| rm -f o6h-memory-guard test-guard test-runtime test-validation test-prepare test-sanitize-guard test-sanitize-runtime test-sanitize-validation test-sanitize-prepare | |||||
| @@ -1,4 +1,4 @@ | |||||
| # o6h-memory-guard 1.0.7 | |||||
| # o6h-memory-guard 1.0.8 | |||||
| Primera implementación para SmartOS global zone: daemon C de 64 bits, libkstat, | Primera implementación para SmartOS global zone: daemon C de 64 bits, libkstat, | ||||
| /proc, identidad UUID + generación de zona + PID + instante de creación, | /proc, identidad UUID + generación de zona + PID + instante de creación, | ||||
| @@ -49,12 +49,12 @@ Si no hay herramientas de desarrollo, compilar en una **zona nativa SmartOS** | |||||
| de la misma plataforma (no LX), ejecutar allí `gmake test`, y copiar el binario | de la misma plataforma (no LX), ejecutar allí `gmake test`, y copiar el binario | ||||
| junto a este árbol al host. No instalar un compilador en un nodo bajo presión. | junto a este árbol al host. No instalar un compilador en un nodo bajo presión. | ||||
| Copiar el archivo distribuido a `/var/tmp/o6h-memory-guard-1.0.7.tar.gz`: | |||||
| Copiar el archivo distribuido a `/var/tmp/o6h-memory-guard-1.0.8.tar.gz`: | |||||
| ```sh | ```sh | ||||
| mkdir -p /opt/custom/src | mkdir -p /opt/custom/src | ||||
| cd /opt/custom/src | cd /opt/custom/src | ||||
| gzip -dc /var/tmp/o6h-memory-guard-1.0.7.tar.gz | tar -xf - | |||||
| gzip -dc /var/tmp/o6h-memory-guard-1.0.8.tar.gz | tar -xf - | |||||
| cd /opt/custom/src/o6h-memory-guard | cd /opt/custom/src/o6h-memory-guard | ||||
| gmake CC=gcc | gmake CC=gcc | ||||
| gmake test CC=gcc | gmake test CC=gcc | ||||
| @@ -297,6 +297,41 @@ de escritura de señal consumen presupuesto para evitar reintentos ambiguos. | |||||
| ## Recursos y fallos | ## Recursos y fallos | ||||
| Desde v1.0.8, la preparación ocurre en 16 trabajadores preasignados. La espera | |||||
| del hilo de rescate se limita a 250 ms en CRITICAL, 100 ms en EMERGENCY y 50 ms | |||||
| en FLOOR. Si vence, abandona ese candidato y prueba el siguiente. Los | |||||
| trabajadores nunca envían señales: sólo rescate usa un descriptor preparado | |||||
| y vigente. Un resultado tardío se descarta y su cierre ocurre en el trabajador. | |||||
| Si todos quedan bloqueados, se rechaza por EBUSY sin crear más hilos. Son | |||||
| presupuestos por candidato: máximo 16 entradas y una escalada pendiente por pasada. | |||||
| Se conserva PID, inicio, UUID/generación, allow/protect y cooldown. La identidad | |||||
| se lee una sola vez por preparación. El último refresco sólo lee freemem con | |||||
| kstat propio; no enumera swap/CPU ni consulta ARC. El muestreo general conserva | |||||
| esas métricas. Los límites controlan la espera, sin garantizar planificación en | |||||
| tiempo real ni una duración máxima de PCKILL dentro del kernel. | |||||
| `action_result` usa `syscall=write operation=PCKILL attempted=1 rc=... errno=...` | |||||
| y `errno_name`. rc es el retorno en bytes de write, no el retorno de kill(2). | |||||
| La escritura completa equivale a éxito y fuerza errno 0. Una escritura parcial | |||||
| se distingue por `transport_status=short_write` y no se reintenta. Los rechazos | |||||
| llevan `syscall=none attempted=0 errno_origin=validation`. No hay timestamps | |||||
| de intento inventados; `signal_sent` exige escritura completa. | |||||
| `candidate_validation` descompone PID, inicio, zona, generación, política, | |||||
| protecciones, cooldown, open/read/parse y memoria. Cooldown incluye la decisión | |||||
| de política en memoria. Algunas medidas se solapan (PID/open), por lo que no | |||||
| se suman; `validate_total_ms` incluye espera y preparación. | |||||
| `validation_late_result discarded=1` informa cuando termina un trabajo expirado. | |||||
| `dispatch_latency_ms` y `action_dispatch_latency_ms` miden decisión → retorno: | |||||
| validación + entrega/planificación + syscall, sin logging. `kill_latency_ms` | |||||
| sólo mide la syscall. Decisión → entrada se obtiene restando `decision_mono` | |||||
| de `kill_attempt_mono`. | |||||
| `INCIDENT_FLOOR_KILL_FAILED_2026_09_23.md` documenta FLOOR486, la ambigüedad | |||||
| de EAGAIN en v1.0.7 y el PASS real del logger. La recuperación no se atribuye | |||||
| al SIGKILL fallido y la selección de víctimas no se confunde con atribuir causas. | |||||
| Almacenamiento fijo para 4096 procesos, 256 zonas, 16 candidatos y una cola de | Almacenamiento fijo para 4096 procesos, 256 zonas, 16 candidatos y una cola de | ||||
| 512 eventos, reservado al arrancar; el tamaño se registra. No hay malloc de la aplicación | 512 eventos, reservado al arrancar; el tamaño se registra. No hay malloc de la aplicación | ||||
| en la ruta de acción, ni `system`, `popen`, `exec`, `vmadm`, `ps` o `vmstat` en | en la ruta de acción, ni `system`, `popen`, `exec`, `vmadm`, `ps` o `vmstat` en | ||||
| @@ -401,7 +436,7 @@ Alloy/Loki puede configurarse fuera del guard, pero esta entrega no lo hace. | |||||
| ## Modelo de activación real (operación futura; no ejecutada en esta entrega) | ## Modelo de activación real (operación futura; no ejecutada en esta entrega) | ||||
| v1.0.7 debe compilarse y observarse primero en SmartOS con `ACTION_MODE dry-run`. | |||||
| v1.0.8 debe compilarse y observarse primero en SmartOS con `ACTION_MODE dry-run`. | |||||
| El manifiesto ya no contiene una segunda puerta oculta. Cuando exista aprobación | El manifiesto ya no contiene una segunda puerta oculta. Cuando exista aprobación | ||||
| operativa explícita, el único cambio de modo es editar la configuración: | operativa explícita, el único cambio de modo es editar la configuración: | ||||
| @@ -1,36 +1,45 @@ | |||||
| 887569535302f7deba4d7c6ffb2103f1fb90bd96a40280240ff238eddc2e3a6f ./.gitignore | |||||
| 835934c3bdd868f0b06cc399081952279c68674677513d6edf63b2c323befee8 ./CHANGELOG.md | |||||
| 23f26b11ceec2765e71bae4d193b6a844dfe24081a20b6212037953745f6bb87 ./CHECKPOINT.md | |||||
| a0f96300e751d08ceeef1360325ed54008b703fa6bd07df9d5368674e580f113 ./INCIDENT_PAGEOUT_DEADMAN_2026_09.md | |||||
| fb6b65a2655ccd808d102fd917b4866cbe939f24fac4e4aeef226a6aeda6d588 ./INCIDENT_PAGEOUT_DEADMAN_AVOIDED_2026_09_21.md | |||||
| 0f18d6dd3e0d027c1e8dbfce05ce6ac3beb70f3f66d1a77a8d0c5e0f4ae2a039 ./INCIDENT_PAGEOUT_DEADMAN_PANIC32_2026_09_22.md | |||||
| 5cdc6a11adf10b5ee9042cf87b8c8e6a5f94a7803be9b5b2f92b57c76c66043c ./Makefile | |||||
| 442e22442b19e1f2576b25bed28f974281ff7b520607d7108fb2e9ca2648338d ./README.md | |||||
| e648242f049aeebf657fc64ce367494abffc9aa54f2833edd234b5dc07d87131 ./VALIDATION.md | |||||
| ca37b8d46de1a5ee432fdda1dd7f8883d4e46e9cc646fb1ff9ad9b6caa7bbeb6 ./etc/o6h-memory-guard.conf | |||||
| f6565d0e1ece0a08721c9893f9ed071d2ab0a2818fa93ed0a14e0050d358ce99 ./install.sh | |||||
| 24c1b9bc39fda71d459d6fad6a8d889b0d9b92be89d303677643b3d0b93caf4b ./logs/distribution-tests.log | |||||
| 50626dec1924e19b4ca92eec30416fb39c3fe7cff28d98a8e120ccf6247d2834 ./logs/example.log | |||||
| 812482297ae6dfb2a0881998781459ed77288ef073f202a18f22055437518fa6 ./logs/policy-tests.log | |||||
| 451357017446eea44680b0fa48c69e091a0f1062fafde97d38405fc8b01f4d5a ./logs/portability.log | |||||
| 1963ed6d329842c2a6cedf4780074e0db28161e1c510e36afd532edf286b5930 ./logs/runtime-tests.log | |||||
| 9b3ffe409f024768277d449c3df456cc2c35a21ce8f42e6653886cb758229e88 ./logs/sanitizers.log | |||||
| 55cf49840cf1d22e4e02bedf579a10207856a0a5b40c86ae2cf6ee2f00d3f972 ./smf/o6h-memory-guard.xml | |||||
| 99e1fb6a90a7bd2c1002ad09320cd3f21c2deb2499212eff2baddc14f3bdf0e6 ./src/config.c | |||||
| 659da2facd27577c763484694a2ff62eef42aea48ebc496b878853b0164b6539 ./src/core.c | |||||
| 727c34a27081c3fedd3180c8e6f932a3cbefeded81906012d04bdfbaf02a9421 ./src/guard.h | |||||
| 71ed7fe84db58b8bb7577fff7eba564b31c38db3d12082df641faec0e7465d09 ./src/illumos.c | |||||
| a9652dddb0aa118b58f462434c3acba425e29bc89ef239589fd91252d2586577 ./src/main.c | |||||
| 1f09afd342ba86580a21f6c04a030d9ea2551a60b669e257295fbf4f43b2fad7 ./src/support.c | |||||
| f754e71d91d65403ab8e84e9701cfbb89bdd91e13766e668445e689e6890b369 ./tests/api-sketch/kstat.h | |||||
| f0d06353d2e326c7bdce776bee6f0a8606cda50d5de957dfdd586b6848fca8da ./tests/api-sketch/procfs.h | |||||
| 1c4fcb7bc48ec0a2774b1ecd73346dd45feb969a9250eb7056809d5d11ad40fe ./tests/api-sketch/sys/swap.h | |||||
| 340600b282a0c813323c1a09d5d6635ed4c56aa49a6d04132636851c8e714170 ./tests/api-sketch/vm/anon.h | |||||
| 9b99e272008ad00ad0abb366e1e8720dd6c51fc050821c5d1d878eae5719c22b ./tests/api-sketch/zone.h | |||||
| 4aa08ded8e98cf25d2a8762543de7a9273f0ebf00b4c7e5b359603ceda46eb56 ./tests/fixtures/global_victim_ranking_smartos_2026_09.csv | |||||
| c5d9d7fc7a39354474d30cd316ea9f122205c2b38e57f927f4a08306b8a62c81 ./tests/fixtures/pageout_deadman_real_incident_2026_09.csv | |||||
| 025983b24045e24a96532c933715b8760edd8c0b0e11b9f0e019481c1c52a50d ./tests/fixtures/panic32_daemon_stall_2026_09_22.csv | |||||
| facc4580ffadef29cdce84bf1226a696cba3880bbbec80161beaceb2752bfd77 ./tests/fixtures/successful_pageout_deadman_avoidance_2026_09_21.csv | |||||
| acee8fe2770c612a051ac92022e23f310afc557e23d0e6193f728a2ecd9729ad ./tests/test_distribution.sh | |||||
| 7c0cfe5fc6719d27258bb87b9e68388be7b580d7031a5ed6deac34ddb3050f25 ./tests/test_guard.c | |||||
| 068f1c641440c285211d70dfb61eff492411c2a549b8c692c3d5f71358d90ce8 ./tests/test_runtime.c | |||||
| ab22dd5e73f360b7f08839f95e35e970ce4401e4541071e802cf2d24e3d8e2a6 .gitignore | |||||
| b6e4b74d694eec1214446e0bfc369e582fd28069a2547eabe9571135cb27d669 CHANGELOG.md | |||||
| 1d366afb5d27b3eb001e3534f9cfff2dd422d4e5524780dbb866a120d80507e4 CHECKPOINT.md | |||||
| 4d0b3983bbb0d2a51c61ce0f99d778cc79768ed371bdb5ced382c0fb5dfcaf5f INCIDENT_FLOOR_KILL_FAILED_2026_09_23.md | |||||
| a0f96300e751d08ceeef1360325ed54008b703fa6bd07df9d5368674e580f113 INCIDENT_PAGEOUT_DEADMAN_2026_09.md | |||||
| fb6b65a2655ccd808d102fd917b4866cbe939f24fac4e4aeef226a6aeda6d588 INCIDENT_PAGEOUT_DEADMAN_AVOIDED_2026_09_21.md | |||||
| 0f18d6dd3e0d027c1e8dbfce05ce6ac3beb70f3f66d1a77a8d0c5e0f4ae2a039 INCIDENT_PAGEOUT_DEADMAN_PANIC32_2026_09_22.md | |||||
| 3f46724f39a0b91fa6cb56e6d2dc79f195894f085954c11b575cb1f611476138 Makefile | |||||
| d56adedb3baf4b7d126cae06dc6f94129b77f9590753b5870b7d89b51106b97d README.md | |||||
| 8afc5ef6c25abf43bc32f56833ad761dc85a495a06aadc79f2b94da890f4693d VALIDATION.md | |||||
| b5a762b6e405dbaa408b8a6a7f5cdfaf9d5b04c3220cdc6787c25e96dba314e1 etc/o6h-memory-guard.conf | |||||
| f6565d0e1ece0a08721c9893f9ed071d2ab0a2818fa93ed0a14e0050d358ce99 install.sh | |||||
| 24c1b9bc39fda71d459d6fad6a8d889b0d9b92be89d303677643b3d0b93caf4b logs/distribution-tests.log | |||||
| 50626dec1924e19b4ca92eec30416fb39c3fe7cff28d98a8e120ccf6247d2834 logs/example.log | |||||
| 812482297ae6dfb2a0881998781459ed77288ef073f202a18f22055437518fa6 logs/policy-tests.log | |||||
| d60b67d7c8b0307593fe28fc13025778f0c7175d9bdf0cc2fa4f5edfcc18fb6c logs/portability.log | |||||
| f0ebf6b604648fa1cddb15b55c9ae7f2f5428cd952bcd41778171a1e6b1dc79d logs/prepare-tests.log | |||||
| 84a2c4ba87494915e8225bae692c9458417131919fed8d8c1c5c116da6a38554 logs/runtime-tests.log | |||||
| 3d707eaf3b6b306a363abbc696226a3764069099bd3c6809585769a5f63a626a logs/sanitizers.log | |||||
| 437b5853cf6bdc05a660620ce44b14a10901fca1428218942ed87897cfef6d17 logs/validation-tests.log | |||||
| 55cf49840cf1d22e4e02bedf579a10207856a0a5b40c86ae2cf6ee2f00d3f972 smf/o6h-memory-guard.xml | |||||
| 99e1fb6a90a7bd2c1002ad09320cd3f21c2deb2499212eff2baddc14f3bdf0e6 src/config.c | |||||
| 659da2facd27577c763484694a2ff62eef42aea48ebc496b878853b0164b6539 src/core.c | |||||
| c4a18ce71f8d5e29e861c5d2507ca811b4d803fda6f00c7a872950a7d32445b7 src/guard.h | |||||
| f6bc7848998e626a822c6ab119af958727c46d67669fbb63ec6313ee6a595e17 src/illumos.c | |||||
| ce063766de0739504172bcf272f1713739c6674861a11f0ac215601229d6aaf6 src/main.c | |||||
| 5bb4e0980de83b29e05bb10ea87d6c04f10df884dc92f74cd6b3b025d41d3332 src/result.c | |||||
| ff0ec972bfbb0bbdc9bd7dd205407da7c0f2b2102263626ce10210773d2da7e8 src/signal.c | |||||
| 1f09afd342ba86580a21f6c04a030d9ea2551a60b669e257295fbf4f43b2fad7 src/support.c | |||||
| dfa4926c9bba9b0707c683dd4e1d8dc4bfa044da5221b0bf25e5a04fe007aac8 src/validation.c | |||||
| f754e71d91d65403ab8e84e9701cfbb89bdd91e13766e668445e689e6890b369 tests/api-sketch/kstat.h | |||||
| f0d06353d2e326c7bdce776bee6f0a8606cda50d5de957dfdd586b6848fca8da tests/api-sketch/procfs.h | |||||
| 1c4fcb7bc48ec0a2774b1ecd73346dd45feb969a9250eb7056809d5d11ad40fe tests/api-sketch/sys/swap.h | |||||
| 340600b282a0c813323c1a09d5d6635ed4c56aa49a6d04132636851c8e714170 tests/api-sketch/vm/anon.h | |||||
| 9b99e272008ad00ad0abb366e1e8720dd6c51fc050821c5d1d878eae5719c22b tests/api-sketch/zone.h | |||||
| 58a3d2e0323453af4196c268b02544c93c70ffbe155df08a88a31b8e30e9d6e9 tests/fixtures/floor_free_pages_486_2026_09_23.csv | |||||
| 4aa08ded8e98cf25d2a8762543de7a9273f0ebf00b4c7e5b359603ceda46eb56 tests/fixtures/global_victim_ranking_smartos_2026_09.csv | |||||
| c5d9d7fc7a39354474d30cd316ea9f122205c2b38e57f927f4a08306b8a62c81 tests/fixtures/pageout_deadman_real_incident_2026_09.csv | |||||
| 025983b24045e24a96532c933715b8760edd8c0b0e11b9f0e019481c1c52a50d tests/fixtures/panic32_daemon_stall_2026_09_22.csv | |||||
| facc4580ffadef29cdce84bf1226a696cba3880bbbec80161beaceb2752bfd77 tests/fixtures/successful_pageout_deadman_avoidance_2026_09_21.csv | |||||
| 84b3e9b9dbab27a6ed18b69d9f11bc7ca6a84105cd80bb543411146cdba57a00 tests/test_distribution.sh | |||||
| 7c0cfe5fc6719d27258bb87b9e68388be7b580d7031a5ed6deac34ddb3050f25 tests/test_guard.c | |||||
| a485433d8c0f1ee1a538a520a2e6a4a82db5a7e6b3896351a7403e0eeb4d2c90 tests/test_prepare.c | |||||
| bbdd14d320368507afeab712f0c8aa4afaa4b31d325233b19d546e78685966b7 tests/test_runtime.c | |||||
| bb6e78e1b4ea22d703f738a3beaaee6c192bfaf103d75af7e381143052818b05 tests/test_validation.c | |||||
| @@ -1,11 +1,21 @@ | |||||
| # Validación de la entrega v1.0.7 | |||||
| # Validación de la entrega v1.0.8 | |||||
| Fecha: 2026-09-22. Entrega source-only. **No se desplegó, no se modificó el | |||||
| Fecha: 2026-09-23. Entrega source-only. **No se desplegó, no se modificó el | |||||
| nodo armado y no se enviaron señales reales.** La configuración conserva | nodo armado y no se enviaron señales reales.** La configuración conserva | ||||
| `ACTION_MODE dry-run`, syslog `local5`, cero UUID `allow` y SMF deshabilitado. | `ACTION_MODE dry-run`, syslog `local5`, cero UUID `allow` y SMF deshabilitado. | ||||
| ## Motivo | ## Motivo | ||||
| FLOOR486 de v1.0.7: free=486, nscan=1548386, validación 1283,513 ms, | |||||
| acción failed errno=11 y recuperación posterior con el candidato aún vivo. | |||||
| No hubo panic en esa traza. El logger aisló escrituras de hasta 6655 ms: | |||||
| PASS real del aislamiento de v1.0.7. La auditoría descubre write(PCKILL), | |||||
| cancelación EAGAIN previa a la syscall y timestamps de intento rellenados | |||||
| por el llamador; no permite atribuir el errno histórico a una operación concreta. | |||||
| Informe: `INCIDENT_FLOOR_KILL_FAILED_2026_09_23.md`. | |||||
| Se conserva como regresión el incidente anterior: | |||||
| panic32 terminó en `pageout_deadman` con `freemem=424`. El guard había resuelto | panic32 terminó en `pageout_deadman` con `freemem=424`. El guard había resuelto | ||||
| dos emergencias, pero en una tercera transcurrieron unos 145 s entre la decisión | dos emergencias, pero en una tercera transcurrieron unos 145 s entre la decisión | ||||
| SIGKILL y `signal_sent`. Después hubo recuperación parcial, recaída, caché con | SIGKILL y `signal_sent`. Después hubo recuperación parcial, recaída, caché con | ||||
| @@ -32,11 +42,33 @@ no está confirmado si lo causó syslog, guard.log u otra syscall. Véase | |||||
| enqueue, guard log y syslog mediante reloj monotónico. | enqueue, guard log y syslog mediante reloj monotónico. | ||||
| 9. `logging_stall` se produce después de recuperar el worker; nunca se registra | 9. `logging_stall` se produce después de recuperar el worker; nunca se registra | ||||
| recursivamente desde la ruta de señal. | recursivamente desde la ruta de señal. | ||||
| 10. Preparación única en 16 trabajadores, presupuesto 250/100/50 ms y fallback. | |||||
| No se duplica una solicitud por identidad atascada. El pool lleno devuelve | |||||
| EBUSY; no crea más hilos. Los trabajadores esperan en semáforos, sin polling | |||||
| continuo en reposo. El hilo de rescate nunca espera su terminación. | |||||
| 11. Una preparación expirada no puede señalar; sólo rescate llama a dispatch. | |||||
| Se descarta el resultado tardío y se cierra el descriptor fuera de rescate. | |||||
| 12. write → captura inmediata de errno → reloj. Retorno real en bytes, nombre, | |||||
| attempted y syscall explícitos. Rechazos de validación no simulan un intento. | |||||
| 13. Instrumentación por subpasos y freemem aislado por trabajador, sin un segundo | |||||
| recorrido de identidad ni refresco ARC/swap/CPU previo a la escritura. | |||||
| ## Pruebas ejecutadas | ## Pruebas ejecutadas | ||||
| - Política: 175 comprobaciones; incluye los fixtures previos y no enlaza backend. | - Política: 175 comprobaciones; incluye los fixtures previos y no enlaza backend. | ||||
| - Runtime simulado: 501 comprobaciones; ninguna señal nativa. | |||||
| - Runtime simulado: 452 comprobaciones; ninguna señal nativa. El número cambia | |||||
| al eliminar las comprobaciones duplicadas del mock de doble validación. | |||||
| - Preparación concurrente: 66 comprobaciones. Espera real inyectada de 1283 ms; | |||||
| abandono con presupuesto de 50 ms, fallback a otro trabajador, descarte tardío, | |||||
| deduplicación, saturación y recuperación del pool. Tolerancias del test local: | |||||
| abandono <150 ms y fallback completado <200 ms, muy inferiores a 1 s; el | |||||
| presupuesto programado sigue siendo 50 ms. No es garantía de tiempo real. | |||||
| - Código nativo de preparación con I/O simulado: 15 comprobaciones de PID/start, | |||||
| generación, protect, errno, memoria recuperada, subpasos y dry-run sin ctl. | |||||
| - Código real de dispatch con write simulado: éxito, ESRCH, EPERM, EINVAL, EAGAIN, | |||||
| errno previo EAGAIN/ENOMEM, reloj que altera errno y escritura parcial. | |||||
| - Fixture `floor_free_pages_486_2026_09_23`: NORMAL→EMERGENCY/FLOOR y recuperación; | |||||
| timeout rank1 → rank2, rechazo sin syscall y resultados sin errno heredado. | |||||
| - Fixture `panic32_daemon_stall_2026_09_22`: conserva el intervalo de 145 s. | - Fixture `panic32_daemon_stall_2026_09_22`: conserva el intervalo de 145 s. | ||||
| - Logger/syslog detenidos 180 s: TERM y SIGKILL se solicitan sin esperar y el | - Logger/syslog detenidos 180 s: TERM y SIGKILL se solicitan sin esperar y el | ||||
| tiempo real de cada llamada a `act()` queda por debajo de 100 ms. | tiempo real de cada llamada a `act()` queda por debajo de 100 ms. | ||||
| @@ -55,7 +87,8 @@ no está confirmado si lo causó syslog, guard.log u otra syscall. Véase | |||||
| - Checksums SHA-256 del árbol source-only y verificación desde paquete extraído. | - Checksums SHA-256 del árbol source-only y verificación desde paquete extraído. | ||||
| Los resultados se conservan en `logs/policy-tests.log`, `logs/runtime-tests.log`, | Los resultados se conservan en `logs/policy-tests.log`, `logs/runtime-tests.log`, | ||||
| `logs/sanitizers.log`, `logs/portability.log` y `logs/distribution-tests.log`. | |||||
| `logs/validation-tests.log`, `logs/prepare-tests.log`, `logs/sanitizers.log`, | |||||
| `logs/portability.log` y `logs/distribution-tests.log`. | |||||
| ## Políticas no modificadas | ## Políticas no modificadas | ||||
| @@ -79,7 +112,7 @@ semántica monotónica de `sampling_overrun`. | |||||
| ## Validación nativa pendiente — NO GO para despliegue | ## Validación nativa pendiente — NO GO para despliegue | ||||
| 1. Compilar y ejecutar toda la suite con headers/ABI SmartOS nativos. | 1. Compilar y ejecutar toda la suite con headers/ABI SmartOS nativos. | ||||
| 2. Confirmar soporte y comportamiento de pthreads en el servicio SMF. | |||||
| 2. Confirmar pthreads, semáforos, los 16 contextos kstat y consumo de memoria en SMF. | |||||
| 3. En laboratorio desechable, bloquear por separado destino de guard.log y | 3. En laboratorio desechable, bloquear por separado destino de guard.log y | ||||
| receptor local5 mientras se generan decisiones simuladas/controladas. | receptor local5 mientras se generan decisiones simuladas/controladas. | ||||
| 4. Confirmar que `decision_mono → kill_attempt_mono` permanece varios órdenes | 4. Confirmar que `decision_mono → kill_attempt_mono` permanece varios órdenes | ||||
| @@ -88,13 +121,18 @@ semántica monotónica de `sampling_overrun`. | |||||
| la caché publicada, sin carreras en la enumeración nativa. | la caché publicada, sin carreras en la enumeración nativa. | ||||
| 6. Validar 8/12 candidatos reales, protecciones, supervisores y recuperación. | 6. Validar 8/12 candidatos reales, protecciones, supervisores y recuperación. | ||||
| 7. Revisar `logging_queue_drop`, `logging_delivery` y `logging_stall` bajo carga. | 7. Revisar `logging_queue_drop`, `logging_delivery` y `logging_stall` bajo carga. | ||||
| 8. Mantener dry-run hasta revisión humana explícita. v1.0.7 no se considera apta | |||||
| 8. Inyectar lecturas lentas por subpaso y comprobar abandono, descarte tardío, | |||||
| recuperación y saturación del pool. Verificar semántica nativa O_NONBLOCK/ctl. | |||||
| 9. Mantener dry-run hasta revisión humana explícita. v1.0.8 no se considera apta | |||||
| para producción sólo por superar las pruebas portables. | para producción sólo por superar las pruebas portables. | ||||
| ## Límites | ## Límites | ||||
| La validación puntual de un candidato y PCKILL siguen siendo syscalls del kernel | |||||
| y no pueden recibir una garantía temporal absoluta desde userland. La cola puede | |||||
| La espera de validación tiene deadline monotónico, pero una desprogramación del | |||||
| hilo puede excederlo; el resultado expirado no se autoriza. La syscall atascada | |||||
| puede continuar en un trabajador sin poder enviar señales. El muestreo general | |||||
| y PCKILL siguen dependiendo del kernel y no tienen garantía temporal absoluta. | |||||
| No se emplea la misma promesa para espera, syscall y scheduling. La cola puede | |||||
| perder logs deliberadamente. Los workers bloqueados sólo se recuperan cuando la | perder logs deliberadamente. Los workers bloqueados sólo se recuperan cuando la | ||||
| syscall subyacente retorna; el proceso no espera por ellos al rescatar ni al salir. | syscall subyacente retorna; el proceso no espera por ellos al rescatar ni al salir. | ||||
| RSS no equivale a memoria exclusiva recuperable. El guard reduce riesgo, no | RSS no equivale a memoria exclusiva recuperable. El guard reduce riesgo, no | ||||
| @@ -1,4 +1,4 @@ | |||||
| # o6h-memory-guard 1.0.7 -- whitespace-separated, no shell evaluation. | |||||
| # o6h-memory-guard 1.0.8 -- whitespace-separated, no shell evaluation. | |||||
| # Restart required for configuration changes. Duplicate scalar keys are errors. | # Restart required for configuration changes. Duplicate scalar keys are errors. | ||||
| ACTION_MODE dry-run | ACTION_MODE dry-run | ||||
| SYSLOG_ENABLED yes | SYSLOG_ENABLED yes | ||||
| @@ -1,3 +1,5 @@ | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -Itests/api-sketch -fsyntax-only src/main.c src/core.c src/config.c src/support.c src/illumos.c | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -Itests/api-sketch -fsyntax-only src/main.c src/core.c src/config.c src/support.c src/illumos.c src/validation.c src/result.c src/signal.c | |||||
| sh -n install.sh tests/test_distribution.sh | sh -n install.sh tests/test_distribution.sh | ||||
| xmllint --nonet --noout smf/o6h-memory-guard.xml | xmllint --nonet --noout smf/o6h-memory-guard.xml | ||||
| PASS GCC -fanalyzer for all SOURCES (silent Makefile loop) | |||||
| API sketches only, not native ABI validation. | |||||
| @@ -0,0 +1 @@ | |||||
| PASS 15 native preparation source checks with mocked proc/kstat/zone I/O; no native ABI claim or signals | |||||
| @@ -1,20 +1,3 @@ | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -o test-guard tests/test_guard.c src/core.c src/config.c | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -o test-runtime tests/test_runtime.c src/core.c src/config.c | |||||
| sh tests/test_distribution.sh | |||||
| PASS distribution defaults to ACTION_MODE dry-run; production SMF does not force it | |||||
| ./test-guard | |||||
| PASS strict configuration, safe defaults, explicit UUID authorization | |||||
| PASS mandatory protections, PID reuse and zone incarnation identity | |||||
| PASS timestamped 5/15/60s windows, missing data, signed growth, overflow | |||||
| PASS all six states, monotonic overruns, threshold jumps, corroboration and recovery | |||||
| PASS pageout_deadman_real_incident_2026_09 exits NORMAL before minfree | |||||
| PASS successful_pageout_deadman_avoidance_2026_09_21 incident fixture | |||||
| SIMULATED t=100 state=CRITICAL UUID=11111111-1111-4111-8111-111111111111 pid=123 WOULD_ACTION=SIGTERM | |||||
| SIMULATED t=105 state=CRITICAL pid=123 WOULD_ACTION=SIGKILL reason=memory_not_recovered | |||||
| SIMULATED state=EMERGENCY floor=1 WOULD_ACTION=SIGKILL reason=floor | |||||
| PASS TERM/KILL sequencing, emergency grace, floor, cooldown, budgets and no-action protections | |||||
| PASS 175 checks; no native backend linked, no signals sent | |||||
| ./test-runtime | |||||
| PASS actual daemon dry-run path records WOULD_ACTION=SIGTERM/SIGKILL; zero real requests | PASS actual daemon dry-run path records WOULD_ACTION=SIGTERM/SIGKILL; zero real requests | ||||
| PASS continuous sample contract and 5/15/60 deltas for commitment, physical swap and pageout | PASS continuous sample contract and 5/15/60 deltas for commitment, physical swap and pageout | ||||
| PASS armed-path mock requests, explicit warmup, stale cache, logging/sampling failures, stop and fresh floor | PASS armed-path mock requests, explicit warmup, stale cache, logging/sampling failures, stop and fresh floor | ||||
| @@ -28,4 +11,5 @@ PASS stalled/incomplete scanner cannot delay or trigger a rescue-path proc scan | |||||
| PASS 16-entry stale rescue cache supplies all 8 EMERGENCY victims without scan | PASS 16-entry stale rescue cache supplies all 8 EMERGENCY victims without scan | ||||
| PASS 16-entry stale rescue cache supplies all 12 FLOOR victims without scan | PASS 16-entry stale rescue cache supplies all 12 FLOOR victims without scan | ||||
| PASS saturated/locked event queue drops telemetry without delaying the signal | PASS saturated/locked event queue drops telemetry without delaying the signal | ||||
| PASS 501 runtime checks; all platform calls mocked, no signals sent | |||||
| PASS floor486 fixture, 50ms timeout fallback rank1->2, syscall errno attribution and validation substep logs | |||||
| PASS 452 runtime checks; all platform calls mocked, no signals sent | |||||
| @@ -1,3 +1,4 @@ | |||||
| ASAN_OPTIONS=detect_leaks=0 (LeakSanitizer disabled in this environment) | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-guard tests/test_guard.c src/core.c src/config.c | gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-guard tests/test_guard.c src/core.c src/config.c | ||||
| ./test-sanitize-guard | ./test-sanitize-guard | ||||
| PASS strict configuration, safe defaults, explicit UUID authorization | PASS strict configuration, safe defaults, explicit UUID authorization | ||||
| @@ -11,7 +12,7 @@ SIMULATED t=105 state=CRITICAL pid=123 WOULD_ACTION=SIGKILL reason=memory_not_re | |||||
| SIMULATED state=EMERGENCY floor=1 WOULD_ACTION=SIGKILL reason=floor | SIMULATED state=EMERGENCY floor=1 WOULD_ACTION=SIGKILL reason=floor | ||||
| PASS TERM/KILL sequencing, emergency grace, floor, cooldown, budgets and no-action protections | PASS TERM/KILL sequencing, emergency grace, floor, cooldown, budgets and no-action protections | ||||
| PASS 175 checks; no native backend linked, no signals sent | PASS 175 checks; no native backend linked, no signals sent | ||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-runtime tests/test_runtime.c src/core.c src/config.c | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-runtime tests/test_runtime.c src/core.c src/config.c src/result.c | |||||
| ./test-sanitize-runtime | ./test-sanitize-runtime | ||||
| PASS actual daemon dry-run path records WOULD_ACTION=SIGTERM/SIGKILL; zero real requests | PASS actual daemon dry-run path records WOULD_ACTION=SIGTERM/SIGKILL; zero real requests | ||||
| PASS continuous sample contract and 5/15/60 deltas for commitment, physical swap and pageout | PASS continuous sample contract and 5/15/60 deltas for commitment, physical swap and pageout | ||||
| @@ -26,4 +27,11 @@ PASS stalled/incomplete scanner cannot delay or trigger a rescue-path proc scan | |||||
| PASS 16-entry stale rescue cache supplies all 8 EMERGENCY victims without scan | PASS 16-entry stale rescue cache supplies all 8 EMERGENCY victims without scan | ||||
| PASS 16-entry stale rescue cache supplies all 12 FLOOR victims without scan | PASS 16-entry stale rescue cache supplies all 12 FLOOR victims without scan | ||||
| PASS saturated/locked event queue drops telemetry without delaying the signal | PASS saturated/locked event queue drops telemetry without delaying the signal | ||||
| PASS 501 runtime checks; all platform calls mocked, no signals sent | |||||
| PASS floor486 fixture, 50ms timeout fallback rank1->2, syscall errno attribution and validation substep logs | |||||
| PASS 452 runtime checks; all platform calls mocked, no signals sent | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -Itests/api-sketch -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-validation tests/test_validation.c | |||||
| ./test-sanitize-validation | |||||
| PASS 66 validation checks: real 1283ms worker abandoned, fallback, late disposal, pool saturation; actual dispatch code with mocked write; no signals | |||||
| gcc -std=c99 -O1 -g -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc -Wall -Wextra -Werror -Wformat=2 -pedantic -pthread -Itests/api-sketch -fsanitize=address,undefined -fno-omit-frame-pointer -o test-sanitize-prepare tests/test_prepare.c src/core.c src/config.c | |||||
| ./test-sanitize-prepare | |||||
| PASS 15 native preparation source checks with mocked proc/kstat/zone I/O; no native ABI claim or signals | |||||
| @@ -0,0 +1 @@ | |||||
| PASS 66 validation checks: real 1283ms worker abandoned, fallback, late disposal, pool saturation; actual dispatch code with mocked write; no signals | |||||
| @@ -13,7 +13,7 @@ | |||||
| #define CONF_PATH "/opt/custom/etc/o6h-memory-guard.conf" | #define CONF_PATH "/opt/custom/etc/o6h-memory-guard.conf" | ||||
| #define LOG_DIR "/opt/custom/var/log/o6h-memory-guard" | #define LOG_DIR "/opt/custom/var/log/o6h-memory-guard" | ||||
| #define RUN_DIR "/opt/custom/var/run" | #define RUN_DIR "/opt/custom/var/run" | ||||
| #define VERSION "1.0.7" | |||||
| #define VERSION "1.0.8" | |||||
| enum state { NORMAL, PRE_PRESSURE, PRESSURE, CRITICAL, EMERGENCY, RECOVERY }; | enum state { NORMAL, PRE_PRESSURE, PRESSURE, CRITICAL, EMERGENCY, RECOVERY }; | ||||
| enum policy { OBSERVE, ALLOW, PROTECT }; | enum policy { OBSERVE, ALLOW, PROTECT }; | ||||
| @@ -95,8 +95,29 @@ int platform_init(void); | |||||
| void platform_fini(void); | void platform_fini(void); | ||||
| int platform_sample(sample_t *); | int platform_sample(sample_t *); | ||||
| int platform_walk(int (*)(const process_t *, void *), void *, unsigned); | int platform_walk(int (*)(const process_t *, void *), void *, unsigned); | ||||
| int platform_signal(const config_t *, const process_t *, enum action, int, | |||||
| uint64_t, double *, double *); | |||||
| typedef struct { | |||||
| double pid_ms, start_ms, zone_ms, generation_ms, policy_ms, protected_ms; | |||||
| double cooldown_ms, open_ms, read_ms, parse_ms, total_ms, memory_ms; | |||||
| const char *stage; | |||||
| } validation_t; | |||||
| typedef struct { | |||||
| int attempted, error; | |||||
| long rc; | |||||
| double attempt, returned; | |||||
| } signal_result_t; | |||||
| /* Worker-only prepare/dispose; only the rescue thread may dispatch. */ | |||||
| int platform_validation_init(unsigned); | |||||
| int platform_prepare(unsigned, const config_t *, const process_t *, int, uint64_t, | |||||
| int *, validation_t *); | |||||
| void platform_dispose(int); | |||||
| void platform_dispatch(int, enum action, signal_result_t *); | |||||
| int validation_start(void); | |||||
| int validation_acquire(const config_t *, const process_t *, int, uint64_t, | |||||
| unsigned, int *, validation_t *); | |||||
| int validation_handle(int); | |||||
| void validation_release(int); | |||||
| void validation_late_result(int, const validation_t *, int); | |||||
| const char *signal_errno_name(int); | |||||
| double monotime(void); | double monotime(void); | ||||
| int secure_file(const char *, int, unsigned); | int secure_file(const char *, int, unsigned); | ||||
| int secure_directory(const char *); | int secure_directory(const char *); | ||||
| @@ -226,54 +226,129 @@ int platform_walk(int (*visit)(const process_t *, void *), void *arg, unsigned b | |||||
| return partial ? -1 : 0; | return partial ? -1 : 0; | ||||
| } | } | ||||
| int platform_signal(const config_t *c, const process_t *expected, enum action action, int real, | |||||
| uint64_t ceiling, double *attempt_mono, double *return_mono) | |||||
| static kstat_ctl_t *validator_kc[16]; | |||||
| int platform_validation_init(unsigned slots) | |||||
| { | |||||
| unsigned i; | |||||
| if (slots > 16) return -1; | |||||
| for (i = 0; i < slots; i++) | |||||
| if (!(validator_kc[i] = kstat_open())) return -1; | |||||
| return 0; | |||||
| } | |||||
| int platform_prepare(unsigned slot, const config_t *c, const process_t *expected, | |||||
| int real, uint64_t ceiling, int *handle, validation_t *timing) | |||||
| { | { | ||||
| char path[64]; | char path[64]; | ||||
| int dir = -1, infofd = -1, ctl = -1, result = -1, saved; | |||||
| int dir = -1, infofd = -1, ctl = -1, result = -1, saved, invalid; | |||||
| psinfo_t info; | psinfo_t info; | ||||
| process_t current; | process_t current; | ||||
| zone_cache_t z; | zone_cache_t z; | ||||
| long command[2]; | |||||
| sample_t latest; | |||||
| if (action != TERM && action != KILL) { errno = EINVAL; return -1; } | |||||
| if (expected->pid == getpid() || protected_process(c, expected) || (real && !c->armed)) { | |||||
| errno = EPERM; return -1; | |||||
| } | |||||
| double start; | |||||
| const zone_rule_t *rule; | |||||
| pid_t init; | |||||
| ssize_t nread; | |||||
| kstat_t *k; | |||||
| uint64_t free_pages; | |||||
| *handle = -1; | |||||
| timing->stage = "policy"; | |||||
| start = monotime(); | |||||
| rule = zone_rule(c, expected->uuid); | |||||
| timing->policy_ms = 1000 * (monotime() - start); | |||||
| if (!rule || rule->policy != ALLOW) { errno = EPERM; return -1; } | |||||
| timing->stage = "protected_process"; | |||||
| start = monotime(); | |||||
| invalid = expected->pid == getpid() || protected_process(c, expected) || (real && !c->armed); | |||||
| timing->protected_ms = 1000 * (monotime() - start); | |||||
| if (invalid) { errno = EPERM; return -1; } | |||||
| snprintf(path, sizeof (path), "/proc/%d", expected->pid); | snprintf(path, sizeof (path), "/proc/%d", expected->pid); | ||||
| dir = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |||||
| timing->stage = "proc_directory_open"; | |||||
| start = monotime(); | |||||
| dir = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NONBLOCK); | |||||
| saved = dir < 0 ? errno : 0; | |||||
| timing->pid_ms = timing->open_ms = 1000 * (monotime() - start); | |||||
| errno = saved; | |||||
| if (dir < 0) goto done; | if (dir < 0) goto done; | ||||
| /* Both descriptors are relative to the same proc directory vnode. */ | /* Both descriptors are relative to the same proc directory vnode. */ | ||||
| infofd = openat(dir, "psinfo", O_RDONLY | O_CLOEXEC); | |||||
| timing->stage = "proc_psinfo_open"; | |||||
| start = monotime(); | |||||
| infofd = openat(dir, "psinfo", O_RDONLY | O_CLOEXEC | O_NONBLOCK); | |||||
| saved = infofd < 0 ? errno : 0; | |||||
| timing->open_ms += 1000 * (monotime() - start); errno = saved; | |||||
| if (infofd < 0) goto done; | if (infofd < 0) goto done; | ||||
| if (real) { | if (real) { | ||||
| ctl = openat(dir, "ctl", O_WRONLY | O_EXCL | O_CLOEXEC); | |||||
| timing->stage = "proc_ctl_open"; | |||||
| start = monotime(); | |||||
| ctl = openat(dir, "ctl", O_WRONLY | O_EXCL | O_CLOEXEC | O_NONBLOCK); | |||||
| saved = ctl < 0 ? errno : 0; | |||||
| timing->open_ms += 1000 * (monotime() - start); errno = saved; | |||||
| if (ctl < 0) goto done; | if (ctl < 0) goto done; | ||||
| } | } | ||||
| if (pread(infofd, &info, sizeof (info), 0) != sizeof (info) || | |||||
| zone_read((int)info.pr_zoneid, &z)) goto done; | |||||
| start = monotime(); | |||||
| timing->stage = "proc_read"; | |||||
| nread = pread(infofd, &info, sizeof (info), 0); | |||||
| saved = nread < 0 ? errno : nread != sizeof (info) ? EIO : 0; | |||||
| timing->read_ms = 1000 * (monotime() - start); errno = saved; | |||||
| if (saved) goto done; | |||||
| timing->stage = "start_time"; | |||||
| start = monotime(); | |||||
| invalid = info.pr_pid != expected->pid || info.pr_start.tv_sec != expected->start_sec || | |||||
| info.pr_start.tv_nsec != expected->start_nsec; | |||||
| timing->start_ms = 1000 * (monotime() - start); | |||||
| if (invalid) { errno = ESTALE; goto done; } | |||||
| memset(&z, 0, sizeof (z)); z.zid = info.pr_zoneid; | |||||
| timing->stage = "zone_identity"; | |||||
| start = monotime(); | |||||
| result = getzonenamebyid((zoneid_t)z.zid, z.uuid, sizeof (z.uuid)); | |||||
| saved = result < 0 ? errno : 0; | |||||
| timing->zone_ms = 1000 * (monotime() - start); errno = saved; | |||||
| result = -1; | |||||
| if (saved) goto done; | |||||
| timing->stage = "zone_generation"; | |||||
| start = monotime(); | |||||
| saved = zone_getattr((zoneid_t)z.zid, ZONE_ATTR_UNIQID, &z.generation, | |||||
| sizeof (z.generation)) < 0 ? errno : 0; | |||||
| timing->generation_ms = 1000 * (monotime() - start); errno = saved; | |||||
| if (saved) goto done; | |||||
| timing->stage = "zone_init_protection"; | |||||
| start = monotime(); | |||||
| saved = zone_getattr((zoneid_t)z.zid, ZONE_ATTR_INITPID, &init, sizeof (init)) < 0 ? errno : 0; | |||||
| timing->protected_ms += 1000 * (monotime() - start); errno = saved; | |||||
| if (saved) goto done; | |||||
| z.initpid = init; | |||||
| timing->stage = "proc_parse"; | |||||
| start = monotime(); | |||||
| convert(&info, &z, ¤t); | convert(&info, &z, ¤t); | ||||
| if (!same_process(expected, ¤t) || strcmp(expected->name, current.name) || | |||||
| timing->parse_ms = 1000 * (monotime() - start); | |||||
| timing->stage = "identity_protection"; | |||||
| start = monotime(); | |||||
| invalid = !same_process(expected, ¤t) || strcmp(expected->name, current.name) || | |||||
| expected->uid != current.uid || expected->euid != current.euid || | expected->uid != current.uid || expected->euid != current.euid || | ||||
| protected_process(c, ¤t)) { errno = ESTALE; goto done; } | |||||
| if (!real) { result = 0; goto done; } | |||||
| if (platform_sample(&latest) || monotime() - latest.at > 2 || latest.free >= ceiling) { | |||||
| protected_process(c, ¤t); | |||||
| timing->protected_ms += 1000 * (monotime() - start); | |||||
| if (invalid) { errno = ESTALE; goto done; } | |||||
| if (!real) { timing->stage = "validated"; result = 0; goto done; } | |||||
| /* Per-worker kstat handle: no ARC, swap enumeration or per-CPU pageouts. */ | |||||
| timing->stage = "memory_recheck"; | |||||
| start = monotime(); | |||||
| k = kstat_lookup(validator_kc[slot], "unix", 0, "system_pages"); | |||||
| saved = !k || kstat_read(validator_kc[slot], k, NULL) == -1 || | |||||
| named(k, "freemem", &free_pages) ? EIO : 0; | |||||
| timing->memory_ms = 1000 * (monotime() - start); errno = saved; | |||||
| if (saved) goto done; | |||||
| if (free_pages >= ceiling) { | |||||
| timing->stage = "memory_recovered"; | |||||
| errno = EAGAIN; goto done; | errno = EAGAIN; goto done; | ||||
| } | } | ||||
| command[0] = PCKILL; command[1] = action == TERM ? SIGTERM : SIGKILL; | |||||
| /* Single atomic proc control message; never retry an ambiguous write. */ | |||||
| { | |||||
| if (attempt_mono) *attempt_mono = monotime(); | |||||
| ssize_t written = write(ctl, command, sizeof (command)); | |||||
| if (return_mono) *return_mono = monotime(); | |||||
| if (written == sizeof (command)) result = 0; | |||||
| else if (written >= 0) errno = EIO; | |||||
| } | |||||
| timing->stage = "validated"; | |||||
| *handle = ctl; ctl = -1; result = 0; | |||||
| done: | done: | ||||
| saved = errno; | |||||
| saved = result ? errno : 0; | |||||
| if (ctl >= 0) close(ctl); | if (ctl >= 0) close(ctl); | ||||
| if (infofd >= 0) close(infofd); | if (infofd >= 0) close(infofd); | ||||
| if (dir >= 0) close(dir); | if (dir >= 0) close(dir); | ||||
| errno = saved; | errno = saved; | ||||
| return result; | return result; | ||||
| } | } | ||||
| void platform_dispose(int handle) { if (handle >= 0) (void)close(handle); } | |||||
| @@ -676,6 +676,29 @@ static void log_sample(const sample_t *s) | |||||
| } | } | ||||
| } | } | ||||
| typedef struct { unsigned rank; int error; double ms; const char *stage; } rejection_t; | |||||
| void validation_late_result(int pid, const validation_t *t, int error) | |||||
| { | |||||
| emit("event=validation_late_result pid=%d discarded=1 errno=%d stage=%s" | |||||
| " validate_total_ms=%.3f proc_open_ms=%.3f proc_read_ms=%.3f" | |||||
| " proc_parse_ms=%.3f validate_pid_exists_ms=%.3f validate_start_time_ms=%.3f" | |||||
| " validate_zone_identity_ms=%.3f validate_zone_generation_ms=%.3f" | |||||
| " validate_policy_ms=%.3f validate_protected_process_ms=%.3f memory_recheck_ms=%.3f", | |||||
| pid, error, t->stage ? t->stage : "unknown", t->total_ms, | |||||
| t->open_ms, t->read_ms, t->parse_ms, t->pid_ms, t->start_ms, | |||||
| t->zone_ms, t->generation_ms, t->policy_ms, t->protected_ms, t->memory_ms); | |||||
| } | |||||
| static void log_rejections(const rejection_t *rejections, unsigned count) | |||||
| { | |||||
| unsigned i; | |||||
| for (i = 0; i < count; i++) | |||||
| emit("event=candidate_rejected reason=%s rank=%u latency_ms=%.3f errno=%d" | |||||
| " syscall=none attempted=0 errno_origin=validation stage=%s", | |||||
| rejections[i].error == ETIMEDOUT ? "validation_timeout" : "validation_failed", | |||||
| rejections[i].rank, rejections[i].ms, rejections[i].error, | |||||
| rejections[i].stage ? rejections[i].stage : "pending_or_unknown"); | |||||
| } | |||||
| static void act(sample_t *sample) | static void act(sample_t *sample) | ||||
| { | { | ||||
| plan_t plan; | plan_t plan; | ||||
| @@ -685,7 +708,13 @@ static void act(sample_t *sample) | |||||
| double candidate_age = -1, decision_mono = 0, validation_start = 0; | double candidate_age = -1, decision_mono = 0, validation_start = 0; | ||||
| double validation_ms = 0, kill_attempt_mono = 0, kill_return_mono = 0; | double validation_ms = 0, kill_attempt_mono = 0, kill_return_mono = 0; | ||||
| double dispatch_ms = 0, kill_ms = 0, enqueue_start, enqueue_ms; | double dispatch_ms = 0, kill_ms = 0, enqueue_start, enqueue_ms; | ||||
| double policy_start, cooldown_ms = 0; | |||||
| unsigned i, rank = 0, rejected = 0; | unsigned i, rank = 0, rejected = 0; | ||||
| unsigned budget_ms; | |||||
| int ticket = -1; | |||||
| validation_t timing; | |||||
| signal_result_t signal_result; | |||||
| rejection_t rejections[CACHED_CANDIDATES + 1]; | |||||
| int err = 0, rc = 0, validated = 0, rejected_pid = 0, rejected_errno = 0; | int err = 0, rc = 0, validated = 0, rejected_pid = 0, rejected_errno = 0; | ||||
| if (stopping) return; | if (stopping) return; | ||||
| if (!engine.danger) { | if (!engine.danger) { | ||||
| @@ -708,17 +737,26 @@ static void act(sample_t *sample) | |||||
| if (fresh.free <= fresh.min) { | if (fresh.free <= fresh.min) { | ||||
| current_engine.state = EMERGENCY; current_engine.danger = 1; | current_engine.state = EMERGENCY; current_engine.danger = 1; | ||||
| } | } | ||||
| budget_ms = current_engine.floor ? 50 : current_engine.state == EMERGENCY ? 100 : 250; | |||||
| memset(&signal_result, 0, sizeof (signal_result)); | |||||
| retry_candidate: | retry_candidate: | ||||
| if (controller.has_pending) { | if (controller.has_pending) { | ||||
| policy_start = monotime(); | |||||
| plan = action_plan(&controller, &cfg, ¤t_engine, &fresh, NULL); | plan = action_plan(&controller, &cfg, ¤t_engine, &fresh, NULL); | ||||
| cooldown_ms = 1000 * (monotime() - policy_start); | |||||
| if (plan.action == NONE) { | if (plan.action == NONE) { | ||||
| emit_important(LOG_WARNING, | emit_important(LOG_WARNING, | ||||
| "event=action_blocked reason=%s state=%s", plan.reason, | "event=action_blocked reason=%s state=%s", plan.reason, | ||||
| state_name(current_engine.state)); return; | state_name(current_engine.state)); return; | ||||
| } | } | ||||
| decision_mono = validation_start = monotime(); | decision_mono = validation_start = monotime(); | ||||
| if (platform_signal(&cfg, &plan.target, plan.action, 0, 0, NULL, NULL)) { | |||||
| if (validation_acquire(&cfg, &plan.target, cfg.armed, | |||||
| current_engine.floor ? fresh.min / 2 + 1 : fresh.des, | |||||
| budget_ms, &ticket, &timing)) { | |||||
| err = errno; controller.has_pending = 0; | err = errno; controller.has_pending = 0; | ||||
| rejections[rejected].rank = 0; rejections[rejected].error = err; | |||||
| rejections[rejected].ms = timing.total_ms; | |||||
| rejections[rejected].stage = timing.stage; | |||||
| rejected++; rejected_pid = plan.target.pid; rejected_errno = err; | rejected++; rejected_pid = plan.target.pid; rejected_errno = err; | ||||
| goto retry_candidate; | goto retry_candidate; | ||||
| } | } | ||||
| @@ -731,11 +769,18 @@ retry_candidate: | |||||
| if (!entry->valid || candidate_age < 0 || | if (!entry->valid || candidate_age < 0 || | ||||
| protected_process(&cfg, &entry->p) || | protected_process(&cfg, &entry->p) || | ||||
| was_victim(&controller, &entry->p)) continue; | was_victim(&controller, &entry->p)) continue; | ||||
| policy_start = monotime(); | |||||
| plan = action_plan(&controller, &cfg, ¤t_engine, &fresh, &entry->p); | plan = action_plan(&controller, &cfg, ¤t_engine, &fresh, &entry->p); | ||||
| cooldown_ms = 1000 * (monotime() - policy_start); | |||||
| if (plan.action == NONE) { blocked_reason = plan.reason; break; } | if (plan.action == NONE) { blocked_reason = plan.reason; break; } | ||||
| decision_mono = validation_start = monotime(); | decision_mono = validation_start = monotime(); | ||||
| if (platform_signal(&cfg, &plan.target, plan.action, 0, 0, NULL, NULL)) { | |||||
| if (validation_acquire(&cfg, &plan.target, cfg.armed, | |||||
| current_engine.floor ? fresh.min / 2 + 1 : fresh.des, | |||||
| budget_ms, &ticket, &timing)) { | |||||
| err = errno; entry->valid = 0; | err = errno; entry->valid = 0; | ||||
| rejections[rejected].rank = i + 1; rejections[rejected].error = err; | |||||
| rejections[rejected].ms = timing.total_ms; | |||||
| rejections[rejected].stage = timing.stage; | |||||
| rejected++; rejected_pid = plan.target.pid; rejected_errno = err; | rejected++; rejected_pid = plan.target.pid; rejected_errno = err; | ||||
| continue; | continue; | ||||
| } | } | ||||
| @@ -747,6 +792,7 @@ retry_candidate: | |||||
| validated = 1; break; | validated = 1; break; | ||||
| } | } | ||||
| if (!validated) { | if (!validated) { | ||||
| log_rejections(rejections, rejected); | |||||
| emit_important(LOG_WARNING, | emit_important(LOG_WARNING, | ||||
| "event=action_blocked reason=%s state=%s scan_complete=%d" | "event=action_blocked reason=%s state=%s scan_complete=%d" | ||||
| " latest_complete_age_ms=%.1f", blocked_reason, | " latest_complete_age_ms=%.1f", blocked_reason, | ||||
| @@ -756,20 +802,23 @@ retry_candidate: | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| if (cfg.armed && stopping) return; | |||||
| timing.cooldown_ms = cooldown_ms; | |||||
| if (cfg.armed && stopping) { validation_release(ticket); return; } | |||||
| if (cfg.armed) { | if (cfg.armed) { | ||||
| rc = platform_signal(&cfg, &plan.target, plan.action, 1, | |||||
| !strcmp(plan.reason, "floor") ? fresh.min / 2 + 1 : fresh.des, | |||||
| &kill_attempt_mono, &kill_return_mono); err = errno; | |||||
| if (!kill_attempt_mono) kill_attempt_mono = monotime(); | |||||
| if (!kill_return_mono) kill_return_mono = monotime(); | |||||
| dispatch_ms = 1000 * (kill_attempt_mono - decision_mono); | |||||
| platform_dispatch(validation_handle(ticket), plan.action, &signal_result); | |||||
| err = signal_result.error; | |||||
| rc = signal_result.rc == (long)(2 * sizeof (long)) ? 0 : -1; | |||||
| kill_attempt_mono = signal_result.attempt; | |||||
| kill_return_mono = signal_result.returned; | |||||
| dispatch_ms = 1000 * (kill_return_mono - decision_mono); | |||||
| kill_ms = 1000 * (kill_return_mono - kill_attempt_mono); | kill_ms = 1000 * (kill_return_mono - kill_attempt_mono); | ||||
| } | } | ||||
| validation_release(ticket); | |||||
| /* State and budgets are memory-only and are updated after the signal attempt. */ | /* State and budgets are memory-only and are updated after the signal attempt. */ | ||||
| action_commit(&controller, &cfg, &fresh, &plan); | action_commit(&controller, &cfg, &fresh, &plan); | ||||
| if (cfg.armed && rc) controller.has_pending = 0; | if (cfg.armed && rc) controller.has_pending = 0; | ||||
| enqueue_start = monotime(); | enqueue_start = monotime(); | ||||
| log_rejections(rejections, rejected); | |||||
| if (rejected) | if (rejected) | ||||
| emit("event=action_rejected reason=identity_or_protection rejected_count=%u" | emit("event=action_rejected reason=identity_or_protection rejected_count=%u" | ||||
| " last_pid=%d last_errno=%d", rejected, rejected_pid, rejected_errno); | " last_pid=%d last_errno=%d", rejected, rejected_pid, rejected_errno); | ||||
| @@ -798,9 +847,12 @@ retry_candidate: | |||||
| alias_for(plan.target.uuid), plan.target.pid, plan.target.name, | alias_for(plan.target.uuid), plan.target.pid, plan.target.name, | ||||
| plan.target.rss_kib, fresh.free, decision_mono, kill_attempt_mono, | plan.target.rss_kib, fresh.free, decision_mono, kill_attempt_mono, | ||||
| kill_return_mono, dispatch_ms); | kill_return_mono, dispatch_ms); | ||||
| emit("event=action_result pid=%d signal=%s result=%s errno=%d", | |||||
| emit("event=action_result pid=%d signal=%s result=%s errno=%d" | |||||
| " syscall=write operation=PCKILL attempted=%d rc=%ld errno_name=%s transport_status=%s", | |||||
| plan.target.pid, plan.action == TERM ? "SIGTERM" : "SIGKILL", | plan.target.pid, plan.action == TERM ? "SIGTERM" : "SIGKILL", | ||||
| rc ? "failed" : "sent", rc ? err : 0); | |||||
| rc ? "failed" : "sent", err, signal_result.attempted, | |||||
| signal_result.rc, signal_errno_name(err), | |||||
| !rc ? "complete" : signal_result.rc < 0 ? "error" : "short_write"); | |||||
| } else { | } else { | ||||
| emit("event=action_decision state=%s candidate_source=%s rank=%u" | emit("event=action_decision state=%s candidate_source=%s rank=%u" | ||||
| " scan_complete=%d candidate_age_ms=%.1f victim_budget_override=%s" | " scan_complete=%d candidate_age_ms=%.1f victim_budget_override=%s" | ||||
| @@ -817,6 +869,16 @@ retry_candidate: | |||||
| plan.target.start_nsec, plan.target.name, plan.target.rss_kib, | plan.target.start_nsec, plan.target.name, plan.target.rss_kib, | ||||
| fresh.free, plan.budget_override); | fresh.free, plan.budget_override); | ||||
| } | } | ||||
| emit("event=candidate_validation pid=%d validate_pid_exists_ms=%.3f" | |||||
| " validate_start_time_ms=%.3f validate_zone_identity_ms=%.3f" | |||||
| " validate_zone_generation_ms=%.3f validate_policy_ms=%.3f" | |||||
| " validate_protected_process_ms=%.3f validate_cooldown_ms=%.3f" | |||||
| " validate_total_ms=%.3f proc_open_ms=%.3f proc_read_ms=%.3f" | |||||
| " proc_parse_ms=%.3f memory_recheck_ms=%.3f budget_ms=%u", | |||||
| plan.target.pid, timing.pid_ms, timing.start_ms, timing.zone_ms, | |||||
| timing.generation_ms, timing.policy_ms, timing.protected_ms, | |||||
| timing.cooldown_ms, timing.total_ms, timing.open_ms, timing.read_ms, | |||||
| timing.parse_ms, timing.memory_ms, budget_ms); | |||||
| enqueue_ms = 1000 * (monotime() - enqueue_start); | enqueue_ms = 1000 * (monotime() - enqueue_start); | ||||
| emit("event=action_timing pid=%d signal=%s candidate_validate_latency_ms=%.3f" | emit("event=action_timing pid=%d signal=%s candidate_validate_latency_ms=%.3f" | ||||
| " kill_latency_ms=%.3f action_dispatch_latency_ms=%.3f" | " kill_latency_ms=%.3f action_dispatch_latency_ms=%.3f" | ||||
| @@ -923,6 +985,7 @@ int main(int argc, char **argv) | |||||
| memset(published_cache, 0, sizeof (published_cache)); | memset(published_cache, 0, sizeof (published_cache)); | ||||
| if (logger_start()) { perror("logger thread initialization"); return 1; } | if (logger_start()) { perror("logger thread initialization"); return 1; } | ||||
| if (scanner_start()) { perror("scanner thread initialization"); return 1; } | if (scanner_start()) { perror("scanner thread initialization"); return 1; } | ||||
| if (validation_start()) { perror("validation pool initialization"); return 1; } | |||||
| if (emit_important(LOG_INFO, | if (emit_important(LOG_INFO, | ||||
| "event=start version=%s pid=%ld mode=%s page_bytes=%ld fixed_storage_bytes=%zu armed_warmup=60", | "event=start version=%s pid=%ld mode=%s page_bytes=%ld fixed_storage_bytes=%zu armed_warmup=60", | ||||
| VERSION, (long)getpid(), cfg.armed ? "armed" : "dry-run", sysconf(_SC_PAGESIZE), | VERSION, (long)getpid(), cfg.armed ? "armed" : "dry-run", sysconf(_SC_PAGESIZE), | ||||
| @@ -0,0 +1,20 @@ | |||||
| #include "guard.h" | |||||
| #include <errno.h> | |||||
| const char *signal_errno_name(int error) | |||||
| { | |||||
| switch (error) { | |||||
| case 0: return "OK"; | |||||
| case ESRCH: return "ESRCH"; | |||||
| case EPERM: return "EPERM"; | |||||
| case EINVAL: return "EINVAL"; | |||||
| case EAGAIN: return "EAGAIN"; | |||||
| case ENOMEM: return "ENOMEM"; | |||||
| case EIO: return "EIO"; | |||||
| case ENOENT: return "ENOENT"; | |||||
| case ESTALE: return "ESTALE"; | |||||
| case ETIMEDOUT: return "ETIMEDOUT"; | |||||
| case EBUSY: return "EBUSY"; | |||||
| case EINTR: return "EINTR"; | |||||
| default: return "UNKNOWN"; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,22 @@ | |||||
| /* Native PCKILL transport; kept small for syscall-level fault injection. */ | |||||
| #include "guard.h" | |||||
| #include <procfs.h> | |||||
| #include <unistd.h> | |||||
| #include <signal.h> | |||||
| #include <errno.h> | |||||
| #include <string.h> | |||||
| void platform_dispatch(int handle, enum action action, signal_result_t *out) | |||||
| { | |||||
| long command[2] = {PCKILL, action == TERM ? SIGTERM : SIGKILL}; | |||||
| ssize_t written; | |||||
| int saved; | |||||
| memset(out, 0, sizeof (*out)); | |||||
| out->attempted = 1; out->attempt = monotime(); | |||||
| errno = 0; | |||||
| written = write(handle, command, sizeof (command)); | |||||
| saved = errno; /* MUST be before clock/log/close or any other call. */ | |||||
| out->rc = (long)written; | |||||
| out->error = written < 0 ? saved : 0; | |||||
| out->returned = monotime(); | |||||
| } | |||||
| @@ -0,0 +1,135 @@ | |||||
| /* Fixed preparation pool. A timed-out worker can never dispatch a signal. */ | |||||
| #include "guard.h" | |||||
| #include <pthread.h> | |||||
| #include <errno.h> | |||||
| #include <string.h> | |||||
| #include <time.h> | |||||
| #include <semaphore.h> | |||||
| #define VALIDATION_SLOTS 16 | |||||
| enum job_state { FREE, RESERVED, QUEUED, RUNNING, READY, CLAIMED, RELEASE, ABANDONED }; | |||||
| typedef struct { | |||||
| volatile int state; | |||||
| sem_t wake; | |||||
| const config_t *config; /* immutable after startup */ | |||||
| process_t expected; | |||||
| int real, handle, result, error; | |||||
| uint64_t ceiling; | |||||
| validation_t timing; | |||||
| } validation_job_t; | |||||
| static validation_job_t jobs[VALIDATION_SLOTS]; | |||||
| static int pool_started; | |||||
| static int state(validation_job_t *j) { return __sync_fetch_and_add(&j->state, 0); } | |||||
| static void *prepare_worker(void *arg) | |||||
| { | |||||
| validation_job_t *j = arg; | |||||
| for (;;) { | |||||
| int wait_rc; | |||||
| do { wait_rc = sem_wait(&j->wake); } while (wait_rc && errno == EINTR); | |||||
| if (wait_rc) return NULL; | |||||
| if (__sync_bool_compare_and_swap(&j->state, QUEUED, RUNNING)) { | |||||
| double begin = monotime(); | |||||
| j->handle = -1; | |||||
| memset(&j->timing, 0, sizeof (j->timing)); | |||||
| errno = 0; | |||||
| j->result = platform_prepare((unsigned)(j - jobs), j->config, &j->expected, j->real, | |||||
| j->ceiling, &j->handle, &j->timing); | |||||
| j->error = j->result ? errno : 0; | |||||
| j->timing.total_ms = 1000 * (monotime() - begin); | |||||
| if (__sync_bool_compare_and_swap(&j->state, RUNNING, READY)) | |||||
| continue; | |||||
| /* Timeout won: discard even a successful preparation. */ | |||||
| validation_late_result(j->expected.pid, &j->timing, j->error); | |||||
| platform_dispose(j->handle); | |||||
| __sync_lock_test_and_set(&j->state, FREE); | |||||
| } else if (__sync_bool_compare_and_swap(&j->state, RELEASE, RESERVED) || | |||||
| __sync_bool_compare_and_swap(&j->state, ABANDONED, RESERVED)) { | |||||
| platform_dispose(j->handle); | |||||
| __sync_lock_test_and_set(&j->state, FREE); | |||||
| } | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| int validation_start(void) | |||||
| { | |||||
| unsigned i; | |||||
| if (pool_started) return 0; | |||||
| if (platform_validation_init(VALIDATION_SLOTS)) return -1; | |||||
| for (i = 0; i < VALIDATION_SLOTS; i++) { | |||||
| pthread_t thread; | |||||
| jobs[i].handle = -1; | |||||
| if (sem_init(&jobs[i].wake, 0, 0)) return -1; | |||||
| if (pthread_create(&thread, NULL, prepare_worker, &jobs[i])) return -1; | |||||
| (void)pthread_detach(thread); | |||||
| } | |||||
| pool_started = 1; | |||||
| return 0; | |||||
| } | |||||
| int validation_acquire(const config_t *c, const process_t *p, int real, | |||||
| uint64_t ceiling, unsigned budget_ms, int *ticket, validation_t *timing) | |||||
| { | |||||
| unsigned i; | |||||
| double begin = monotime(), deadline = begin + budget_ms / 1000.0; | |||||
| const struct timespec pause = {0, 250000}; | |||||
| validation_job_t *j = NULL; | |||||
| memset(timing, 0, sizeof (*timing)); *ticket = -1; | |||||
| if (!pool_started) { errno = ENXIO; return -1; } | |||||
| /* Single caller owns request fields. Do not fill the pool with repeated | |||||
| * attempts on the same stuck PID incarnation after cache refreshes. */ | |||||
| for (i = 0; i < VALIDATION_SLOTS; i++) { | |||||
| const process_t *old = &jobs[i].expected; | |||||
| if (state(&jobs[i]) != FREE && old->pid == p->pid && | |||||
| old->start_sec == p->start_sec && old->start_nsec == p->start_nsec && | |||||
| old->zone_generation == p->zone_generation && !strcmp(old->uuid, p->uuid)) { | |||||
| errno = EBUSY; return -1; | |||||
| } | |||||
| } | |||||
| for (i = 0; i < VALIDATION_SLOTS; i++) | |||||
| if (__sync_bool_compare_and_swap(&jobs[i].state, FREE, RESERVED)) { | |||||
| j = &jobs[i]; break; | |||||
| } | |||||
| if (!j) { errno = EBUSY; return -1; } | |||||
| j->config = c; j->expected = *p; j->real = real; j->ceiling = ceiling; | |||||
| j->handle = -1; | |||||
| __sync_lock_test_and_set(&j->state, QUEUED); | |||||
| (void)sem_post(&j->wake); | |||||
| for (;;) { | |||||
| if (monotime() >= deadline) { | |||||
| int s; | |||||
| do { s = state(j); } | |||||
| while (!__sync_bool_compare_and_swap(&j->state, s, | |||||
| s == READY ? RELEASE : ABANDONED)); | |||||
| if (s == READY) (void)sem_post(&j->wake); | |||||
| timing->total_ms = 1000 * (monotime() - begin); | |||||
| errno = ETIMEDOUT; return -1; | |||||
| } | |||||
| if (__sync_bool_compare_and_swap(&j->state, READY, CLAIMED)) { | |||||
| int error = j->error; | |||||
| *timing = j->timing; | |||||
| timing->total_ms = 1000 * (monotime() - begin); | |||||
| if (j->result) { | |||||
| __sync_lock_test_and_set(&j->state, RELEASE); | |||||
| (void)sem_post(&j->wake); | |||||
| errno = error; return -1; | |||||
| } | |||||
| /* A delayed scheduler must not turn a late READY into authorization. */ | |||||
| if (monotime() >= deadline) { | |||||
| __sync_lock_test_and_set(&j->state, RELEASE); | |||||
| (void)sem_post(&j->wake); | |||||
| errno = ETIMEDOUT; return -1; | |||||
| } | |||||
| *ticket = (int)i; return 0; | |||||
| } | |||||
| (void)nanosleep(&pause, NULL); | |||||
| } | |||||
| } | |||||
| int validation_handle(int ticket) { return jobs[ticket].handle; } | |||||
| void validation_release(int ticket) | |||||
| { | |||||
| if (ticket >= 0 && ticket < VALIDATION_SLOTS) | |||||
| if (__sync_bool_compare_and_swap(&jobs[ticket].state, CLAIMED, RELEASE)) | |||||
| (void)sem_post(&jobs[ticket].wake); | |||||
| } | |||||
| @@ -0,0 +1,4 @@ | |||||
| seconds,free_pages,nscan,event | |||||
| 0,175000,0,normal | |||||
| 1,486,1548386,floor_validation_1283ms_errno11 | |||||
| 2,214354,1548386,recovery_without_candidate_kill | |||||
| @@ -44,7 +44,7 @@ grep -Fq '#define CACHED_CANDIDATES 16' src/main.c | |||||
| grep -Fq '#define EVENT_QUEUE_SIZE 512' src/main.c | grep -Fq '#define EVENT_QUEUE_SIZE 512' src/main.c | ||||
| grep -Fq 'pthread_mutex_trylock(&event_mutex)' src/main.c | grep -Fq 'pthread_mutex_trylock(&event_mutex)' src/main.c | ||||
| grep -Fq 'pthread_mutex_trylock(&scan_mutex)' src/main.c | grep -Fq 'pthread_mutex_trylock(&scan_mutex)' src/main.c | ||||
| signal_line=$(grep -n 'rc = platform_signal' src/main.c | cut -d: -f1) | |||||
| signal_line=$(grep -n ' platform_dispatch' src/main.c | cut -d: -f1) | |||||
| commit_line=$(grep -n 'action_commit(&controller' src/main.c | cut -d: -f1) | commit_line=$(grep -n 'action_commit(&controller' src/main.c | cut -d: -f1) | ||||
| enqueue_line=$(grep -n 'enqueue_start = monotime' src/main.c | cut -d: -f1) | enqueue_line=$(grep -n 'enqueue_start = monotime' src/main.c | cut -d: -f1) | ||||
| test "$signal_line" -lt "$commit_line" | test "$signal_line" -lt "$commit_line" | ||||
| @@ -0,0 +1,115 @@ | |||||
| /* Actual illumos preparation code against API sketches and injected I/O. */ | |||||
| #include "guard.h" | |||||
| #include <sys/types.h> | |||||
| #include <fcntl.h> | |||||
| #include <unistd.h> | |||||
| #include <string.h> | |||||
| #include <errno.h> | |||||
| #include <stdio.h> | |||||
| #include <stdlib.h> | |||||
| static int mock_open(const char *, int, ...); | |||||
| static int mock_openat(int, const char *, int, ...); | |||||
| static ssize_t mock_pread(int, void *, size_t, off_t); | |||||
| static int mock_close(int); | |||||
| #define open mock_open | |||||
| #define openat mock_openat | |||||
| #define pread mock_pread | |||||
| #define close mock_close | |||||
| #include "../src/illumos.c" | |||||
| #undef open | |||||
| #undef openat | |||||
| #undef pread | |||||
| #undef close | |||||
| static unsigned checks; | |||||
| #define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL prepare %d: %s\n", __LINE__, #x); exit(1); } checks++; } while (0) | |||||
| static double now; | |||||
| static psinfo_t ps; | |||||
| static uint64_t generation = 20, available = 486; | |||||
| static int ctl_opens, closed, fail_open, fail_read, fail_generation; | |||||
| static kstat_ctl_t fake_kc; | |||||
| static kstat_t fake_kstat; | |||||
| static kstat_named_t fake_value; | |||||
| static const char *uuid = "11111111-1111-4111-8111-111111111111"; | |||||
| double monotime(void) { return now; } | |||||
| static int mock_open(const char *path, int flags, ...) | |||||
| { (void)path; (void)flags; now += .001; if (fail_open) { errno = ENOMEM; return -1; } return 10; } | |||||
| static int mock_openat(int dir, const char *path, int flags, ...) | |||||
| { | |||||
| (void)dir; (void)flags; now += .002; | |||||
| if (!strcmp(path, "ctl")) { ctl_opens++; return 12; } | |||||
| return 11; | |||||
| } | |||||
| static ssize_t mock_pread(int fd, void *out, size_t n, off_t offset) | |||||
| { | |||||
| (void)fd; (void)offset; now += .003; | |||||
| if (fail_read) { errno = EIO; return -1; } | |||||
| memcpy(out, &ps, n); return (ssize_t)n; | |||||
| } | |||||
| static int mock_close(int fd) | |||||
| { (void)fd; closed++; errno = EINVAL; return 0; } | |||||
| ssize_t getzonenamebyid(zoneid_t zid, char *out, size_t n) | |||||
| { (void)zid; now += .004; snprintf(out, n, "%s", uuid); return 37; } | |||||
| ssize_t zone_getattr(zoneid_t zid, int attr, void *out, size_t n) | |||||
| { | |||||
| (void)zid; now += .005; | |||||
| if (attr == ZONE_ATTR_UNIQID) { | |||||
| if (fail_generation) { errno = EAGAIN; return -1; } | |||||
| memcpy(out, &generation, n); | |||||
| } else { pid_t init = 99; memcpy(out, &init, n); } | |||||
| return (ssize_t)n; | |||||
| } | |||||
| kstat_ctl_t *kstat_open(void) { return &fake_kc; } | |||||
| int kstat_close(kstat_ctl_t *ctl) { (void)ctl; return 0; } | |||||
| int kstat_chain_update(kstat_ctl_t *ctl) { (void)ctl; return 0; } | |||||
| zoneid_t getzoneid(void) { return 0; } | |||||
| int swapctl(int command, void *arg) { (void)command; (void)arg; return -1; } | |||||
| kstat_t *kstat_lookup(kstat_ctl_t *ctl, char *module, int instance, char *name) | |||||
| { (void)ctl; (void)module; (void)instance; (void)name; return &fake_kstat; } | |||||
| int kstat_read(kstat_ctl_t *ctl, kstat_t *k, void *buf) | |||||
| { (void)ctl; (void)k; (void)buf; now += .006; return 0; } | |||||
| void *kstat_data_lookup(kstat_t *k, char *name) | |||||
| { | |||||
| (void)k; (void)name; | |||||
| fake_value.data_type = KSTAT_DATA_UINT64; fake_value.value.ui64 = available; | |||||
| return &fake_value; | |||||
| } | |||||
| int main(void) | |||||
| { | |||||
| config_t c; process_t p; validation_t t; int handle; | |||||
| defaults(&c); c.armed = 1; c.nzones = 1; | |||||
| strcpy(c.zones[0].uuid, uuid); c.zones[0].policy = ALLOW; | |||||
| memset(&ps, 0, sizeof (ps)); ps.pr_pid = 123; ps.pr_ppid = 100; | |||||
| ps.pr_zoneid = 9; ps.pr_nlwp = 1; ps.pr_start.tv_sec = 1000; | |||||
| ps.pr_rssize = 2000000; strcpy(ps.pr_fname, "clamd"); | |||||
| { zone_cache_t z; memset(&z, 0, sizeof (z)); | |||||
| z.initpid = 99; z.generation = 20; strcpy(z.uuid, uuid); convert(&ps, &z, &p); } | |||||
| CHECK(platform_validation_init(16) == 0); | |||||
| memset(&t, 0, sizeof (t)); errno = EAGAIN; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == 0); | |||||
| CHECK(handle == 12 && errno == 0 && ctl_opens == 1 && closed == 2); | |||||
| CHECK(t.open_ms > 4.9 && t.read_ms > 2.9 && t.zone_ms > 3.9); | |||||
| CHECK(t.generation_ms > 4.9 && t.memory_ms > 5.9); | |||||
| platform_dispose(handle); | |||||
| available = 214354; memset(&t, 0, sizeof (t)); | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1); | |||||
| CHECK(handle == -1 && errno == EAGAIN && !strcmp(t.stage, "memory_recovered")); | |||||
| available = 486; ps.pr_start.tv_sec++; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1 && errno == ESTALE); | |||||
| ps.pr_start.tv_sec--; generation++; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1 && errno == ESTALE); | |||||
| generation--; c.zones[0].policy = PROTECT; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1 && errno == EPERM); | |||||
| c.zones[0].policy = ALLOW; fail_open = 1; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1 && errno == ENOMEM); | |||||
| fail_open = 0; fail_read = 1; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1 && errno == EIO); | |||||
| fail_read = 0; fail_generation = 1; | |||||
| CHECK(platform_prepare(0, &c, &p, 1, 24539, &handle, &t) == -1 && errno == EAGAIN); | |||||
| fail_generation = 0; ctl_opens = 0; | |||||
| CHECK(platform_prepare(0, &c, &p, 0, 24539, &handle, &t) == 0); | |||||
| CHECK(handle == -1 && ctl_opens == 0); | |||||
| printf("PASS %u native preparation source checks with mocked proc/kstat/zone I/O; no native ABI claim or signals\n", checks); | |||||
| return 0; | |||||
| } | |||||
| @@ -49,23 +49,38 @@ int platform_walk(int (*fn)(const process_t *, void *), void *arg, unsigned budg | |||||
| for (j = 0; j < nfixtures; j++) if (fn(&fixtures[j], arg)) return -1; | for (j = 0; j < nfixtures; j++) if (fn(&fixtures[j], arg)) return -1; | ||||
| return partial ? -1 : 0; | return partial ? -1 : 0; | ||||
| } | } | ||||
| int platform_signal(const config_t *c, const process_t *p, enum action action, | |||||
| int real, uint64_t ceiling, double *attempt_mono, double *return_mono) | |||||
| static int mock_signal_errno, mock_validation_errno, mock_timeout_pid; | |||||
| static int mock_ticket_pid; | |||||
| int validation_start(void) { return 0; } | |||||
| int validation_handle(int ticket) { return ticket; } | |||||
| void validation_release(int ticket) { (void)ticket; } | |||||
| int validation_acquire(const config_t *c, const process_t *p, int real, | |||||
| uint64_t ceiling, unsigned budget_ms, int *ticket, validation_t *timing) | |||||
| { | { | ||||
| unsigned j; int found = 0; | unsigned j; int found = 0; | ||||
| CHECK(action == TERM || action == KILL); | |||||
| (void)real; (void)ceiling; | |||||
| memset(timing, 0, sizeof (*timing)); | |||||
| CHECK(!protected_process(c, p)); | CHECK(!protected_process(c, p)); | ||||
| for (j = 0; j < nfixtures; j++) | for (j = 0; j < nfixtures; j++) | ||||
| if (fixtures[j].pid == p->pid && same_process(&fixtures[j], p)) { found = 1; break; } | if (fixtures[j].pid == p->pid && same_process(&fixtures[j], p)) { found = 1; break; } | ||||
| if (real) { | |||||
| CHECK(c->armed && fake_sample.free < ceiling); real_requests++; | |||||
| if (attempt_mono) *attempt_mono = fake_now; | |||||
| if (return_mono) *return_mono = fake_now; | |||||
| validation_requests++; | |||||
| if (p->pid == mock_timeout_pid) { | |||||
| fake_now += budget_ms / 1000.0; timing->total_ms = budget_ms; | |||||
| errno = ETIMEDOUT; return -1; | |||||
| } | } | ||||
| else validation_requests++; | |||||
| if (fail_validation || p->pid == invalid_pid || !found) { errno = ESTALE; return -1; } | if (fail_validation || p->pid == invalid_pid || !found) { errno = ESTALE; return -1; } | ||||
| *ticket = p->pid; mock_ticket_pid = p->pid; errno = mock_validation_errno; | |||||
| return 0; /* This test backend cannot send any signal. */ | return 0; /* This test backend cannot send any signal. */ | ||||
| } | } | ||||
| void platform_dispatch(int handle, enum action action, signal_result_t *out) | |||||
| { | |||||
| CHECK(handle == mock_ticket_pid && (action == TERM || action == KILL)); | |||||
| real_requests++; | |||||
| memset(out, 0, sizeof (*out)); out->attempted = 1; | |||||
| out->attempt = out->returned = fake_now; | |||||
| out->rc = mock_signal_errno ? -1 : (long)(2 * sizeof (long)); | |||||
| out->error = mock_signal_errno; | |||||
| } | |||||
| static void reset(void) | static void reset(void) | ||||
| { | { | ||||
| defaults(&cfg); cfg.log_mib = 100; | defaults(&cfg); cfg.log_mib = 100; | ||||
| @@ -88,6 +103,7 @@ static void reset(void) | |||||
| syslog_count = syslog_open_count = syslog_close_count = 0; | syslog_count = syslog_open_count = syslog_close_count = 0; | ||||
| syslog_facility = -1; fail_syslog = 0; syslog_ident[0] = 0; | syslog_facility = -1; fail_syslog = 0; syslog_ident[0] = 0; | ||||
| syslog_delay_seconds = 0; | syslog_delay_seconds = 0; | ||||
| mock_signal_errno = mock_validation_errno = mock_timeout_pid = 0; | |||||
| scan_generation = 0; scan_complete = published_scan_complete = 0; | scan_generation = 0; scan_complete = published_scan_complete = 0; | ||||
| scanner_latest_complete_scan_at = latest_complete_scan_at = 0; | scanner_latest_complete_scan_at = latest_complete_scan_at = 0; | ||||
| published_latest_complete_scan_at = 0; | published_latest_complete_scan_at = 0; | ||||
| @@ -226,6 +242,50 @@ static void critical_path_faults(void) | |||||
| puts("PASS saturated/locked event queue drops telemetry without delaying the signal"); | puts("PASS saturated/locked event queue drops telemetry without delaying the signal"); | ||||
| } | } | ||||
| static void floor_errno_fixture(void) | |||||
| { | |||||
| FILE *f; char line[160], event[80]; | |||||
| unsigned seconds, rows = 0, i, j; | |||||
| uint64_t free_pages, scans; | |||||
| delta_t zero = {0, 0, 0}; | |||||
| const int prior[] = {EAGAIN, ENOMEM}; | |||||
| const int errors[] = {0, ESRCH, EPERM, EINVAL, EAGAIN}; | |||||
| populate_many_candidates(16); cfg.armed = 1; async_logging = 1; | |||||
| engine_init(&engine); | |||||
| f = fopen("tests/fixtures/floor_free_pages_486_2026_09_23.csv", "r"); | |||||
| CHECK(f != NULL && fgets(line, sizeof (line), f) != NULL); | |||||
| while (fscanf(f, "%u,%" SCNu64 ",%" SCNu64 ",%79s", &seconds, | |||||
| &free_pages, &scans, event) == 4) { | |||||
| fake_now = 200 + seconds; fake_sample.at = fake_now; | |||||
| fake_sample.free = free_pages; fake_sample.scan = scans; | |||||
| engine_step(&engine, &cfg, &fake_sample, zero, zero, zero); | |||||
| if (seconds == 1) { | |||||
| CHECK(engine.state == EMERGENCY && engine.floor); | |||||
| mock_timeout_pid = candidate_cache[0].p.pid; | |||||
| act(&fake_sample); | |||||
| CHECK(real_requests == 1 && mock_ticket_pid == candidate_cache[1].p.pid); | |||||
| CHECK(queued_contains("reason=validation_timeout rank=1 latency_ms=50.000")); | |||||
| CHECK(queued_contains("rank=2")); | |||||
| CHECK(fake_now - fake_sample.at < 0.100); | |||||
| } | |||||
| rows++; | |||||
| } | |||||
| fclose(f); CHECK(rows == 3 && engine.state == RECOVERY); | |||||
| for (i = 0; i < 2; i++) for (j = 0; j < 5; j++) { | |||||
| char expected[120]; | |||||
| reset(); cfg.armed = 1; async_logging = 1; | |||||
| mock_validation_errno = prior[i]; mock_signal_errno = errors[j]; | |||||
| act(&fake_sample); | |||||
| snprintf(expected, sizeof (expected), "result=%s errno=%d syscall=write operation=PCKILL attempted=1 rc=%ld errno_name=%s", | |||||
| errors[j] ? "failed" : "sent", errors[j], | |||||
| errors[j] ? -1L : (long)(2 * sizeof (long)), signal_errno_name(errors[j])); | |||||
| CHECK(queued_contains(expected)); | |||||
| CHECK(queued_contains("event=signal_sent") == (errors[j] == 0)); | |||||
| CHECK(queued_contains("validate_start_time_ms=")); | |||||
| } | |||||
| puts("PASS floor486 fixture, 50ms timeout fallback rank1->2, syscall errno attribution and validation substep logs"); | |||||
| } | |||||
| static void load_global_ranking_fixture(void) | static void load_global_ranking_fixture(void) | ||||
| { | { | ||||
| FILE *f; | FILE *f; | ||||
| @@ -447,7 +507,7 @@ int main(void) | |||||
| syslog_open_count == 1); | syslog_open_count == 1); | ||||
| emit_important(LOG_INFO, "event=start version=%s mode=dry-run", VERSION); | emit_important(LOG_INFO, "event=start version=%s mode=dry-run", VERSION); | ||||
| CHECK(syslog_count == 1 && syslog_records[0].priority == LOG_INFO && | CHECK(syslog_count == 1 && syslog_records[0].priority == LOG_INFO && | ||||
| strstr(syslog_records[0].message, "event=start version=1.0.7") != NULL); | |||||
| strstr(syslog_records[0].message, "event=start version=1.0.8") != NULL); | |||||
| log_sample(&fake_sample); scan_processes(0); | log_sample(&fake_sample); scan_processes(0); | ||||
| CHECK(syslog_count == 1); /* High-volume sample/delta/proc/cache events stay local. */ | CHECK(syslog_count == 1); /* High-volume sample/delta/proc/cache events stay local. */ | ||||
| { | { | ||||
| @@ -499,6 +559,7 @@ int main(void) | |||||
| CHECK(strstr(contents, "event=sampling_overrun late_seconds=4.459 state=CRITICAL free_pages=60000") != NULL); | CHECK(strstr(contents, "event=sampling_overrun late_seconds=4.459 state=CRITICAL free_pages=60000") != NULL); | ||||
| puts("PASS selective native syslog ident/facility/severity, exclusions, signal ordering, disable and failure isolation"); | puts("PASS selective native syslog ident/facility/severity, exclusions, signal ordering, disable and failure isolation"); | ||||
| critical_path_faults(); | critical_path_faults(); | ||||
| floor_errno_fixture(); | |||||
| fclose(log); | fclose(log); | ||||
| printf("PASS %u runtime checks; all platform calls mocked, no signals sent\n", checks); | printf("PASS %u runtime checks; all platform calls mocked, no signals sent\n", checks); | ||||
| return 0; | return 0; | ||||
| @@ -0,0 +1,105 @@ | |||||
| /* Real preparation workers and native dispatch code, mocked I/O only. */ | |||||
| #include "guard.h" | |||||
| #include <sys/types.h> | |||||
| #include <time.h> | |||||
| #include <errno.h> | |||||
| #include <stdio.h> | |||||
| #include <stdlib.h> | |||||
| #include <string.h> | |||||
| #include <unistd.h> | |||||
| static unsigned checks; | |||||
| #define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL validation %d: %s\n", __LINE__, #x); exit(1); } checks++; } while (0) | |||||
| static volatile int disposed, gate; | |||||
| static int injected_errno, inherited_errno, calls, poison_clock; | |||||
| static long injected_rc; | |||||
| double monotime(void) | |||||
| { | |||||
| struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); | |||||
| if (__sync_fetch_and_add(&poison_clock, 0)) errno = ENOMEM; | |||||
| return t.tv_sec + t.tv_nsec / 1e9; | |||||
| } | |||||
| static void pause_ms(unsigned ms) | |||||
| { | |||||
| struct timespec t = {ms / 1000, (long)(ms % 1000) * 1000000}; | |||||
| while (nanosleep(&t, &t) && errno == EINTR) { } | |||||
| } | |||||
| int platform_validation_init(unsigned slots) { return slots == 16 ? 0 : -1; } | |||||
| int platform_prepare(unsigned slot, const config_t *c, const process_t *p, | |||||
| int real, uint64_t ceiling, int *handle, validation_t *t) | |||||
| { | |||||
| double start = monotime(); | |||||
| (void)slot; (void)c; (void)real; (void)ceiling; | |||||
| if (p->pid == 1) pause_ms(1283); | |||||
| if (p->pid >= 100) while (__sync_fetch_and_add(&gate, 0)) pause_ms(1); | |||||
| *handle = p->pid; | |||||
| t->read_ms = 1000 * (monotime() - start); | |||||
| errno = EAGAIN; return 0; | |||||
| } | |||||
| void platform_dispose(int handle) | |||||
| { if (handle >= 0) __sync_fetch_and_add(&disposed, 1); } | |||||
| void validation_late_result(int pid, const validation_t *t, int error) | |||||
| { (void)pid; (void)t; (void)error; } | |||||
| static ssize_t injected_write(int fd, const void *buf, size_t n) | |||||
| { | |||||
| (void)fd; (void)buf; (void)n; | |||||
| calls++; errno = injected_errno; return injected_rc; | |||||
| } | |||||
| #define write injected_write | |||||
| #include "../src/signal.c" | |||||
| #undef write | |||||
| #include "../src/validation.c" | |||||
| int main(void) | |||||
| { | |||||
| config_t c; process_t p; validation_t t; signal_result_t r; | |||||
| int ticket, i, j; | |||||
| double start; | |||||
| const int previous[] = {EAGAIN, ENOMEM}; | |||||
| const int errors[] = {0, ESRCH, EPERM, EINVAL, EAGAIN}; | |||||
| memset(&c, 0, sizeof (c)); memset(&p, 0, sizeof (p)); | |||||
| CHECK(validation_start() == 0); | |||||
| p.pid = 1; start = monotime(); | |||||
| CHECK(validation_acquire(&c, &p, 1, 500, 50, &ticket, &t) == -1); | |||||
| CHECK(errno == ETIMEDOUT && ticket == -1); | |||||
| CHECK(monotime() - start < 0.150); | |||||
| CHECK(validation_acquire(&c, &p, 1, 500, 50, &ticket, &t) == -1 && errno == EBUSY); | |||||
| p.pid = 2; | |||||
| CHECK(validation_acquire(&c, &p, 1, 500, 50, &ticket, &t) == 0); | |||||
| CHECK(validation_handle(ticket) == 2 && monotime() - start < 0.200); | |||||
| validation_release(ticket); | |||||
| CHECK(calls == 0); /* A validator, including a late one, cannot signal. */ | |||||
| pause_ms(1350); | |||||
| CHECK(__sync_fetch_and_add(&disposed, 0) == 2 && calls == 0); | |||||
| __sync_lock_test_and_set(&poison_clock, 1); | |||||
| for (i = 0; i < 2; i++) for (j = 0; j < 5; j++) { | |||||
| inherited_errno = previous[i]; injected_errno = errors[j]; | |||||
| injected_rc = injected_errno ? -1 : (long)(2 * sizeof (long)); | |||||
| errno = inherited_errno; | |||||
| platform_dispatch(10, KILL, &r); | |||||
| CHECK(r.attempted && r.rc == injected_rc && r.error == injected_errno); | |||||
| CHECK(r.returned >= r.attempt && r.attempt > 0); | |||||
| } | |||||
| injected_rc = 1; injected_errno = EAGAIN; | |||||
| platform_dispatch(10, KILL, &r); | |||||
| CHECK(r.rc == 1 && r.error == 0); /* short write is not an errno */ | |||||
| injected_rc = (long)(2 * sizeof (long)); injected_errno = EAGAIN; | |||||
| platform_dispatch(10, TERM, &r); | |||||
| CHECK(r.error == 0 && r.rc == injected_rc); | |||||
| __sync_lock_test_and_set(&poison_clock, 0); | |||||
| __sync_lock_test_and_set(&gate, 1); | |||||
| for (i = 0; i < 16; i++) { | |||||
| p.pid = 100 + i; | |||||
| CHECK(validation_acquire(&c, &p, 1, 500, 10, &ticket, &t) == -1); | |||||
| CHECK(errno == ETIMEDOUT); | |||||
| } | |||||
| p.pid = 200; | |||||
| start = monotime(); | |||||
| CHECK(validation_acquire(&c, &p, 1, 500, 50, &ticket, &t) == -1); | |||||
| CHECK(errno == EBUSY && monotime() - start < 0.050); | |||||
| __sync_lock_test_and_set(&gate, 0); pause_ms(50); | |||||
| p.pid = 2; | |||||
| CHECK(validation_acquire(&c, &p, 1, 500, 50, &ticket, &t) == 0); | |||||
| validation_release(ticket); | |||||
| printf("PASS %u validation checks: real 1283ms worker abandoned, fallback, late disposal, pool saturation; actual dispatch code with mocked write; no signals\n", checks); | |||||
| return 0; | |||||
| } | |||||