Debian Codegraph @

doc/exim-security-2025-12-09.1/report.txt

raw
1 From [email protected] Sat Nov 22 02:40:13 2025
2 Subject: Multiple vulnerabilities in Exim 4.99 SQLite integration: SQL
3 injection + heap buffer overflow
4 From: "Fasano, Andrew S. (Fed)" <[email protected]>
5 To: "[email protected]" <[email protected]>
6 Date: Sat, 22 Nov 2025 01:39:46 +0000
7 Return-Path: <[email protected]>
8 Authentication-Results: mx10.schlittermann.de; iprev=pass (cumin.exim.org)
9 smtp.remote-ip=152.53.204.32; spf=permerror smtp.mailfrom=nist.gov;
10 dkim=pass header.d=nist.gov header.s=selector2 header.a=rsa-sha256;
11 dmarc=pass header.from=nist.gov
12 Authentication-Results: exim.org; iprev=pass
13 (mail-northcentralusazon11011052.outbound.protection.outlook.com)
14 smtp.remote-ip=40.107.199.52; spf=pass smtp.mailfrom=nist.gov; dkim=pass
15 header.d=nist.gov header.s=selector2 header.a=rsa-sha256; dmarc=pass
16 header.from=nist.gov; arc=pass (i=1) header.s=arcselector10001
17 arc.oldest-pass=1 smtp.remote-ip=40.107.199.52
18 authentication-results: dkim=none (message not signed)
19 header.d=none;dmarc=none action=none header.from=nist.gov;
20 X-Spam-Score: -2.3 (--)
21 MIME-Version: 1.0
22 Content-Transfer-Encoding: 8bit
23 Content-Type: text/plain; charset=utf-8
24
25 Hello,
26
27 I'm writing to disclose two security vulnerabilities in Exim 4.99's
28 SQLite hints database implementation. One is related to the recently patched
29 CVE-2025-26794 (SQL injection), but the fix doesn't fully address the issue.
30 I've also discovered a new heap buffer overflow vulnerability in the same
31 code path.
32
33 In vulnerable configurations, a remote, unauthenticated attacker can achieve
34 heap corruption. I was unable to develop an end-to-end exploit chain for
35 remote code execution, but it may be possible with further work. I'm reporting
36 this to you immediately upon discovery so you can assess and remediate.
37
38 ================================================================================
39 OVERVIEW
40 ================================================================================
41
42 Two distinct vulnerabilities exist in the SQLite hints database code:
43
44 1. Incomplete SQL injection fix - CVE-2025-26794's patch doesn't escape
45 single quotes
46
47 2. Heap buffer overflow - Unvalidated database field used as array bound (NEW)
48
49 IMPORTANT: Only specific ratelimit configurations expose these vulnerabilities.
50
51 ================================================================================
52 VULNERABILITY #1: SQL INJECTION VIA RATELIMIT KEY (SAME ROOT CAUSE AS CVE-2025-26794)
53 ================================================================================
54
55 Related to: CVE-2025-26794 (same vulnerable code, different attack vector)
56 CWE: CWE-89
57
58 --------------------------------------------------------------------------------
59 Background
60 --------------------------------------------------------------------------------
61
62 CVE-2025-26794 was assigned for SQL injection via ETRN commands when SQLite
63 hints are used. That vulnerability was fixed by hashing ETRN input before
64 using it as a database key. However, the underlying SQL injection primitive in
65 xtextencode() was not fixed, and the commit message noted: "The hints db
66 remains injectable, in case of USE_SQLITE."
67
68 This report documents a separate attack vector exploiting the same vulnerable
69 code via ratelimit ACLs, which warrants a new CVE as it affects different
70 configurations and users.
71
72 --------------------------------------------------------------------------------
73 Technical Details
74 --------------------------------------------------------------------------------
75
76 The xtextencode() function sanitizes database keys before SQL query
77 construction, but doesn't handle single quotes (ASCII 39):
78
79 // xtextencode.c:35-37<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/xtextencode.c#L35-L37>
80 for(uschar ch; len > 0; len--, clear++)
81 g = (ch = *clear) < 33 || ch > 126 || ch '+' || ch '='
82 ? string_fmt_append(g, "+%.02X", ch) // Only encodes: <33, >126, +, =
83 : string_catn(g, clear, 1); // Single quote (39) passes through!
84
85 This encoded key is directly interpolated into SQL:
86
87 // hints_sqlite.h:129<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/hintsdb/hints_sqlite.h#L129>
88 # define FMT "SELECT dat FROM tbl WHERE ky = '%s';"
89 // hints_sqlite.h:137, 153<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/hintsdb/hints_sqlite.h#L137-L153>
90 encoded_key = xtextencode(key->data, key->len);
91 qry = string_sprintf(FMT, encoded_key); // No escaping!
92
93 --------------------------------------------------------------------------------
94 Exploitation
95 --------------------------------------------------------------------------------
96
97 An attacker can inject SQL via quoted SMTP addresses:
98
99 MAIL FROM:<"x'/**/UNION/**/SELECT/**/X'<hex_blob>'--"@attacker.com>
100
101 The single quote breaks out of the SQL string context, allowing arbitrary
102 queries including returning attacker-controlled binary blobs.
103
104 --------------------------------------------------------------------------------
105 Configuration Requirement
106 --------------------------------------------------------------------------------
107
108 This is only exploitable when attacker-controlled data flows into the database
109 key. For ratelimit ACLs, this happens when:
110
111 - Using an explicit key parameter:
112 ratelimit = 100 / 1h / per_rcpt / $sender_address
113
114 - Using per_addr with an explicit key:
115 ratelimit = 100 / 1h / per_addr / $sender_address
116
117 - Using unique= with attacker data:
118 ratelimit = 100 / 1h / per_rcpt / unique=$sender_address
119
120 NOT VULNERABLE: Default per_addr (without explicit key) uses client IP
121 address, which isn't attacker-controlled via SMTP.
122
123 --------------------------------------------------------------------------------
124 Remediation
125 --------------------------------------------------------------------------------
126
127 Add single quote escaping to xtextencode():
128
129 case '\'':
130 g = string_catn(g, US"+27", 3);
131 break;
132
133 Alternatively (preferred), migrate to parameterized queries throughout the
134 SQLite integration.
135
136 ================================================================================
137 VULNERABILITY #2: HEAP BUFFER OVERFLOW VIA UNVALIDATED DATABASE FIELD
138 ================================================================================
139
140 CWE: CWE-122, CWE-787, CWE-843
141
142 --------------------------------------------------------------------------------
143 Technical Details
144 --------------------------------------------------------------------------------
145
146 Database records are cast directly to internal structures without validation:
147
148 // acl.c:2666<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/acl.c#L2666>
149 dbdb = dbfn_read_with_length(dbm, key, &dbdb_size);
150 // acl.c:2671-2675<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/acl.c#L2671-L2675>
151 if (dbdb)
152 {
153 /* Locate the basic ratelimit block inside the DB data. */
154 HDEBUG(D_acl) debug_printf_indent("ratelimit found key in database\n");
155 dbd = &dbdb->dbd; // Direct cast, trusting database content
156
157 The structure definition:
158 // hintsdb_structs.h:142-147<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/hintsdb_structs.h#L142-L147>
159 typedef struct {
160 dbdata_ratelimit dbd;
161 time_t bloom_epoch; // 8 bytes
162 unsigned bloom_size; // 4 bytes - ATTACKER CONTROLLED
163 uschar bloom[40]; // Fixed 40 bytes, but bloom_size can be larger!
164 } dbdata_ratelimit_unique;
165
166 No validation occurs to ensure bloom_size matches the actual array size. This
167 value is then used directly as an array bound in the bloom filter code:
168
169 // acl.c:2798-2808<https://github.com/Exim/exim/blob/1fd121860e713f4d2783be54939b92a297a82dd4/src/src/acl.c#L2798-L2808>
170 seen = TRUE;
171 for (n = 0; n < 8; n++, hash += hinc)
172 {
173 int bit = 1 << (hash % 8);
174 int byte = (hash / 8) % dbdb->bloom_size; // bloom_size from DB, not validated!
175 if ((dbdb->bloom[byte] & bit) == 0)
176 {
177 dbdb->bloom[byte] |= bit; // HEAP BUFFER OVERFLOW!
178 seen = FALSE;
179 }
180 }
181
182 The bloom array is declared as 40 bytes, but if bloom_size is set to a large
183 value, writes can occur far beyond the allocated buffer.
184
185 --------------------------------------------------------------------------------
186 Configuration Requirement
187 --------------------------------------------------------------------------------
188
189 The bloom filter code only executes when a unique value is set. The unique parameter
190 is set either:
191 1. Explicitly: unique=$sender_address
192 2. Implicitly via per_addr mode in RCPT context (sets unique to recipient)
193
194 NOT VULNERABLE: Ratelimit ACLs without unique= or per_addr never enter the
195 bloom filter code.
196
197 --------------------------------------------------------------------------------
198 Exploitation
199 --------------------------------------------------------------------------------
200
201 Using the SQL injection from vulnerability #1, an attacker injects an 80-byte
202 blob with bloom_size set to values far exceeding the actual 40-byte allocation
203 (e.g., 1505996). When the bloom filter code executes, this oversized value is
204 used as the modulo bound for calculating array indexes:
205
206 int byte = (hash / 8) % dbdb->bloom_size; // If bloom_size = 1505996...
207 dbdb->bloom[byte] |= bit; // ...writes up to 1.5MB past buffer
208
209 The write offset is determined by the MD5 hash of the unique value:
210
211 hash = first_4_bytes(MD5(unique_value));
212 byte_offset = (hash / 8) % bloom_size;
213 bit_value = 1 << (hash % 8);
214 bloom[byte_offset] |= bit_value;
215
216 This provides:
217 - Controlled offset: Choose recipient addresses to target specific heap
218 locations
219 - Bit-level control: Each recipient performs a bitwise OR operation
220 - Arbitrary byte values: Multiple recipients can OR together to construct
221 0x00-0xFF
222
223 --------------------------------------------------------------------------------
224 Proof of Concept Results
225 --------------------------------------------------------------------------------
226
227 I successfully demonstrated:
228 - Using bloom_size = 1505996 (37,649x larger than the 40-byte array)
229 - Targeting specific heap offsets by pre-computing recipient addresses with
230 desired MD5 hashes
231 - Writing arbitrary byte values through multiple recipients that OR together
232 - Reliable crash oracle distinguishing valid vs. invalid heap addresses
233
234 --------------------------------------------------------------------------------
235 Why RCE Wasn't Achieved
236 --------------------------------------------------------------------------------
237
238 The theoretical exploitation path involves corrupting SQLite internal
239 structures to gain arbitrary write capability, then overwriting GOT entries
240 to hijack control flow. However, this requires knowledge of PIE base, libc
241 base, and heap addresses to defeat ASLR/PIE. I couldn't find a reliable
242 information leak to get around this. But it may be possible.
243
244 --------------------------------------------------------------------------------
245 Remediation
246 --------------------------------------------------------------------------------
247
248 Validate database records before using their contents:
249
250 if (dbdb_size < sizeof(dbdata_ratelimit_unique))
251 {
252 log_write(0, LOG_MAIN, "ratelimit: invalid record size %d", dbdb_size);
253 dbdb = NULL;
254 }
255 else if (dbdb->bloom_size == 0 || dbdb->bloom_size > sizeof(dbdb->bloom))
256 {
257 HDEBUG(D_acl)
258 debug_printf_indent("ratelimit: invalid bloom_size %u (max %zu)\n",
259 dbdb->bloom_size, sizeof(dbdb->bloom));
260 log_write(0, LOG_MAIN, "ratelimit: bloom_size %u exceeds maximum %zu",
261 dbdb->bloom_size, sizeof(dbdb->bloom));
262 dbdb->bloom_size = sizeof(dbdb->bloom); // Clamp to safe value
263 dbdb->bloom_epoch = 0; // Invalidate bloom filter
264 seen = FALSE;
265 }
266
267 ================================================================================
268 AFFECTED CONFIGURATIONS
269 ================================================================================
270
271 --------------------------------------------------------------------------------
272 Compilation Requirement
273 --------------------------------------------------------------------------------
274
275 Exim must be compiled with SQLite support (USE_SQLITE=yes and
276 hints_database = sqlite in configuration).
277
278 --------------------------------------------------------------------------------
279 Exploitable Configurations
280 --------------------------------------------------------------------------------
281
282 The full vulnerability chain requires BOTH conditions:
283
284 Condition 1: Attacker data used in ratelimit database key (for SQL injection)
285 Condition 2: Bloom filter triggered (for heap overflow)
286
287 Examples:
288
289 EXPLOITABLE - per_addr with explicit key:
290
291 warn ratelimit = 100 / 1h / per_addr / $sender_address
292
293 [✓] Sender address goes into key (SQL injection)
294 [✓] Recipient address triggers bloom filter (heap overflow)
295
296 EXPLOITABLE - explicit unique with attacker data:
297
298 warn ratelimit = 100 / 1h / per_rcpt / unique=$sender_address
299
300 [✓] Sender address goes into key (SQL injection)
301 [✓] Sender address triggers bloom filter (heap overflow)
302
303 NOT EXPLOITABLE - default per_addr:
304
305 warn ratelimit = 100 / 1h / per_addr
306
307 [✗] Client IP in key (not attacker-controlled via SMTP)
308 [✓] Recipient address triggers bloom filter
309 Result: Heap overflow reachable but can't inject malicious blob
310
311 NOT EXPLOITABLE - per_rcpt without unique:
312
313 deny ratelimit = 50 / 1h / per_rcpt
314
315 [✗] No unique parameter (bloom filter never runs)
316 Result: Even with SQL injection, no heap overflow
317
318 NOT EXPLOITABLE - per_mail:
319
320 accept ratelimit = 10 / 1h / per_mail
321
322 [✗] No unique parameter (bloom filter never runs)
323 Result: Even with SQL injection, no heap overflow
324
325 --------------------------------------------------------------------------------
326 Key Construction
327 --------------------------------------------------------------------------------
328
329 The database key is built from configuration parameters:
330
331 key = string_sprintf("%s/%s/%s%s",
332 sender_rate_period,
333 ratelimit_option_string[mode],
334 unique == NULL ? "" : "unique/",
335 key);
336
337 With ratelimit = 100 / 1h / per_addr / $sender_address, the key becomes:
338
339 1h/per_rcpt/unique/"x'UNION SELECT..."@attacker.com
340 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
341 Attacker-controlled
342
343 With ratelimit = 100 / 1h / per_addr (no explicit key), it becomes:
344
345 1h/per_rcpt/unique/192.168.1.100
346 ^^^^^^^^^^^^^
347 Client IP (not attacker-controlled)
348
349 --------------------------------------------------------------------------------
350 Real-World Impact
351 --------------------------------------------------------------------------------
352
353 I successfully tested the exploit against the per_addr / $sender_address pattern.
354
355 The vulnerabilities require specific configuration, but these patterns are
356 not unreasonable for production deployments. Administrators using ratelimit
357 with sender-based keys for granular rate limiting would be affected.
358
359 ================================================================================
360 CVE ASSIGNMENT RECOMMENDATIONS
361 ================================================================================
362
363 I recommend two new CVEs:
364
365 1. SQL Injection via Ratelimit (NEW) - Same root cause as CVE-2025-26794 but
366 different attack vector. Requires ratelimit ACLs with attacker-controlled
367 keys (e.g., $sender_address). The fix for CVE-2025-26794 addressed ETRN
368 specifically and does not protect ratelimit configurations.
369
370 2. Heap Buffer Overflow (NEW) - Unvalidated database field used as array
371 bound, requires validation of bloom_size before use.
372
373 ================================================================================
374 DISCLOSURE TIMELINE
375 ================================================================================
376
377 I'm disclosing this immediately upon discovery. I will not publish details
378 publicly until the following conditions are met, or 60 days have passed.
379
380 - You've had adequate time to develop and test patches
381 - We agree on a coordinated disclosure date
382 - CVEs are assigned (if appropriate)
383
384 I'm happy to provide additional technical details, testing assistance, or
385 clarification on any points.
386
387 Thank you for maintaining Exim. I look forward to working with you on
388 remediation.
389
390 Thanks,
391 Andrew
392
393
394
395 –
396
397 Andrew Fasano, PhD
398
399 Cyber Lead
400 Center for AI Standards and Innovation (CAISI)
401 National Institute of Standards and Technology
402 U.S. Department of Commerce