From 22edd69503fc5985cd85160ddae7b57e64296a1e Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Wed, 4 Sep 2024 02:54:09 +0000 Subject: [PATCH] smbd: improve reinit_after_fork error handling reinit_after_fork() may panic or return an error on failure. When smbd is started in interactive mode, it ignores the reinit_after_fork() return status and unconditionally proceeds to smbd_process(). Similarly, if messaging_reinit() fails within reinit_after_fork() then it will subsequently call ctdb_async_ctx_reinit() if clustering is enabled. There's no reason why these errors shouldn't be handled immediately, so add appropriate error handling. Found by code inspection; not seen in the wild. Signed-off-by: David Disseldorp Reviewed-by: Ralph Boehme Autobuild-User(master): David Disseldorp Autobuild-Date(master): Wed Sep 4 09:53:01 UTC 2024 on atb-devel-224 --- source3/lib/util.c | 1 + source3/smbd/server.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source3/lib/util.c b/source3/lib/util.c index 5561aa815ce..2e7cf649ebe 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -482,6 +482,7 @@ NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx, if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("messaging_reinit() failed: %s\n", nt_errstr(status))); + goto done; } if (lp_clustering()) { diff --git a/source3/smbd/server.c b/source3/smbd/server.c index e9ba7be9166..b43d654d6a5 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -976,7 +976,13 @@ static void smbd_accept_connection(struct tevent_context *ev, smb_set_close_on_exec(fd); if (s->parent->interactive) { - reinit_after_fork(msg_ctx, ev, true); + NTSTATUS status; + + status = reinit_after_fork(msg_ctx, ev, true); + if (!NT_STATUS_IS_OK(status)) { + exit_server("reinit_after_fork() failed"); + return; + } smbd_process(ev, msg_ctx, fd, true); exit_server_cleanly("end of interactive mode"); return;