From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id 666717D0DC for ; Mon, 21 May 2018 12:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751363AbeEUM3D (ORCPT ); Mon, 21 May 2018 08:29:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60470 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751202AbeEUM3C (ORCPT ); Mon, 21 May 2018 08:29:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 464AF4076044; Mon, 21 May 2018 12:29:02 +0000 (UTC) Received: from asgard.redhat.com (ovpn-200-31.brq.redhat.com [10.40.200.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC51F4E62F; Mon, 21 May 2018 12:28:57 +0000 (UTC) Date: Mon, 21 May 2018 14:29:51 +0200 From: Eugene Syromiatnikov To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Kees Cook , Kai-Heng Feng , Daniel Borkmann , Alexei Starovoitov , Jonathan Corbet , Jiri Olsa , Jesper Dangaard Brouer Subject: [PATCH 1/3] bpf: add ability to configure unprivileged BPF via boot-time parameter Message-ID: <20180521122951.GA19358@asgard.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 21 May 2018 12:29:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 21 May 2018 12:29:02 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'esyr@redhat.com' RCPT:'' Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org This patch introduces two configuration options, UNPRIVILEGED_BPF_BOOTPARAM and UNPRIVILEGED_BPF_BOOTPARAM_VALUE, that allow configuring the initial value of kernel.unprivileged_bpf_disabled sysctl knob, which is useful for the cases when disabling unprivileged bpf() access during the early boot is desirable. Signed-off-by: Eugene Syromiatnikov --- Documentation/admin-guide/kernel-parameters.txt | 8 +++++++ init/Kconfig | 31 +++++++++++++++++++++++++ kernel/bpf/syscall.c | 16 +++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 11fc28e..aa8e831 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4355,6 +4355,14 @@ unknown_nmi_panic [X86] Cause panic on unknown NMI. + unprivileged_bpf_disabled= + Format: { "0" | "1" } + Sets initial value of kernel.unprivileged_bpf_disabled + sysctl knob. + 0 - unprivileged bpf() syscall access enabled. + 1 - unprivileged bpf() syscall access disabled. + Default value is set via kernel config option. + usbcore.authorized_default= [USB] Default USB device authorization: (default -1 = authorized except for wireless USB, diff --git a/init/Kconfig b/init/Kconfig index 480a4f2..1403a3e 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1404,6 +1404,37 @@ config BPF_JIT_ALWAYS_ON Enables BPF JIT and removes BPF interpreter to avoid speculative execution of BPF instructions by the interpreter +config UNPRIVILEGED_BPF_BOOTPARAM + bool "Unprivileged bpf() boot parameter" + depends on BPF_SYSCALL + default n + help + This option adds a kernel parameter 'unprivileged_bpf_disabled' + that allows configuring default state of the + kernel.unprivileged_bpf_disabled sysctl knob. + If this option is selected, unprivileged access to the bpf() syscall + can be disabled with unprivileged_bpf_disabled=1 on the kernel command + line. The purpose of this option is to allow disabling unprivileged + bpf() syscall access during the early boot. + + If you are unsure how to answer this question, answer N. + +config UNPRIVILEGED_BPF_BOOTPARAM_VALUE + int "Unprivileged bpf() boot parameter default value" + depends on UNPRIVILEGED_BPF_BOOTPARAM + range 0 1 + default 0 + help + This option sets the default value for the kernel parameter + 'unprivileged_bpf_disabled', which allows disabling unprivileged bpf() + syscall access at boot. If this option is set to 0 (zero), the + unprivileged bpf() boot kernel parameter will default to 0, allowing + unprivileged bpf() syscall access at bootup. If this option is + set to 1 (one), the unprivileged bpf() kernel parameter will default + to 1, disabling unprivileged bpf() syscall access at bootup. + + If you are unsure how to answer this question, answer 0. + config USERFAULTFD bool "Enable userfaultfd() system call" select ANON_INODES diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index bfcde94..fdc5fd9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -29,6 +29,7 @@ #include #include #include +#include #define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \ (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \ @@ -45,7 +46,22 @@ static DEFINE_SPINLOCK(prog_idr_lock); static DEFINE_IDR(map_idr); static DEFINE_SPINLOCK(map_idr_lock); +#ifdef CONFIG_UNPRIVILEGED_BPF_BOOTPARAM +int sysctl_unprivileged_bpf_disabled __read_mostly = + CONFIG_UNPRIVILEGED_BPF_BOOTPARAM_VALUE; + +static int __init unprivileged_bpf_setup(char *str) +{ + unsigned long disabled; + + if (!kstrtoul(str, 0, &disabled)) + sysctl_unprivileged_bpf_disabled = !!disabled; + return 1; +} +__setup("unprivileged_bpf_disabled=", unprivileged_bpf_setup); +#else /* !CONFIG_UNPRIVILEGED_BPF_BOOTPARAM */ int sysctl_unprivileged_bpf_disabled __read_mostly; +#endif /* CONFIG_UNPRIVILEGED_BPF_BOOTPARAM */ static const struct bpf_map_ops * const bpf_map_types[] = { #define BPF_PROG_TYPE(_id, _ops) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html