]> git.ipfire.org Git - thirdparty/postfix.git/commitdiff
postfix-3.9-20231219
authorWietse Venema <wietse@porcupine.org>
Tue, 19 Dec 2023 05:00:00 +0000 (00:00 -0500)
committerViktor Dukhovni <ietf-dane@dukhovni.org>
Wed, 20 Dec 2023 18:20:18 +0000 (13:20 -0500)
14 files changed:
postfix/HISTORY
postfix/html/postconf.5.html
postfix/html/smtpd.8.html
postfix/man/man5/postconf.5
postfix/man/man8/smtpd.8
postfix/mantools/postlink
postfix/proto/postconf.proto
postfix/proto/stop
postfix/proto/stop.double-history
postfix/src/global/mail_params.h
postfix/src/global/mail_version.h
postfix/src/global/smtp_stream.c
postfix/src/global/smtp_stream.h
postfix/src/smtpd/smtpd.c

index d57557f5ecba8542fb7e5382a46d1d1aa1e88c06..f4d9255126220e202870cc13bd713e495eace190 100644 (file)
@@ -27630,3 +27630,13 @@ Apologies for any names omitted.
        cleanup/cleanup_milter.c, cleanup/Makefile.in,
        cleanup/test-queue-file18, cleanup/cleanup_milter.in18[a-d],
        cleanup/cleanup_milter.ref18[a-d][12].
+
+20231219
+
+       Protocol enforcement: with "smtpd_forbid_bare_newline =
+       yes" (the default for Postfix 3.9), reply with "Error: bare
+       <LF> received" and disconnect when an SMTP client sends a
+       line ending in <LF>, violating the RFC 5321 requirement
+       that lines must end in <CR><LF>. Files: mantools/postlink,
+       proto/postconf.proto, global/mail_params.h, global/smtp_stream.c,
+       global/smtp_stream.h, smtpd/smtpd.c.
index 06553f229bca7781dea5c4ad5e2da9b6bf22ad5c..ee933d66b35c07448ac04203ade5f97a966d31f7 100644 (file)
@@ -15919,6 +15919,23 @@ This feature is available in Postfix 2.0 and later.
 </p>
 
 
+</DD>
+
+<DT><b><a name="smtpd_forbid_bare_newline">smtpd_forbid_bare_newline</a>
+(default: Postfix &ge; 3.9: yes)</b></DT><DD>
+
+<p> Reply with "Error: bare &lt;LF&gt; received" and disconnect
+when a remote SMTP client sends a line ending in &lt;LF&gt;, violating
+the <a href="https://tools.ietf.org/html/rfc5321">RFC 5321</a> requirement that lines must end in &lt;CR&gt;&lt;LF&gt;.
+This feature is enabled by default with Postfix &ge; 3.9 but may
+not work with non-standard clients such as netcat. Specify
+"<a href="postconf.5.html#smtpd_forbid_bare_newline">smtpd_forbid_bare_newline</a> = no" to disable (not recommended for
+an Internet-connected MTA). </p>
+
+<p> This feature is available in Postfix &ge; 3.9, 3.8.4, 3.7.9,
+3.6.13, and 3.5.23. </p>
+
+
 </DD>
 
 <DT><b><a name="smtpd_forbid_unauth_pipelining">smtpd_forbid_unauth_pipelining</a>
index a9d2b9a9a5679f7f7e95830258a0320134a8f634..084d34bc39721e5b0927d13dcc8b94cda17b892f 100644 (file)
@@ -995,6 +995,13 @@ SMTPD(8)                                                              SMTPD(8)
               Disconnect remote SMTP clients that violate <a href="https://tools.ietf.org/html/rfc2920">RFC 2920</a>  (or  5321)
               command pipelining constraints.
 
+       Available in Postfix 3.9, 3.8.3, 3.7.9, 3.6.13, 3.5.23 and later:
+
+       <b><a href="postconf.5.html#smtpd_forbid_bare_newline">smtpd_forbid_bare_newline</a> (Postfix</b> &gt;<b>= 3.9: yes)</b>
+              Reply  with  "Error:  bare  &lt;LF&gt; received" and disconnect when a
+              remote SMTP client sends a line ending in  &lt;LF&gt;,  violating  the
+              <a href="https://tools.ietf.org/html/rfc5321">RFC 5321</a> requirement that lines must end in &lt;CR&gt;&lt;LF&gt;.
+
 <b>TARPIT CONTROLS</b>
        When  a  remote  SMTP  client makes errors, the Postfix SMTP server can
        insert delays before responding. This can help to  slow  down  run-away
