stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Ben Hutchings <ben.hutchings@codethink.co.uk>
Subject: [PATCH 4.9 046/103] bpf: restrict access to core bpf sysctls
Date: Thu, 22 Aug 2019 10:18:34 -0700	[thread overview]
Message-ID: <20190822171730.662419102@linuxfoundation.org> (raw)
In-Reply-To: <20190822171728.445189830@linuxfoundation.org>

From: Daniel Borkmann <daniel@iogearbox.net>

commit 2e4a30983b0f9b19b59e38bbf7427d7fdd480d98 upstream.

Given BPF reaches far beyond just networking these days, it was
never intended to allow setting and in some cases reading those
knobs out of a user namespace root running without CAP_SYS_ADMIN,
thus tighten such access.

Also the bpf_jit_enable = 2 debugging mode should only be allowed
if kptr_restrict is not set since it otherwise can leak addresses
to the kernel log. Dump a note to the kernel log that this is for
debugging JITs only when enabled.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
[bwh: Backported to 4.9:
 - We don't have bpf_dump_raw_ok(), so drop the condition based on it. This
   condition only made it a bit harder for a privileged user to do something
   silly.
 - Drop change to bpf_jit_kallsyms]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/core/sysctl_net_core.c |   39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -232,6 +232,41 @@ static int proc_do_rss_key(struct ctl_ta
 	return proc_dostring(&fake_table, write, buffer, lenp, ppos);
 }
 
+#ifdef CONFIG_BPF_JIT
+static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write,
+					   void __user *buffer, size_t *lenp,
+					   loff_t *ppos)
+{
+	int ret, jit_enable = *(int *)table->data;
+	struct ctl_table tmp = *table;
+
+	if (write && !capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	tmp.data = &jit_enable;
+	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+	if (write && !ret) {
+		*(int *)table->data = jit_enable;
+		if (jit_enable == 2)
+			pr_warn("bpf_jit_enable = 2 was set! NEVER use this in production, only for JIT debugging!\n");
+	}
+	return ret;
+}
+
+# ifdef CONFIG_HAVE_EBPF_JIT
+static int
+proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write,
+				    void __user *buffer, size_t *lenp,
+				    loff_t *ppos)
+{
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+}
+# endif
+#endif
+
 static struct ctl_table net_core_table[] = {
 #ifdef CONFIG_NET
 	{
@@ -293,7 +328,7 @@ static struct ctl_table net_core_table[]
 		.data		= &bpf_jit_enable,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
+		.proc_handler	= proc_dointvec_minmax_bpf_enable,
 # ifdef CONFIG_BPF_JIT_ALWAYS_ON
 		.extra1		= &one,
 		.extra2		= &one,
@@ -308,7 +343,7 @@ static struct ctl_table net_core_table[]
 		.data		= &bpf_jit_harden,
 		.maxlen		= sizeof(int),
 		.mode		= 0600,
-		.proc_handler	= proc_dointvec_minmax,
+		.proc_handler	= proc_dointvec_minmax_bpf_restricted,
 		.extra1		= &zero,
 		.extra2		= &two,
 	},



  parent reply	other threads:[~2019-08-22 17:23 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-22 17:17 [PATCH 4.9 000/103] 4.9.190-stable review Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 001/103] usb: usbfs: fix double-free of usb memory upon submiturb error Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 002/103] usb: iowarrior: fix deadlock on disconnect Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 003/103] sound: fix a memory leak bug Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 004/103] x86/mm: Check for pfn instead of page in vmalloc_sync_one() Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 005/103] x86/mm: Sync also unmappings in vmalloc_sync_all() Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 006/103] mm/vmalloc: Sync unmappings in __purge_vmap_area_lazy() Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 007/103] perf record: Fix wrong size in perf_record_mmap for last kernel module Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 008/103] perf db-export: Fix thread__exec_comm() Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 009/103] perf record: Fix module size on s390 Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 010/103] usb: yurex: Fix use-after-free in yurex_delete Greg Kroah-Hartman
