diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2025-08-16 10:54:14 +0200 |
---|---|---|
committer | Dimitri Staessens <dimitri@ouroboros.rocks> | 2025-08-23 10:13:33 +0200 |
commit | 575adac4acacf7d02395df0322ff5f03b7b82aaf (patch) | |
tree | f5de69d4f3599f2be0a075b9a9e1af52a9754ad5 /src/irmd/main.c | |
parent | d0b9463a9e52332b8b0b856d2f9773bbb5d42433 (diff) | |
download | ouroboros-575adac4acacf7d02395df0322ff5f03b7b82aaf.tar.gz ouroboros-575adac4acacf7d02395df0322ff5f03b7b82aaf.zip |
ipcpd: Fix request handling at shutdown
The IPCP states were not entirely correct causing some operations to
be serviced during shutdown. This caused some use-after-free in the
pff. States in the IPCP are now correctly set. IRMd states updated to
the same strategy. The IRMd registry tracks if the IPCP was ENROLLED
or BOOTSTRAPPED, the IPCP just goes to OPERATIONAL.
IPCP state diagram::
NULL -> init() -> INIT -> start() -> BOOT ->
bootstrap/enroll() -> OPERATIONAL -> shutdown()
-> SHUTDOWN -> stop_components() -> BOOT ->
stop() -> INIT -> fini() -> NULL
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index e799666f..6fa6ad02 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -80,6 +80,7 @@ enum irm_state { IRMD_NULL = 0, + IRMD_INIT, IRMD_RUNNING, IRMD_SHUTDOWN }; @@ -234,7 +235,7 @@ static pid_t spawn_ipcp(struct ipcp_info * info) } info->pid = pid; - info->state = IPCP_BOOT; + info->state = IPCP_INIT; return 0; } @@ -337,7 +338,7 @@ int bootstrap_ipcp(pid_t pid, goto fail; } - info.state = IPCP_BOOTSTRAPPED; + info.state = IPCP_BOOT; if (reg_set_layer_for_ipcp(&info, &layer) < 0) { log_err("Failed to set layer info for IPCP."); @@ -369,6 +370,8 @@ int enroll_ipcp(pid_t pid, goto fail; } + info.state = IPCP_BOOT; + if (reg_set_layer_for_ipcp(&info, &layer) < 0) { log_err("Failed to set layer info for IPCP."); goto fail; @@ -2303,6 +2306,9 @@ static int irm_init(void) gcry_control(GCRYCTL_INITIALIZATION_FINISHED); #endif + + irmd_set_state(IRMD_INIT); + return 0; #ifdef HAVE_LIBGCRYPT @@ -2343,7 +2349,7 @@ static void irm_fini(void) struct timespec wait = TIMESPEC_INIT_MS(1); int retries = 5; #endif - if (irmd_get_state() != IRMD_NULL) + if (irmd_get_state() != IRMD_INIT) log_warn("Unsafe destroy."); pthread_mutex_lock(&irmd.auth.mtx); @@ -2394,6 +2400,8 @@ static void irm_fini(void) log_err("Failed to remove " FUSE_PREFIX); #endif assert(list_is_empty(&irmd.cmds)); + + irmd.state = IRMD_NULL; } static void usage(void) @@ -2409,11 +2417,11 @@ static void usage(void) static int irm_start(void) { + irmd_set_state(IRMD_RUNNING); + if (tpm_start(irmd.tpm)) goto fail_tpm_start; - irmd_set_state(IRMD_RUNNING); - if (pthread_create(&irmd.irm_sanitize, NULL, irm_sanitize, NULL)) goto fail_irm_sanitize; @@ -2428,9 +2436,9 @@ static int irm_start(void) pthread_cancel(irmd.irm_sanitize); pthread_join(irmd.irm_sanitize, NULL); fail_irm_sanitize: - irmd_set_state(IRMD_NULL); tpm_stop(irmd.tpm); fail_tpm_start: + irmd_set_state(IRMD_INIT); return -1; } @@ -2471,7 +2479,7 @@ static void irm_stop(void) tpm_stop(irmd.tpm); - irmd_set_state(IRMD_NULL); + irmd_set_state(IRMD_INIT); } static void irm_argparse(int argc, |