Skip to content

Fix invalid access of freed log-writer cfg#5445

Merged
HofiOne merged 2 commits intosyslog-ng:developfrom
beni-atlnz:log-writer-cfg-bug
Sep 1, 2025
Merged

Fix invalid access of freed log-writer cfg#5445
HofiOne merged 2 commits intosyslog-ng:developfrom
beni-atlnz:log-writer-cfg-bug

Conversation

@beni-atlnz
Copy link
Contributor

@beni-atlnz beni-atlnz commented Aug 28, 2025

Description

Reloading syslog-ng after a config change caused syslog-ng to crash. During the main_loop_reload_config_apply the cfg is de-initialized and freed, however in afprogram_dd_deinit the log writer is stored afprogram_dd_store_reload_store_item before the cfg is freed. The log writer is then restored and the cfg it points to no longer exists. When log_pipe_init or log_pipe_deinit calls cfg_tree_register_initialized_pipe for the log_writer this results in an invalid read, causing a seg fault crashing syslog-ng.

See here: #5444

Implementation

To prevent the crash, when the log-writer is stored before the reload takes place the stored log-writer's pointer to the cfg is released. When the log-writer is restored, the cfg is set to the new cfg.

Alternative fixes were considered, such as always creating a new log-writer on reload. However, as the log-writer is being stored, it must be required that the log-writer be persistent after the reload.

Testing

This fix was tested by following the reproduction method outlined in #5444. Observing that valgrind did not detect an invalid read after using syslog-ng-ctl reload. No syslog-ng crashes have been observed with this patch applied.

Fixes: #5444

@kira-syslogng
Copy link
Contributor

Can one of the admins verify this patch?

1 similar comment
@kira-syslogng
Copy link
Contributor

Can one of the admins verify this patch?

@HofiOne
Copy link
Collaborator

HofiOne commented Aug 28, 2025

@beni-atlnz could you please fix the commits-check issue (you can ignore the fedore-rawhide problems for now), thanks

@HofiOne
Copy link
Collaborator

HofiOne commented Aug 28, 2025

@beni-atlnz what would you say to this version instead?

afprog.c

I think the responsibility belongs at a slightly higher level. Basically, it does the same as what you did, but at a more appropriate level.

@beni-atlnz
Copy link
Contributor Author

@HofiOne the version you have supplied is a great fix for this issue. I think that that is a suitable place to be setting and resetting the cfg of the log writer.

@HofiOne
Copy link
Collaborator

HofiOne commented Aug 29, 2025

@HofiOne the version you have supplied is a great fix for this issue. I think that that is a suitable place to be setting and resetting the cfg of the log writer.

@beni-atlnz Could you please apply that version to this PR? You can use it freely.

The cfg stored by a log-writer is freed in cfg deinitialization and then
accessed in the cfg reinitialisation. This patch sets the stored cfg of
the log writer to NULL and sets the cfg to the new cfg when restored.

See here: syslog-ng#5444

Signed-off-by: Benjamin Ireland <[email protected]>
Signed-off-by: Benjamin Ireland <[email protected]>
@HofiOne HofiOne marked this pull request as ready for review September 1, 2025 07:29
@HofiOne HofiOne merged commit 304069c into syslog-ng:develop Sep 1, 2025
29 of 30 checks passed
@HofiOne
Copy link
Collaborator

HofiOne commented Sep 1, 2025

@beni-atlnz Thank you, and thanks for your signal too!

@kovgeri01 kovgeri01 mentioned this pull request Sep 22, 2025
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.

Invalid access of syslog-ng cfg causes crash

3 participants