[packages/rspamd] Up to 4.2.3
arekm
arekm at pld-linux.org
Thu Oct 29 09:42:38 CET 2026
commit 7f78be05f389b96a0b4f44b51ab522749255bde1
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Oct 29 09:30:21 2026 +0100
Up to 4.2.3
Build without jemalloc by default: PLD jemalloc is je_-prefixed, and
-DJEMALLOC_MANGLE mixed glibc and jemalloc allocations, so workers
segfaulted.
rspamd-milter-proxy-uaf.patch | 84 +++++++++++++++++++++++++++++++++++++++++++
rspamd.spec | 12 +++----
2 files changed, 90 insertions(+), 6 deletions(-)
---
diff --git a/rspamd.spec b/rspamd.spec
index 6fc13cb..3e58c4f 100644
--- a/rspamd.spec
+++ b/rspamd.spec
@@ -2,24 +2,26 @@
# Conditional build:
%bcond_without blas # OpenBLAS/CBLAS for neural network acceleration
%bcond_without hyperscan # Hyperscan/Vectorscan fast regexp processing
-%bcond_without jemalloc # jemalloc allocator
+%bcond_with jemalloc # jemalloc allocator, needs jemalloc built without je_ prefix
%bcond_without system_xxhash # system xxhash instead of bundled
%bcond_without system_zstd # system zstd instead of bundled
#
Summary: Fast, free and open-source spam filtering system
Summary(pl.UTF-8): Szybki, wolny system filtrowania spamu
Name: rspamd
-Version: 4.0.0
+Version: 4.2.3
Release: 0.1
License: Apache v2.0
Group: Networking/Daemons
Source0: https://github.com/rspamd/rspamd/archive/%{version}/%{name}-%{version}.tar.gz
-# Source0-md5: cf16e0556c82b7ba749a8035517e8353
+# Source0-md5: d6e8c6c251b1dc5ec51c6ac800bbb969
Source1: %{name}.tmpfiles
Source2: %{name}.init
Source3: %{name}.sysconfig
+Patch0: %{name}-milter-proxy-uaf.patch
URL: https://rspamd.com
BuildRequires: cmake >= 3.15
+BuildRequires: elfutils-devel
BuildRequires: glib2-devel >= 1:2.28
BuildRequires: libarchive-devel >= 3.0.0
BuildRequires: libicu-devel
@@ -78,15 +80,13 @@ regularnych i niestandardowe reguły Lua.
%prep
%setup -q
+%patch -P0 -p1
%{__sed} -i -e '1s,/usr/bin/env perl,/usr/bin/perl,' utils/rspamd_stats.pl utils/mapstats.pl
%build
install -d build
cd build
-CFLAGS="%{rpmcflags}%{?with_jemalloc: -DJEMALLOC_MANGLE}"
-CXXFLAGS="%{rpmcxxflags}%{?with_jemalloc: -DJEMALLOC_MANGLE}"
-export CFLAGS CXXFLAGS
%cmake \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCONFDIR=%{_sysconfdir}/%{name} \
diff --git a/rspamd-milter-proxy-uaf.patch b/rspamd-milter-proxy-uaf.patch
new file mode 100644
index 0000000..c9771cc
--- /dev/null
+++ b/rspamd-milter-proxy-uaf.patch
@@ -0,0 +1,84 @@
+From ae863c335f89ca9bfd4626c8268b1bd7b75485f7 Mon Sep 17 00:00:00 2001
+From: Jens Erat <email at jenserat.de>
+Date: Sat, 24 Oct 2026 11:12:47 +0200
+Subject: [PATCH] [Fix] proxy: fix milter session use-after-free on upstream
+ failure
+
+proxy_send_master_message()'s error path released the proxy session
+unconditionally for milter connections:
+
+ if (session->client_milter_conn) {
+ rspamd_milter_send_action(..., RSPAMD_MILTER_TEMPFAIL);
+ REF_RELEASE(session);
+ }
+
+The release used to be balanced by a REF_RETAIN() in
+proxy_milter_finish_handler(), added in 2c56437e7. Commit 3ae630614
+removed that retain while reworking the nconns accounting but kept the
+release, so on the milter path the base reference of the accepted MTA
+connection is dropped.
+
+The path is reachable when the retry in proxy_backend_master_error_handler()
+cannot select an upstream. With the default token bucket rotation the retry
+passes the failed upstream as `except`, and with a single upstream (the
+default `hosts = "localhost"`) rspamd_upstream_get_token_bucket() returns
+NULL. The proxy then hits the err: block, frees the proxy session, and its
+destructor unrefs the milter session. The milter library's own REF_RELEASE
+in the BODYEOB handler then frees the session while
+rspamd_milter_consume_input() is still using it.
+
+Depending on timing this is a SIGSEGV in rspamd_proxy or a wedged worker
+that stops calling accept(). In the latter case the listen backlog fills
+with unaccepted sockets; the MTA times out and they remain in CLOSE_WAIT.
+Because heartbeats_loss_max defaults to 0 and the proxy port is not
+health-checked, the worker can stay in this state indefinitely.
+
+Both the unbalanced release and the default token bucket rotation are
+present since 4.0.0, so 4.2.3 and master are affected. 3.14 is not: without
+the token bucket, the round-robin retry returns the single alive upstream
+even when it equals `except`.
+
+Do not release the session in proxy_send_master_message()'s error path. The
+async retry path releases it via proxy_client_write_error(), while the direct
+end-of-message path releases it from the QUIT/EOF finish or error callback.
+This keeps exactly one reference per accepted MTA connection.
+
+Add a functional regression test (181_milter_dead_upstream) that forces the
+same err: block by using an upstream without a default, runs two complete
+milter transactions, and expects SMFIR_TEMPFAIL for both. The second
+transaction also verifies that the proxy worker survived the error.
+
+Verified with:
+- patched: new test passes, existing 180_milter suite passes (6/6)
+- unpatched: new test fails, proxy worker SIGSEGVs in
+ rspamd_milter_consume_input()
+- unpatched ASAN: heap-use-after-free (WRITE in
+ rspamd_milter_consume_input(), freed by rspamd_milter_session_dtor())
+- patched ASAN: test passes without a report
+
+Fixes #6333
+---
+
+diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
+index ae45b95e3d..a46999ebad 100644
+--- a/src/rspamd_proxy.c
++++ b/src/rspamd_proxy.c
+@@ -3538,9 +3538,17 @@ proxy_send_master_message(struct rspamd_proxy_session *session)
+
+ err:
+ if (session->client_milter_conn) {
++ /* The session is owned by the milter connection: there is exactly
++ * one reference per accepted MTA connection. Do not release it
++ * here. The async retry path releases it via
++ * proxy_client_write_error(), while the direct end-of-message path
++ * releases it from the QUIT/EOF finish or error callback. Dropping
++ * the last reference here frees both the proxy and the milter
++ * sessions while proxy_backend_master_error_handler() and the
++ * milter library are still using them (use-after-free). It also
++ * closes the socket before the TEMPFAIL below can be written. */
+ rspamd_milter_send_action(session->client_milter_conn,
+ RSPAMD_MILTER_TEMPFAIL);
+- REF_RELEASE(session);
+ }
+ else {
+ rspamd_http_connection_steal_msg(session->client_conn);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/rspamd.git/commitdiff/7f78be05f389b96a0b4f44b51ab522749255bde1
More information about the pld-cvs-commit
mailing list