Page MenuHomeFreeBSD

init: fix shutdown race
ClosedPublic

Authored by corvink on Aug 26 2022, 9:23 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 19, 3:21 PM
Unknown Object (File)
Sep 25 2024, 3:39 PM
Unknown Object (File)
Sep 7 2024, 1:51 PM
Unknown Object (File)
Sep 3 2024, 2:01 PM
Unknown Object (File)
Sep 3 2024, 11:06 AM
Unknown Object (File)
Aug 17 2024, 9:40 PM
Unknown Object (File)
Aug 17 2024, 11:18 AM
Unknown Object (File)
Aug 5 2024, 10:20 AM

Details

Summary

When calling shutdown, shutdown sends a signal to init and exits. This
causes a race condition for the waitpid function. If the signal wins the
race, wpid will be set to -1 and init calls death_single. If shutdown
wins the race, wpid will be set to the pid of the shutdown process and
the requested_transition will be ignored.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

corvink added subscribers: rgrimes, trasz, des.

@trasz @imp @des @rgrimes I add you as reviewer because I found you in the git history.

The single_user function checks for requested_transition in it's while condition:

do {
  ...
} while (wpid != pid && !requested_transition);

if (requested_transition)
  return (state_funct_t) requested_transition

Does it make sense to use it here too?

how does this fix the rate?

The race is still there. However, it's not an issue any more. This patch checks requested_transition on each exit of waitpid and not only when the signal wins the race (wpid == -1).

Ah, it makes the race not matter. I think I understand and I agree that the change is good.

This revision is now accepted and ready to land.Sep 5 2022, 8:04 PM
This revision was automatically updated to reflect the committed changes.