setconfig: fix crash when a configvar outlives its plugin option - #9386
Closed
ksedgwic wants to merge 1 commit into
Closed
setconfig: fix crash when a configvar outlives its plugin option#9386ksedgwic wants to merge 1 commit into
ksedgwic wants to merge 1 commit into
Conversation
configvar_finalize_overrides() dereferences the result of opt_find_long() without checking for NULL. A configvar can outlive its option: stopping a plugin unregisters the plugin's options, but destroy_plugin_opt() only removes configvars created by `plugin start` parameters. A configvar created by an earlier setconfig, or read from a config file at boot, stays in memory naming an option that is no longer registered. Once such a stale configvar exists, the next setconfig of ANY option (builtin or plugin, persistent or transient) walks all configvars in configvar_finalize_overrides() and crashes: common/configvar.c:112 (configvar_finalize_overrides) lightningd/configs.c:337 (configvar_updated) lightningd/configs.c:530 (configvar_save) lightningd/configs.c:600 (setconfig_success) lightningd/configs.c:804 (json_setconfig) Observed in the field when a plugin was dynamically restarted as a newer build that dropped one of its options; the first setconfig after the restart killed lightningd. Skip configvars whose option is no longer registered: they override nothing. (This also avoids two such stale configvars falsely marking each other overridden, since both would map to NULL.) Changelog-Fixed: lightningd: crash on `setconfig` after a dynamically restarted plugin dropped an option.
Collaborator
|
Duplicate of #9249 |
Collaborator
|
Please let me know If any of your tests should be included in #9249, which was originally just a repro test PR. |
Collaborator
Author
|
The test comes at it from a different code path, but doesn't add any coverage over what you've got so I don't think it's worth very much |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A configvar from a config file or an earlier setconfig outlives its
option when a plugin stops: destroy_plugin_opt() only removes
plugin start configvars. The next setconfig of any option then
NULL-derefs in configvar_finalize_overrides(). Seen in the field
after a routine dynamic plugin upgrade that dropped an option.
NULL-guard the lookup and add a pytest reproducing the crash
(lightningd SIGSEGVs on the test without the fix).
Fixes #9385