From nobody Thu Feb 10 19:33:29 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4184B19C48E4; Thu, 10 Feb 2022 19:33:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jvn3Y69r6z3D6q; Thu, 10 Feb 2022 19:33:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644521609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yKNYFCeatMK7jTUg4EeB+lWoZ7K+YLYKU9USuGTcPZc=; b=lnpLP7es9Kti7wShQlitPacaUQO7zYbcZ+nNMsNSjDP3QyCBJB6gNM0Jqg2P+ulrxaK8Y8 ZZg+uRZLyVm8657agZPj3O7NXlfU8D+K9Hg4qleMil4bB3esxQNOjxWRVf7/14PYSeRWOm hRE7BZtfP5jgW1lgLzIZ8PQwsg9eOMmu2WKlb9vR1pHoAC0V6r4Ku/XdGwS4HfEYzpg8Vu 7vshHa+Gw3cQ/ZIUlcphsqDokPdnQRNyiC1GZYNQnuUwrFj4PYBKaCK8m16XqkK1/QrKCX RJsE9QiwAA3rN1jzKCNZteF+M89gC/T+5w3rSjzY3jZrdUO0fjStb+aQqDhvow== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 831BF26418; Thu, 10 Feb 2022 19:33:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21AJXT7V022143; Thu, 10 Feb 2022 19:33:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21AJXTTZ022142; Thu, 10 Feb 2022 19:33:29 GMT (envelope-from git) Date: Thu, 10 Feb 2022 19:33:29 GMT Message-Id: <202202101933.21AJXTTZ022142@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Wing Subject: git: 7205809809e7 - stable/13 - syncache: accept packet with no SA when TCP_MD5SIG is set List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rew X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7205809809e70db0abf2cecaf7f5e056650315bb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644521610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yKNYFCeatMK7jTUg4EeB+lWoZ7K+YLYKU9USuGTcPZc=; b=OCZRKVMYZKk20SHmirBxvJpCFcdoZbvnmT0MSn5vEuCL/BhuZB+nbbMSjeqOkhZ33g5MRx 1qIuV2NqBfoYJ4tfr7Yzwk9eGJR75DZz4PMJA4vTve9ASdr2RUhu9McYQoS0sADr+O7Svw B7CmZBq4eMfO2xRtjoGj/poNNmAmUra8YOuf1pui0jH80ctwFr+gJFIJkIVKZsg805eAdr YKvlrTAzjuRplkn+A9rdQYT1W5ROnQVUgk20Hp3J18jSZMNG0AaLGHkF2WVpxV4daLH1Rf lJ82hV8kMnvQoy75HCDxC+UP+wQRtaBlfJUEBXn5CZX3b2Wz9YCjsI/xhjGEhw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644521610; a=rsa-sha256; cv=none; b=Li8hth2xrpOgO4Do7NHCRJGh6LpgHq1UFka/t7XCGuUU+rTmEtp12GSegwGobgY9pEm5zC x0yShnIenirIXAGNUx32z+K7M5HSlMgoIYtCF/u4/u3DJJeBFQVDF3EAiA/lgvdQqAjQ4k xGqy3QV7+UDN2/EZeuiuMsB6mW9OLjeBiJsXvUZVbNh+G/tWp2PozwPn7HMIFjS8lcug4d EtX17v9tAX9dc9Pem0iDCDoH9UOp/eaUXZ6Qwxfd5o1MoZgoN07zuY+rxjOXqKSl0tSZJq D0CEZPtPeTr1tb0hnAV3i1apCvrNZ77u1TD/83yQf7WduxbffLx+ETQzpkv5fw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=7205809809e70db0abf2cecaf7f5e056650315bb commit 7205809809e70db0abf2cecaf7f5e056650315bb Author: Robert Wing AuthorDate: 2022-01-09 01:07:50 +0000 Commit: Robert Wing CommitDate: 2022-02-10 19:31:33 +0000 syncache: accept packet with no SA when TCP_MD5SIG is set When TCP_MD5SIG is set on a socket, all packets are dropped that don't contain an MD5 signature. Relax this behavior to accept a non-signed packet when a security association doesn't exist with the peer. This is useful when a listen socket set with TCP_MD5SIG wants to handle connections protected with and without MD5 signatures. Reviewed by: bz (previous version) Sponsored by: nepustil.net Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D33227 (cherry picked from commit eb18708ec8c7e1de6a05aba41971659549991b10) --- share/man/man4/tcp.4 | 6 +++++- sys/netinet/tcp_syncache.c | 30 ++++++++++++++++++------------ sys/netipsec/xform_tcp.c | 5 +++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/share/man/man4/tcp.4 b/share/man/man4/tcp.4 index e49df5319efb..3fe2753bf408 100644 --- a/share/man/man4/tcp.4 +++ b/share/man/man4/tcp.4 @@ -34,7 +34,7 @@ .\" From: @(#)tcp.4 8.1 (Berkeley) 6/5/93 .\" $FreeBSD$ .\" -.Dd June 27, 2021 +.Dd January 8, 2022 .Dt TCP 4 .Os .Sh NAME @@ -339,6 +339,10 @@ This entry can only be specified on a per-host basis at this time. .Pp If an SADB entry cannot be found for the destination, the system does not send any outgoing segments and drops any inbound segments. +However, during connection negotiation, a non-signed segment will be accepted if +an SADB entry does not exist between hosts. +When a non-signed segment is accepted, the established connection is not +protected with MD5 digests. .It Dv TCP_STATS Manage collection of connection level statistics using the .Xr stats 3 diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index a1102574b325..e7fb8da52216 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1513,19 +1513,25 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE) /* - * If listening socket requested TCP digests, check that received - * SYN has signature and it is correct. If signature doesn't match - * or TCP_SIGNATURE support isn't enabled, drop the packet. + * When the socket is TCP-MD5 enabled check that, + * - a signed packet is valid + * - a non-signed packet does not have a security association + * + * If a signed packet fails validation or a non-signed packet has a + * security association, the packet will be dropped. */ if (ltflags & TF_SIGNATURE) { - if ((to->to_flags & TOF_SIGNATURE) == 0) { - TCPSTAT_INC(tcps_sig_err_nosigopt); - goto done; + if (to->to_flags & TOF_SIGNATURE) { + if (!TCPMD5_ENABLED() || + TCPMD5_INPUT(m, th, to->to_signature) != 0) + goto done; + } else { + if (TCPMD5_ENABLED() && + TCPMD5_INPUT(m, NULL, NULL) != ENOENT) + goto done; } - if (!TCPMD5_ENABLED() || - TCPMD5_INPUT(m, th, to->to_signature) != 0) - goto done; - } + } else if (to->to_flags & TOF_SIGNATURE) + goto done; #endif /* TCP_SIGNATURE */ /* * See if we already have an entry for this connection. @@ -1723,11 +1729,11 @@ skip_alloc: } #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE) /* - * If listening socket requested TCP digests, flag this in the + * If incoming packet has an MD5 signature, flag this in the * syncache so that syncache_respond() will do the right thing * with the SYN+ACK. */ - if (ltflags & TF_SIGNATURE) + if (to->to_flags & TOF_SIGNATURE) sc->sc_flags |= SCF_SIGNATURE; #endif /* TCP_SIGNATURE */ if (to->to_flags & TOF_SACKPERM) diff --git a/sys/netipsec/xform_tcp.c b/sys/netipsec/xform_tcp.c index b53544cd00fb..ce2552f0a205 100644 --- a/sys/netipsec/xform_tcp.c +++ b/sys/netipsec/xform_tcp.c @@ -269,6 +269,11 @@ tcp_ipsec_input(struct mbuf *m, struct tcphdr *th, u_char *buf) KMOD_TCPSTAT_INC(tcps_sig_err_buildsig); return (ENOENT); } + if (buf == NULL) { + key_freesav(&sav); + KMOD_TCPSTAT_INC(tcps_sig_err_nosigopt); + return (EACCES); + } /* * tcp_input() operates with TCP header fields in host * byte order. We expect them in network byte order.