2019-08-22 17:17 ` [PATCH 4.9 011/103] can: peak_usb: fix potential double kfree_skb() Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 012/103] netfilter: nfnetlink: avoid deadlock due to synchronous request_module Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 013/103] iscsi_ibft: make ISCSI_IBFT dependson ACPI instead of ISCSI_IBFT_FIND Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 014/103] mac80211: dont warn about CW params when not using them Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 015/103] hwmon: (nct6775) Fix register address and added missed tolerance for nct6106 Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 016/103] cpufreq/pasemi: fix use-after-free in pas_cpufreq_cpu_init() Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 017/103] s390/qdio: add sanity checks to the fast-requeue path Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 018/103] ALSA: compress: Fix regression on compressed capture streams Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 019/103] ALSA: compress: Prevent bypasses of set_params Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 020/103] ALSA: compress: Dont allow paritial drain operations on capture streams Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 021/103] ALSA: compress: Be more restrictive about when a drain is allowed Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 022/103] perf probe: Avoid calling freeing routine multiple times for same pointer Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 023/103] drbd: dynamically allocate shash descriptor Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 024/103] ACPI/IORT: Fix off-by-one check in iort_dev_find_its_id() Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 025/103] ARM: davinci: fix sleep.S build error on ARMv4 Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 026/103] scsi: megaraid_sas: fix panic on loading firmware crashdump Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 027/103] scsi: ibmvfc: fix WARN_ON during event pool release Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 028/103] scsi: scsi_dh_alua: always use a 2 second delay before retrying RTPG Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 029/103] tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 030/103] perf/core: Fix creating kernel counters for PMUs that override event->cpu Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 031/103] can: peak_usb: pcan_usb_pro: Fix info-leaks to USB devices Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 032/103] can: peak_usb: pcan_usb_fd: " Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 033/103] hwmon: (nct7802) Fix wrong detection of in4 presence Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 034/103] ALSA: firewire: fix a memory leak bug Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 035/103] ALSA: hda - Dont override global PCM hw info flag Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 036/103] mac80211: dont WARN on short WMM parameters from AP Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 037/103] SMB3: Fix deadlock in validate negotiate hits reconnect Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 038/103] smb3: send CAP_DFS capability during session setup Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 039/103] mwifiex: fix 802.11n/WPA detection Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 040/103] iwlwifi: dont unmap as page memory that was mapped as single Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 041/103] scsi: mpt3sas: Use 63-bit DMA addressing on SAS35 HBA Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 042/103] sh: kernel: hw_breakpoint: Fix missing break in switch statement Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 043/103] mm/usercopy: use memory range to be accessed for wraparound check Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 044/103] mm/memcontrol.c: fix use after free in mem_cgroup_iter() Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 045/103] bpf: get rid of pure_initcall dependency to enable jits Greg Kroah-Hartman
2019-08-22 17:18 ` Greg Kroah-Hartman [this message]
2019-08-22 17:18 ` [PATCH 4.9 047/103] bpf: add bpf_jit_limit knob to restrict unpriv allocations Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 048/103] vhost-net: set packet weight of tx polling to 2 * vq size Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 049/103] vhost_net: use packet weight for rx handler, too Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 050/103] vhost_net: introduce vhost_exceeds_weight() Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 051/103] vhost: " Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 052/103] vhost_net: fix possible infinite loop Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 053/103] vhost: scsi: add weight support Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 054/103] siphash: add cryptographically secure PRF Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 055/103] siphash: implement HalfSipHash1-3 for hash tables Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 056/103] inet: switch IP ID generator to siphash Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 057/103] netfilter: ctnetlink: dont use conntrack/expect object addresses as id Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 058/103] xtensa: add missing isync to the cpu_reset TLB code Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 059/103] ALSA: hda - Fix a memory leak bug Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 060/103] ALSA: hda - Add a generic reboot_notify Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 061/103] ALSA: hda - Let all conexant codec enter D3 when rebooting Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 062/103] HID: holtek: test for sanity of intfdata Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 063/103] HID: hiddev: avoid opening a disconnected device Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 064/103] HID: hiddev: do cleanup in failure of opening a device Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 065/103] Input: kbtab - sanity check for endpoint type Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 066/103] Input: iforce - add sanity checks Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 067/103] net: usb: pegasus: fix improper read if get_registers() fail Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 068/103] xen/pciback: remove set but not used variable old_state Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 069/103] irqchip/irq-imx-gpcv2: Forward irq type to parent Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 070/103] perf header: Fix divide by zero error if f_header.attr_size==0 Greg Kroah-Hartman
2019-08-22 17:18 ` [PATCH 4.9 071/103] perf header: Fix use of unitialized value warning Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 072/103] libata: zpodd: Fix small read overflow in zpodd_get_mech_type() Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 073/103] scsi: hpsa: correct scsi command status issue after reset Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 074/103] ata: libahci: do not complain in case of deferred probe Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 075/103] kbuild: modpost: handle KBUILD_EXTRA_SYMBOLS only for external modules Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 076/103] arm64/efi: fix variable si set but not used Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 077/103] arm64/mm: fix variable pud " Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 078/103] IB/core: Add mitigation for Spectre V1 Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 079/103] IB/mad: Fix use-after-free in ib mad completion handling Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 080/103] ocfs2: remove set but not used variable last_hash Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 081/103] staging: comedi: dt3000: Fix signed integer overflow divider * base Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 082/103] staging: comedi: dt3000: Fix rounding up of timer divisor Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 083/103] USB: core: Fix races in character device registration and deregistraion Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 084/103] usb: cdc-acm: make sure a refcount is taken early enough Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 085/103] USB: CDC: fix sanity checks in CDC union parser Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 086/103] USB: serial: option: add D-Link DWM-222 device ID Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 087/103] USB: serial: option: Add support for ZTE MF871A Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 088/103] USB: serial: option: add the BroadMobi BM818 card Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 089/103] USB: serial: option: Add Motorola modem UARTs Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 090/103] asm-generic: fix -Wtype-limits compiler warnings Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 091/103] bpf: fix bpf_jit_limit knob for PAGE_SIZE >= 64K Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 092/103] arm64: compat: Allow single-byte watchpoints on all addresses Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 093/103] netfilter: conntrack: Use consistent ct id hash calculation Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 094/103] Input: psmouse - fix build error of multiple definition Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 095/103] iommu/amd: Move iommu_init_pci() to .init section Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 096/103] bnx2x: Fix VFs VLAN reconfiguration in reload Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 097/103] net/packet: fix race in tpacket_snd() Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 098/103] sctp: fix the transport error_count check Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 099/103] xen/netback: Reset nr_frags before freeing skb Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 100/103] net/mlx5e: Only support tx/rx pause setting for port owner Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 101/103] net/mlx5e: Use flow keys dissector to parse packets for ARFS Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 102/103] team: Add vlan tx offload to hw_enc_features Greg Kroah-Hartman
2019-08-22 17:19 ` [PATCH 4.9 103/103] bonding: " Greg Kroah-Hartman
2019-08-22 21:17 ` [PATCH 4.9 000/103] 4.9.190-stable review kernelci.org bot
2019-08-23  2:06 ` Jon Hunter
2019-08-23  8:02 ` Naresh Kamboju
2019-08-23 14:27 ` Guenter Roeck
2019-08-24 17:59 ` shuah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190822171730.662419102@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ast@kernel.org \
    --cc=ben.hutchings@codethink.co.uk \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).