From patchwork Tue Feb 23 13:52:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1443498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DlL8P3QDHz9sWP; Wed, 24 Feb 2021 00:52:20 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1lEY6s-0008UE-5a; Tue, 23 Feb 2021 13:52:18 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lEY6q-0008Tq-Es for kernel-team@lists.ubuntu.com; Tue, 23 Feb 2021 13:52:16 +0000 Received: from mail-pg1-f199.google.com ([209.85.215.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lEY6q-0008RY-3F for kernel-team@lists.ubuntu.com; Tue, 23 Feb 2021 13:52:16 +0000 Received: by mail-pg1-f199.google.com with SMTP id 18so9777823pgp.22 for ; Tue, 23 Feb 2021 05:52:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jlktfvlS9ECMJoV3MLphB6EJDYkH2K+qpcIp0o7DRbY=; b=Oqqv9qhQ3kwRuSMHMYmlUrm0TJtxxs2B3Hr2z1RVET8T753ob78jM0AgUOAvjtC0HT JPRXh48YUy9a2oHOxBiEcel6mrD6Dd79pS+gyLNqD/OBaIWvzftT8pKYyKgluK4dZP1m vT6XQO95FiIi/KJYHQlJ8l7DDe7ar7hCZLh4IM/j6KS44XepVSJI39ctMuLsEA5YfjNK YW/SVPFFAm3HSMw0mUmBt7P82DotYLiOCwQmc9E7RqEAauTHBaxY2+w9JtuXnuYcWL+/ 6LFJBX+dCXnH2/Ek06bV4g7iBVllGXeSOHRFzl7qxMyGVtKVdNXs7ofKRRSvbWascwBt f8kg== X-Gm-Message-State: AOAM5300hWDr9EbPP5VZ8Lbx4432IHDmShFyM1cojiL2bQDD0ttdScqr +pcXw0I9dP+l/tPVB/ERwsX9Qt8NycR81KeWU5zY6EwVEVCxLm2osdflyNDoksgzBiowMRcw6Rf kX5Yw6MTf1zzrIodOZuwD5jhhmQR4m+id9miRQe82uw== X-Received: by 2002:a17:90a:74c6:: with SMTP id p6mr7935896pjl.134.1614088334525; Tue, 23 Feb 2021 05:52:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVlVAfgEdIH7kKNYGIN/w8GStY1oRef5/JdY0NPdL1nSanRpIomxJPT8OInSp5kkplFoVSlw== X-Received: by 2002:a17:90a:74c6:: with SMTP id p6mr7935880pjl.134.1614088334258; Tue, 23 Feb 2021 05:52:14 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id d73sm6542979pfd.0.2021.02.23.05.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 05:52:13 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH] icmp: randomize the global rate limiter Date: Tue, 23 Feb 2021 06:52:09 -0700 Message-Id: <20210223135209.3936-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210223135209.3936-1-tim.gardner@canonical.com> References: <20210223135209.3936-1-tim.gardner@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Eric Dumazet BugLink: https://bugs.launchpad.net/bugs/1902115 [ Upstream commit b38e7819cae946e2edf869e604af1e65a5d241c5 ] Keyu Man reported that the ICMP rate limiter could be used by attackers to get useful signal. Details will be provided in an upcoming academic publication. Our solution is to add some noise, so that the attackers no longer can get help from the predictable token bucket limiter. Fixes: 4cdf507d5452 ("icmp: add a global rate limitation") Signed-off-by: Eric Dumazet Reported-by: Keyu Man Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman Signed-off-by: Kamal Mostafa Signed-off-by: Ian May (cherry picked from commit fc3d57b1e860f9bdd97bbbf14f1617e718fae7f3 bionic/linux-oracle-5.4) CVE-2020-25705 Signed-off-by: Tim Gardner I chose bionic/linux-oracle-5.4 for this cherry-pick since the patch had already been backported, regression tested, and released; thereby reducing the chances of backporting error or regression. Acked-by: Stefan Bader Acked-by: Kleber Sacilotto de Souza --- Documentation/networking/ip-sysctl.txt | 4 +++- net/ipv4/icmp.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt index 5f53faff4e25..151d6ad0e0a7 100644 --- a/Documentation/networking/ip-sysctl.txt +++ b/Documentation/networking/ip-sysctl.txt @@ -1005,12 +1005,14 @@ icmp_ratelimit - INTEGER icmp_msgs_per_sec - INTEGER Limit maximal number of ICMP packets sent per second from this host. Only messages whose type matches icmp_ratemask (see below) are - controlled by this limit. + controlled by this limit. For security reasons, the precise count + of messages per second is randomized. Default: 1000 icmp_msgs_burst - INTEGER icmp_msgs_per_sec controls number of ICMP packets sent per second, while icmp_msgs_burst controls the burst size of these packets. + For security reasons, the precise burst size is randomized. Default: 50 icmp_ratemask - INTEGER diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index f369e7ce685b..dcffda472585 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -239,7 +239,7 @@ static struct { /** * icmp_global_allow - Are we allowed to send one more ICMP message ? * - * Uses a token bucket to limit our ICMP messages to sysctl_icmp_msgs_per_sec. + * Uses a token bucket to limit our ICMP messages to ~sysctl_icmp_msgs_per_sec. * Returns false if we reached the limit and can not send another packet. * Note: called with BH disabled */ @@ -267,7 +267,10 @@ bool icmp_global_allow(void) } credit = min_t(u32, icmp_global.credit + incr, sysctl_icmp_msgs_burst); if (credit) { - credit--; + /* We want to use a credit of one in average, but need to randomize + * it for security reasons. + */ + credit = max_t(int, credit - prandom_u32_max(3), 0); rc = true; } WRITE_ONCE(icmp_global.credit, credit);