Skip to content

setconfig: fix crash when a configvar outlives its plugin option - #9386

Closed
ksedgwic wants to merge 1 commit into
ElementsProject:masterfrom
ksedgwic:setconfig-dropped-option-segv
Closed

setconfig: fix crash when a configvar outlives its plugin option#9386
ksedgwic wants to merge 1 commit into
ElementsProject:masterfrom
ksedgwic:setconfig-dropped-option-segv

Conversation

@ksedgwic

@ksedgwic ksedgwic commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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

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.
@daywalker90

Copy link
Copy Markdown
Collaborator

Duplicate of #9249

@daywalker90 daywalker90 marked this as a duplicate of #9249 Aug 6, 2026
@daywalker90 daywalker90 closed this Aug 6, 2026
@daywalker90

Copy link
Copy Markdown
Collaborator

Please let me know If any of your tests should be included in #9249, which was originally just a repro test PR.

@ksedgwic

ksedgwic commented Aug 6, 2026

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lightningd crashes (SIGSEGV) on any setconfig after a dynamically restarted plugin drops an option

2 participants