index 0ceea67ee000702c9b4a95648a1dc470c86326e6..623ea49fddf9762e64a234cfc56463a54b83713f 100644 (file)
@@ -11003,6 +11003,17 @@ The smtpd_expansion_filter value is not subject to Postfix configuration
 parameter $name expansion.
 .PP
 This feature is available in Postfix 2.0 and later.
+.SH smtpd_forbid_bare_newline (default: Postfix >= 3.9: yes)
+Reply with "Error: bare <LF> received" and disconnect
+when a remote SMTP client sends a line ending in <LF>, violating
+the RFC 5321 requirement that lines must end in <CR><LF>.
+This feature is enabled by default with Postfix >= 3.9 but may
+not work with non\-standard clients such as netcat. Specify
+"smtpd_forbid_bare_newline = no" to disable (not recommended for
+an Internet\-connected MTA).
+.PP
+This feature is available in Postfix >= 3.9, 3.8.4, 3.7.9,
+3.6.13, and 3.5.23.
 .SH smtpd_forbid_unauth_pipelining (default: Postfix >= 3.9: yes)
 Disconnect remote SMTP clients that violate RFC 2920 (or 5321)
 command pipelining constraints. The server replies with "554 5.5.0
index 6883ab107702ddae705a90f7315c2bf6a8672646..56e22621cc2ce0b1b861af3d5563aa3ec38544de 100644 (file)
@@ -868,6 +868,12 @@ Available in Postfix 3.9, 3.8.1, 3.7.6, 3.6.10, 3.5.20 and later:
 .IP "\fBsmtpd_forbid_unauth_pipelining (Postfix >= 3.9: yes)\fR"
 Disconnect remote SMTP clients that violate RFC 2920 (or 5321)
 command pipelining constraints.
+.PP
+Available in Postfix 3.9, 3.8.3, 3.7.9, 3.6.13, 3.5.23 and later:
+.IP "\fBsmtpd_forbid_bare_newline (Postfix >= 3.9: yes)\fR"
+Reply with "Error: bare <LF> received" and disconnect
+when a remote SMTP client sends a line ending in <LF>, violating
+the RFC 5321 requirement that lines must end in <CR><LF>.
 .SH "TARPIT CONTROLS"
 .na
 .nf
