SECURITY: Avoid integer overflow on too many recipients
authorPhil Pennock <phil+git@pennock-tech.com>
Fri, 30 Oct 2020 01:48:05 +0000 (21:48 -0400)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Tue, 27 Apr 2021 22:40:24 +0000 (00:40 +0200)
(cherry picked from commit 323ff55e67b44e95f9d3cfaba155e385aa33c4bd)

doc/doc-txt/ChangeLog
src/src/receive.c

index 055b1ace82d1575b371eb65de6447c0d6691fc35..3bb5326cef9a42da7eb3ae6546c50fa4bab422fc 100644 (file)
@@ -191,6 +191,11 @@ PP/07 Refuse to allocate too little memory, block negative/zero allocations.
 
 PP/08 Change default for recipients_max from unlimited to 50,000.
 
+PP/09 Fix security issue with too many recipients on a message (to remove a
+      known security problem if someone does set recipients_max to unlimited,
+      or if local additions add to the recipient list).
+      Fixes CVE-2020-RCPTL reported by Qualys.
+
 
 Exim version 4.94
 -----------------
index ec90e93cdce03216b496f4a069bcb7c27a763ffb..ba6a8d3a61fcbbc020ddae0f74e33e8ad72c7998 100644 (file)
@@ -485,11 +485,18 @@ Returns:      nothing
 void
 receive_add_recipient(uschar *recipient, int pno)
 {
+/* XXX This is a math limit; we should consider a performance/sanity limit too. */
+const int safe_recipients_limit = INT_MAX / sizeof(recipient_item) - 1;
+
 if (recipients_count >= recipients_list_max)
   {
   recipient_item *oldlist = recipients_list;
   int oldmax = recipients_list_max;
   recipients_list_max = recipients_list_max ? 2*recipients_list_max : 50;
+  if ((recipients_list_max >= safe_recipients_limit) || (recipients_list_max < 0))
+    {
+    log_write(0, LOG_MAIN|LOG_PANIC, "Too many recipients needed: %d not satisfiable", recipients_list_max);
+    }
   recipients_list = store_get(recipients_list_max * sizeof(recipient_item), FALSE);
   if (oldlist != NULL)
     memcpy(recipients_list, oldlist, oldmax * sizeof(recipient_item));