From nobody Thu Mar 31 14:46:16 2022 X-Original-To: dev-commits-src-main@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 514ED1A4AC05; Thu, 31 Mar 2022 14:46:17 +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 4KTmMY1m4qz3r7D; Thu, 31 Mar 2022 14:46:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648737977; 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=/tG7wzS20VQr22p6YYSeG+QJSaylx4Ztwl5VFx9IuFM=; b=cICtlC1YwXcAoA/u9SwEWLaTz29Y/pdRqiSgxzqalE/d1XUwz0w0jhtzMF/PdcTNxo8cb7 H9vJ806RzsXBIRUtrEa+nEU4Zu1kgNcpq5v3rLf3kwPC9nGYoNSNgC4jYz9HxS9TDk6s8L QaKaOUsuF3iDp+9jiwjIiAcs7M2BQlIhVccOK7gwVH0EqxthlnP+9dZSH4UPDc4Cj8Lul1 0SNNNNuaR1ane4/Z9W1plIloWCLwHiZHPVOdO/5ftjKD/feqLuHVaioq/xiUWMslNdp0qw bvlSPqBq5UU697zECacR31+WqxkPptXoFnU8C0c+7WnwpmjsSHcQLSYybdXO1A== 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 1841929A15; Thu, 31 Mar 2022 14:46:17 +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 22VEkG0Q085710; Thu, 31 Mar 2022 14:46:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22VEkGjQ085709; Thu, 31 Mar 2022 14:46:16 GMT (envelope-from git) Date: Thu, 31 Mar 2022 14:46:16 GMT Message-Id: <202203311446.22VEkGjQ085709@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: ca4cd20c4afe - main - Address issue pointed out in CVE-2020-25705 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ca4cd20c4afeb68ae30c4cc1103280590a099fe7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648737977; 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=/tG7wzS20VQr22p6YYSeG+QJSaylx4Ztwl5VFx9IuFM=; b=lC0rPYEvYDM4Ytql+ny2lRQtREQ9GDRCsrEcricT3P6TAXMTfC7RFprieiapT5p3FFqE+a 4Zno9Pnb3hPxuCuDsii15jx8tQl8+ThfGV+s/BRJZ5vqRGHtPFAEPY8GNww8vzO1bwEVcH NYgWub9zxOm9xAMxhQmr8UsdT2EugwYHxhnUdoBbsHCqX8+7PCRlMerXbInM7Acgbu525u PtGSk7Y4kiHWPIXs6mmNN8CB/P7hW1qpRAtizdeAkCE+/Q6ewvZacksy6JoV4713a+BTH0 2bXkphgN5EQ9faGey+W0UOlRmAxEXk3Hver0tVNpA85UZOByGP+kLp6WWPUhkQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648737977; a=rsa-sha256; cv=none; b=qNcgp+N0BeZZHAAKXbIlv+x2sIJKU6hLdl/FOgWhbv5uitqbh9JV6tSnIDbYLdY24wHqFH FMkVwA2fkL4tmZsH46i4eFxXC1C3y+55DMetnv3Z9RunPqwQseJD7/0ZuAVQl7GmUgGOdq JhcXX880mettDaBWwyzv/OH+vTU1h+Y9s7t/28oBiWzCWWmRAdepCInH7UbV/dz0uPNSHL jqS4eOshv9ERNweK71QSLgBT8y+Fk46tSuBsOBIMmfggiBoAhkN0IXoqxsC5248iIEQxZa Dz/3UWv0tJyOPGG8hvLqLKKkCg3BU4u6+t0VJ+AABQIDvE7q5xK0eU+N2ViVAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=ca4cd20c4afeb68ae30c4cc1103280590a099fe7 commit ca4cd20c4afeb68ae30c4cc1103280590a099fe7 Author: George V. Neville-Neil AuthorDate: 2022-03-19 16:48:16 +0000 Commit: Kristof Provost CommitDate: 2022-03-31 14:45:50 +0000 Address issue pointed out in CVE-2020-25705 Add jitter to the ICMP bandwidth limit to deny a side-channel port scan. Reviewed by: kp, philip, cy, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D27354 --- sys/netinet/ip_icmp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 463ac8c8e04d..76bce4b38e24 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -88,6 +88,14 @@ SYSCTL_INT(_net_inet_icmp, ICMPCTL_ICMPLIM, icmplim, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(icmplim), 0, "Maximum number of ICMP responses per second"); +VNET_DEFINE_STATIC(int, icmplim_curr_jitter) = 0; +#define V_icmplim_curr_jitter VNET(icmplim_curr_jitter) +VNET_DEFINE_STATIC(int, icmplim_jitter) = 16; +#define V_icmplim_jitter VNET(icmplim_jitter) +SYSCTL_INT(_net_inet_icmp, OID_AUTO, icmplim_jitter, CTLFLAG_VNET | CTLFLAG_RW, + &VNET_NAME(icmplim_jitter), 0, + "Random icmplim jitter adjustment limit"); + VNET_DEFINE_STATIC(int, icmplim_output) = 1; #define V_icmplim_output VNET(icmplim_output) SYSCTL_INT(_net_inet_icmp, OID_AUTO, icmplim_output, CTLFLAG_VNET | CTLFLAG_RW, @@ -1122,11 +1130,29 @@ badport_bandlim(int which) KASSERT(which >= 0 && which < BANDLIM_MAX, ("%s: which %d", __func__, which)); - pps = counter_ratecheck(&V_icmp_rates[which].cr, V_icmplim); + if ((V_icmplim + V_icmplim_curr_jitter) <= 0) + V_icmplim_curr_jitter = -V_icmplim + 1; + + pps = counter_ratecheck(&V_icmp_rates[which].cr, V_icmplim + + V_icmplim_curr_jitter); + if (pps > 0) { + /* + * Adjust limit +/- to jitter the measurement to deny a + * side-channel port scan as in CVE-2020-25705 + */ + if (V_icmplim_jitter > 0) { + int32_t inc = + arc4random_uniform(V_icmplim_jitter * 2 +1) + - V_icmplim_jitter; + + V_icmplim_curr_jitter = inc; + } + } if (pps == -1) return (-1); if (pps > 0 && V_icmplim_output) log(LOG_NOTICE, "Limiting %s from %jd to %d packets/sec\n", - V_icmp_rates[which].descr, (intmax_t )pps, V_icmplim); + V_icmp_rates[which].descr, (intmax_t )pps, V_icmplim + + V_icmplim_curr_jitter); return (0); }