index 35337f5da5dd471d2a25840821d95b90bab1b58a..31f00be25d652ac79e269c4a21dd26ef4b3183d3 100755 (executable)
@@ -561,6 +561,7 @@ while (<>) {
     s;\bsmtpd_etrn_restrictions\b;<a href="postconf.5.html#smtpd_etrn_restrictions">$&</a>;g;
     s;\bsmtpd_expansion_filter\b;<a href="postconf.5.html#smtpd_expansion_filter">$&</a>;g;
     s;\bsmtpd_for[-</bB>]*\n*[ <bB>]*bidden_commands\b;<a href="postconf.5.html#smtpd_forbidden_commands">$&</a>;g;
+    s;\bsmtpd_for[-</bB>]*\n*[ <bB>]*bid_bare_newline\b;<a href="postconf.5.html#smtpd_forbid_bare_newline">$&</a>;g;
     s;\bsmtpd_for[-</bB>]*\n*[ <bB>]*bid_unauth_pipelining\b;<a href="postconf.5.html#smtpd_forbid_unauth_pipelining">$&</a>;g;
     s;\bsmtpd_hard_error_limit\b;<a href="postconf.5.html#smtpd_hard_error_limit">$&</a>;g;
     s;\bsmtpd_helo_required\b;<a href="postconf.5.html#smtpd_helo_required">$&</a>;g;
index 8e014f690f1dfcc42b788e1baac66465c39b50dd..1023c776e0ce687ec5726e0ad1506a0c4376aec3 100644 (file)
@@ -19055,6 +19055,19 @@ MinProtocol = TLSv1
 <p> This feature is available in Postfix &ge; 3.9, 3.8.1, 3.7.6,
 3.6.10, and 3.5.20. </p>
 
+%PARAM smtpd_forbid_bare_newline Postfix &ge; 3.9: yes
+
+<p> Reply with "Error: bare &lt;LF&gt; received" and disconnect
+when a remote SMTP client sends a line ending in &lt;LF&gt;, violating
+the RFC 5321 requirement that lines must end in &lt;CR&gt;&lt;LF&gt;.
+This feature is enabled by default with Postfix &ge; 3.9 but may
+not work with non-standard clients such as netcat. Specify
+"smtpd_forbid_bare_newline = no" to disable (not recommended for
+an Internet-connected MTA). </p>
+
+<p> This feature is available in Postfix &ge; 3.9, 3.8.4, 3.7.9,
+3.6.13, and 3.5.23. </p>
+
 %PARAM smtpd_forbid_unauth_pipelining Postfix &ge; 3.9: yes
 
 <p> Disconnect remote SMTP clients that violate RFC 2920 (or 5321)
index 66dd2dab13dceb7f2e5e066ffc6db4c4945f5a64..375597d29527efde1127353cde4d97559e717f24 100644 (file)
@@ -1588,3 +1588,4 @@ sni
 Amawalk
 resychronization
 ENVID
+netcat
index 68d5bd80fe460f89657fc81ab5b9cf7a16c8808a..b75d9c7dcfb7cc4c7b806bc93435901f179b70bd 100644 (file)
@@ -81,3 +81,4 @@ proto  proto aliases proto virtual proto ADDRESS_REWRITING_README html
  client process name File proxymap proxymap c 
  available Files local command c local local c 
  ID if available File pipe pipe c 
+ global smtp_stream h smtpd smtpd c 
index 11d58a6e7e6039537cbba876661b59dfa18670fc..244f05f51928bc1e731389cc0a71955735daf50c 100644 (file)
@@ -4302,6 +4302,12 @@ extern char *var_smtp_dns_re_filter;
 #define DEF_SMTPD_DNS_RE_FILTER                ""
 extern char *var_smtpd_dns_re_filter;
 
+ /*
+  * Backwards compatibility.
+  */
+#define VAR_SMTPD_FORBID_BARE_LF       "smtpd_forbid_bare_newline"
+#define DEF_SMTPD_FORBID_BARE_LF       1
+
  /*
   * Share TLS sessions through tlsproxy(8).
   */
index 3f684bfb1778e9b124721c63b3b383a10a1c9139..2bfce0ea5b5b04101486484967419fe3bcbbaa73 100644 (file)
@@ -20,7 +20,7 @@
   * Patches change both the patchlevel and the release date. Snapshots have no
   * patchlevel; they change the release date only.
   */
-#define MAIL_RELEASE_DATE      "20231213"
+#define MAIL_RELEASE_DATE      "20231219"
 #define MAIL_VERSION_NUMBER    "3.9"
 
 #ifdef SNAPSHOT
index 595a159f04547b6480dd1eabf5bf5da475cd1f62..b7209009d2f36aff8021d3b7f16a8ccfa091a7b6 100644 (file)
@@ -52,6 +52,8 @@
 /*     VSTREAM *stream;
 /*     char    *format;
 /*     va_list ap;
+/*
+/*     int     smtp_forbid_bare_lf;
 /* AUXILIARY API
 /*     int     smtp_get_noexcept(vp, stream, maxlen, flags)
 /*     VSTRING *vp;
 /*     smtp_vprintf() is the machine underneath smtp_printf().
 /*
 /*     smtp_get_noexcept() implements the subset of smtp_get()
-/*     without timeouts and without making long jumps. Instead,
+/*     without long jumps for timeout or EOF errors. Instead,
 /*     query the stream status with vstream_feof() etc.
+/*     This function will make a VSTREAM long jump (error code
+/*     SMTP_ERR_LF) when rejecting input with a bare newline byte.
 /*
 /*     smtp_timeout_setup() is a backwards-compatibility interface
 /*     for programs that don't require deadline or data-rate support.
+/*
+/*     smtp_forbid_bare_lf controls whether smtp_get_noexcept()
+/*     will reject input with a bare newline byte.
 /* DIAGNOSTICS
 /* .fi
 /* .ad
   * the buffer. Such system calls would really hurt when receiving or sending
   * body content one line at a time.
   */
+int     smtp_forbid_bare_lf;
 
 /* smtp_timeout_reset - reset per-stream error flags */
 
@@ -418,6 +426,9 @@ int     smtp_get_noexcept(VSTRING *vp, VSTREAM *stream, ssize_t bound, int flags
         */
     case '\n':
        vstring_truncate(vp, VSTRING_LEN(vp) - 1);
+       if (smtp_forbid_bare_lf
+           && (VSTRING_LEN(vp) == 0 || vstring_end(vp)[-1] != '\r'))
+           vstream_longjmp(stream, SMTP_ERR_LF);
        while (VSTRING_LEN(vp) > 0 && vstring_end(vp)[-1] == '\r')
            vstring_truncate(vp, VSTRING_LEN(vp) - 1);
        VSTRING_TERMINATE(vp);
index 75700fed32e32d6cbaf49f15245f0b727b3e496b..4bcd6b59bd481682b6bab5865517c62dcbf1781b 100644 (file)
@@ -32,6 +32,7 @@
 #define SMTP_ERR_QUIET 3               /* silent cleanup (application) */
 #define SMTP_ERR_NONE  4               /* non-error case */
 #define SMTP_ERR_DATA  5               /* application data error */
+#define SMTP_ERR_LF    6               /* bare <LF> protocol error */
 
 extern void smtp_stream_setup(VSTREAM *, int, int, int);
 extern void PRINTFLIKE(2, 3) smtp_printf(VSTREAM *, const char *,...);
@@ -43,6 +44,7 @@ extern void smtp_fputs(const char *, ssize_t len, VSTREAM *);
 extern void smtp_fwrite(const char *, ssize_t len, VSTREAM *);
 extern void smtp_fread_buf(VSTRING *, ssize_t len, VSTREAM *);
 extern void smtp_fputc(int, VSTREAM *);
+extern int smtp_forbid_bare_lf;
 
 extern void smtp_vprintf(VSTREAM *, const char *, va_list);
 
index 2dbc8350bcc289190a224804aac37a1df8b27e38..8e91fc2f03f74b0d9cb9449242d6ec24c6166761 100644 (file)
 /* .IP "\fBsmtpd_forbid_unauth_pipelining (Postfix >= 3.9: yes)\fR"
 /*     Disconnect remote SMTP clients that violate RFC 2920 (or 5321)
 /*     command pipelining constraints.
+/* .PP
+/*     Available in Postfix 3.9, 3.8.3, 3.7.9, 3.6.13, 3.5.23 and later:
+/* .IP "\fBsmtpd_forbid_bare_newline (Postfix >= 3.9: yes)\fR"
+/*     Reply with "Error: bare <LF> received" and disconnect
+/*     when a remote SMTP client sends a line ending in <LF>, violating
+/*     the RFC 5321 requirement that lines must end in <CR><LF>.
 /* TARPIT CONTROLS
 /* .ad
 /* .fi
@@ -1608,6 +1614,7 @@ static void tls_reset(SMTPD_STATE *);
 #define REASON_TIMEOUT         "timeout"
 #define REASON_LOST_CONNECTION "lost connection"
 #define REASON_ERROR_LIMIT     "too many errors"
+#define REASON_BARE_LF         "bare <LF> received"
 
 #ifdef USE_TLS
 
@@ -4066,6 +4073,7 @@ static int bdat_cmd(SMTPD_STATE *state, int argc, SMTPD_TOKEN *argv)
      */
     done = 0;
     do {
+       int     payload_err;
 
        /*
         * Do not skip the smtp_fread_buf() call if read_len == 0. We still
@@ -4079,6 +4087,11 @@ static int bdat_cmd(SMTPD_STATE *state, int argc, SMTPD_TOKEN *argv)
        smtp_fread_buf(state->buffer, read_len, state->client);
        state->bdat_get_stream = vstream_memreopen(
                           state->bdat_get_stream, state->buffer, O_RDONLY);
+       vstream_control(state->bdat_get_stream, CA_VSTREAM_CTL_EXCEPT,
+                       CA_VSTREAM_CTL_END);
+       if ((payload_err = vstream_setjmp(state->bdat_get_stream))
+           != SMTP_ERR_NONE)
+           vstream_longjmp(state->client, payload_err);
 
        /*
         * Read lines from the fragment. The last line may continue in the
@@ -5576,6 +5589,13 @@ static void smtpd_proto(SMTPD_STATE *state)
                             var_myhostname);
        break;
 
+    case SMTP_ERR_LF:
+       state->reason = REASON_BARE_LF;
+       if (vstream_setjmp(state->client) == 0)
+           smtpd_chat_reply(state, "521 5.5.2 %s Error: bare <LF> received",
+                            var_myhostname);
+       break;
+
     case 0:
 
        /*
@@ -6570,6 +6590,7 @@ int     main(int argc, char **argv)
        VAR_SMTPD_DELAY_OPEN, DEF_SMTPD_DELAY_OPEN, &var_smtpd_delay_open,
        VAR_SMTPD_CLIENT_PORT_LOG, DEF_SMTPD_CLIENT_PORT_LOG, &var_smtpd_client_port_log,
        VAR_SMTPD_FORBID_UNAUTH_PIPE, DEF_SMTPD_FORBID_UNAUTH_PIPE, &var_smtpd_forbid_unauth_pipe,
+       VAR_SMTPD_FORBID_BARE_LF, DEF_SMTPD_FORBID_BARE_LF, &smtp_forbid_bare_lf,
        0,
     };
     static const CONFIG_NBOOL_TABLE nbool_table[] = {