Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2458221pxb; Tue, 12 Oct 2021 07:05:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfAlDYxNvKt7jZ16BCwrqROxixOvOEptpJWZsjj/VDVGjhikVQu3NOexnVljxMTwGMqPH9 X-Received: by 2002:a05:6512:2206:: with SMTP id h6mr19227463lfu.326.1634047530982; Tue, 12 Oct 2021 07:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634047530; cv=none; d=google.com; s=arc-20160816; b=rSy88NRbk4TXOj2M345zrVG7l4qQWv6/EVcPCADis9pdQRlEAGj9by6j8esFEkF5Gl xPpT82TT52aBdY7N/+Xfav8V9u/ZGfUQC/p0H9Krr8V5k8jloMonEidXNbbvbLULuuxP RjgL5LEe8WEnzRGQIIL1TT4lQFJLusvdFKiEv634UHldqH/sd766agvxpU827aIZoKQk xvNsmaaTsw0ZrTrtUJz6r+/VtGmNDuJUz4Zj1wRPJL1Ho+T7hMwCVIhRJA11RbkZChdI 6UT+DULoTBh/ALngd5tOjU9sqx16RDF2Lb3f92Fxyu/2WnBAun60w5K/nRtq9hxzn4sH YR+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lgl8mZ/YrF8TfvvRQz3SdK85Z+G04kK8iCOR7zSeTw4=; b=ju6IUxVOkG6TCzkB0rDga5zTesp5TCWXlZv1DOja/tuWWVCv/EjEuPwFDwweUkWymY iqamEn2ER0G6YgGfGulQbuy2m2tR4PfYHEzevfnJUoSrLfkeTZJDD7vA3AN1x28S/9UO TQS4n5bVl3crQIuQYDHKWMt0coxD6zMYA0bq3Yxl32g+Ob7CIxPkfv1Dh2KHDBVCx7m3 t66UcQ1gm63RaPRJSjKAnpl+fXaFMjxae1j9eJyzUqdqZv3P4qHvEYO5MpknL5FeZLlg mfaR9qmP1k9GFxqzCRFyviHqK+zaBfH6tkRsH1ckl1s8O0WUNsQKs4NEYFjg5mQPy2/0 XL1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=INxp6FXw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y17si13306873eda.575.2021.10.12.07.05.03; Tue, 12 Oct 2021 07:05:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=INxp6FXw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237069AbhJLOBw (ORCPT + 99 others); Tue, 12 Oct 2021 10:01:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237083AbhJLOBt (ORCPT ); Tue, 12 Oct 2021 10:01:49 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B63C061749 for ; Tue, 12 Oct 2021 06:59:47 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id r10so67331111wra.12 for ; Tue, 12 Oct 2021 06:59:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lgl8mZ/YrF8TfvvRQz3SdK85Z+G04kK8iCOR7zSeTw4=; b=INxp6FXwb6b2KjWNVfqnMSgcpV68kvNe9sNWshotThFLh64Nc6bBRKSU7r7yhl7ZWa ZIbiQA3t1WZjMeKB9nfdLZjXwAAtDk99IfxP2lRRq7oDFzGi1zN59vslvFotpPyoYuXB bvdbLnC0lFAENBfYhwKn3dWhzg+d4ejOZDyBg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lgl8mZ/YrF8TfvvRQz3SdK85Z+G04kK8iCOR7zSeTw4=; b=6jk2qIrtyz1uxzQM2QXkkFUOZmiUMJpz+Lh+BCc4IxU68fZF6vkx17OHnD1hkeVg/6 PhLNGlo+1VD5yLDIEXHUyfqu8r/VMhwfHiaSvnbIalZHh6YtMDkNk/DuOiarPSMCPPee PAqT/UZf5+Kz2m6aON4BfEbkUa5l/A3DykUY10YtA915+SPrU+sqlJxL0e6yFlZ0S4Rg s0FH2AFBBHsQ5t+ila40iRFojRtslpeerutAzx5kBrQnREfMrY5rt7PqsHizqJlOKxgl wrfLIYZt6OlLk0LYMcxI/oqvzjMfPRY7uBTOR2jPVVr+nLEXGLgydmfRKONfC4mVcMk5 ziZw== X-Gm-Message-State: AOAM530KddgU04E9QmceZ0CHLrYCeJpQrj0yKypwow5zF5i354ii5ssG DMJzcZxl+TfcSfUnwWpzyVQU+w== X-Received: by 2002:a05:6000:1567:: with SMTP id 7mr32439654wrz.408.1634047186275; Tue, 12 Oct 2021 06:59:46 -0700 (PDT) Received: from antares.. (d.5.b.3.f.b.d.4.c.0.9.7.6.8.3.1.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:1386:790c:4dbf:3b5d]) by smtp.gmail.com with ESMTPSA id o6sm14875894wri.49.2021.10.12.06.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 06:59:46 -0700 (PDT) From: Lorenz Bauer To: nicolas.dichtel@6wind.com, luke.r.nels@gmail.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "David S. Miller" , Jakub Kicinski Cc: kernel-team@cloudflare.com, Lorenz Bauer , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] bpf: prevent increasing bpf_jit_limit above max Date: Tue, 12 Oct 2021 14:59:34 +0100 Message-Id: <20211012135935.37054-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211012135935.37054-1-lmb@cloudflare.com> References: <20211012135935.37054-1-lmb@cloudflare.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Restrict bpf_jit_limit to the maximum supported by the arch's JIT. Signed-off-by: Lorenz Bauer --- include/linux/filter.h | 1 + kernel/bpf/core.c | 4 +++- net/core/sysctl_net_core.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index 47f80adbe744..8231a6a257f6 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1050,6 +1050,7 @@ extern int bpf_jit_enable; extern int bpf_jit_harden; extern int bpf_jit_kallsyms; extern long bpf_jit_limit; +extern long bpf_jit_limit_max; typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index b6c72af64d5d..ab84b3816339 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -525,6 +525,7 @@ int bpf_jit_enable __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON); int bpf_jit_kallsyms __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_DEFAULT_ON); int bpf_jit_harden __read_mostly; long bpf_jit_limit __read_mostly; +long bpf_jit_limit_max __read_mostly; static void bpf_prog_ksym_set_addr(struct bpf_prog *prog) @@ -818,7 +819,8 @@ u64 __weak bpf_jit_alloc_exec_limit(void) static int __init bpf_jit_charge_init(void) { /* Only used as heuristic here to derive limit. */ - bpf_jit_limit = min_t(u64, round_up(bpf_jit_alloc_exec_limit() >> 2, + bpf_jit_limit_max = bpf_jit_alloc_exec_limit(); + bpf_jit_limit = min_t(u64, round_up(bpf_jit_limit_max >> 2, PAGE_SIZE), LONG_MAX); return 0; } diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index c8496c1142c9..5f88526ad61c 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -419,7 +419,7 @@ static struct ctl_table net_core_table[] = { .mode = 0600, .proc_handler = proc_dolongvec_minmax_bpf_restricted, .extra1 = &long_one, - .extra2 = &long_max, + .extra2 = &bpf_jit_limit_max, }, #endif { -- 2.30.2