stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Jann Horn <jannh@google.com>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 4.14 079/100] netfilter: xt_bpf: add overflow checks
Date: Sun, 28 Jan 2018 22:26:50 +0000	[thread overview]
Message-ID: <20180128222547.7398-79-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180128222547.7398-1-alexander.levin@microsoft.com>

From: Jann Horn <jannh@google.com>

[ Upstream commit 6ab405114b0b229151ef06f4e31c7834dd09d0c0 ]

Check whether inputs from userspace are too long (explicit length field too
big or string not null-terminated) to avoid out-of-bounds reads.

As far as I can tell, this can at worst lead to very limited kernel heap
memory disclosure or oopses.

This bug can be triggered by an unprivileged user even if the xt_bpf module
is not loaded: iptables is available in network namespaces, and the xt_bpf
module can be autoloaded.

Triggering the bug with a classic BPF filter with fake length 0x1000 causes
the following KASAN report:

==================================================================
BUG: KASAN: slab-out-of-bounds in bpf_prog_create+0x84/0xf0
Read of size 32768 at addr ffff8801eff2c494 by task test/4627

CPU: 0 PID: 4627 Comm: test Not tainted 4.15.0-rc1+ #1
[...]
Call Trace:
 dump_stack+0x5c/0x85
 print_address_description+0x6a/0x260
 kasan_report+0x254/0x370
 ? bpf_prog_create+0x84/0xf0
 memcpy+0x1f/0x50
 bpf_prog_create+0x84/0xf0
 bpf_mt_check+0x90/0xd6 [xt_bpf]
[...]
Allocated by task 4627:
 kasan_kmalloc+0xa0/0xd0
 __kmalloc_node+0x47/0x60
 xt_alloc_table_info+0x41/0x70 [x_tables]
[...]
The buggy address belongs to the object at ffff8801eff2c3c0
                which belongs to the cache kmalloc-2048 of size 2048
The buggy address is located 212 bytes inside of
                2048-byte region [ffff8801eff2c3c0, ffff8801eff2cbc0)
[...]
==================================================================

Fixes: e6f30c731718 ("netfilter: x_tables: add xt_bpf match")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
---
 net/netfilter/xt_bpf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
index 29123934887b..5185ff0f8f58 100644
--- a/net/netfilter/xt_bpf.c
+++ b/net/netfilter/xt_bpf.c
@@ -27,6 +27,9 @@ static int __bpf_mt_check_bytecode(struct sock_filter *insns, __u16 len,
 {
 	struct sock_fprog_kern program;
 
+	if (len > XT_BPF_MAX_NUM_INSTR)
+		return -EINVAL;
+
 	program.len = len;
 	program.filter = insns;
 
@@ -55,6 +58,9 @@ static int __bpf_mt_check_path(const char *path, struct bpf_prog **ret)
 	mm_segment_t oldfs = get_fs();
 	int retval, fd;
 
+	if (strnlen(path, XT_BPF_PATH_MAX) == XT_BPF_PATH_MAX)
+		return -EINVAL;
+
 	set_fs(KERNEL_DS);
 	fd = bpf_obj_get_user(path);
 	set_fs(oldfs);
-- 
2.11.0

  parent reply	other threads:[~2018-01-28 22:27 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-28 22:25 [PATCH AUTOSEL for 4.14 001/100] usb: build drivers/usb/common/ when USB_SUPPORT is set Sasha Levin
2018-01-28 22:25 ` [PATCH AUTOSEL for 4.14 002/100] serdev: fix receive_buf return value when no callback Sasha Levin
2018-01-28 22:25 ` [PATCH AUTOSEL for 4.14 003/100] ARM: OMAP2+: Fix SRAM virt to phys translation for save_secure_ram_context Sasha Levin
2018-01-28 22:25 ` [PATCH AUTOSEL for 4.14 004/100] ARM: AM33xx: PRM: Remove am33xx_pwrdm_read_prev_pwrst function Sasha Levin
2018-01-28 22:25 ` [PATCH AUTOSEL for 4.14 005/100] ARM: dts: Fix omap4 hang with GPS connected to USB by using wakeupgen Sasha Levin
2018-01-28 22:25 ` [PATCH AUTOSEL for 4.14 007/100] ARM: dts: logicpd-somlv: Fix wl127x pinmux Sasha Levin
2018-01-28 22:25 ` [PATCH AUTOSEL for 4.14 006/100] ARM: dts: logicpd-som-lv: Fix gpmc addresses for NAND and enet Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 008/100] ARM: dts: am4372: Correct the interrupts_properties of McASP Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 009/100] ARM: dts: am437x-cm-t43: Correct the dmas property of spi0 Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 011/100] perf help: Fix a bug during strstart() conversion Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 010/100] perf record: Fix -c/-F options for cpu event aliases Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 012/100] perf annotate: Do not truncate instruction names at 6 chars Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 013/100] perf test shell: Fix check open filename arg using 'perf trace' on s390x Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 014/100] perf: Fix header.size for namespace events Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 016/100] perf bench numa: Fixup discontiguous/sparse numa nodes Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 015/100] perf top: Fix window dimensions change handling Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 017/100] perf test: Fix test 21 for s390x Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 019/100] kvm: arm: don't treat unavailable HYP mode as an error Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 018/100] pinctrl: denverton: Fix UART2 RTS pin mode Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 020/100] trace/xdp: fix compile warning: 'struct bpf_map' declared inside parameter list Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 022/100] media: ov13858: Select V4L2_FWNODE Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 021/100] media: s5k6aa: describe some function parameters Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 023/100] net: mvpp2: allocate zeroed tx descriptors Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 025/100] gpio: davinci: Assign first bank regs for unbanked case Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 024/100] gpio: 74x164: Fix crash during .remove() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 026/100] pinctrl: sunxi: Fix A80 interrupt pin bank Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 027/100] pinctrl: sunxi: Fix A64 UART mux value Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 028/100] IB/hfi1: Initialize bth1 in 16B rc ack builder Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 029/100] meson-gx-socinfo: Fix package id parsing Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 030/100] KVM: arm/arm64: Fix spinlock acquisition in vgic_set_owner Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 031/100] i40iw: Allocate a sdbuf per CQP WQE Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 033/100] i40iw: Correct ARP index mask Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 032/100] i40iw: Do not free sqbuf when event is I40IW_TIMER_TYPE_CLOSE Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 034/100] RDMA/cma: Make sure that PSN is not over max allowed Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 035/100] IB/core: Init subsys if compiled to vmlinuz-core Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 036/100] md/raid5: correct degraded calculation in raid5_error Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 037/100] sctp: only update outstanding_bytes for transmitted queue when doing prsctp_prune Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 038/100] sfp: fix RX_LOS signal handling Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 039/100] phylink: ensure we take the link down when phylink_stop() is called Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 040/100] md/raid1/10: add missed blk plug Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 041/100] iio: proximity: sx9500: Assign interrupt from GpioIo() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 042/100] iio: fix kernel-doc build errors Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 043/100] scripts/kernel-doc: Don't fail with status != 0 if error encountered with -none Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 044/100] bnxt_en: Need to unconditionally shut down RoCE in bnxt_shutdown Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 045/100] ipvlan: Add the skb->mark as flow4's member to lookup route Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 046/100] m68k: add missing SOFTIRQENTRY_TEXT linker section Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 047/100] powerpc/perf: Fix oops when grouping different pmu events Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 048/100] PM / runtime: Fix handling of suppliers with disabled runtime PM Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 049/100] s390/virtio: add BSD license to virtio-ccw Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 050/100] s390/dasd: prevent prefix I/O error Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 051/100] ARM: dts: Fix elm interrupt compiler warning Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 052/100] nfp: fix port stats for mac representors Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 053/100] gianfar: fix a flooded alignment reports because of padding issue Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 054/100] net_sched: red: Avoid devision by zero Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 055/100] net_sched: red: Avoid illegal values Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 056/100] VSOCK: fix outdated sk_state value in hvs_release() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 057/100] KVM: VMX: fix page leak in hardware_setup() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 058/100] net: qualcomm: rmnet: Fix leak on transmit failure Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 059/100] dccp: CVE-2017-8824: use-after-free in DCCP code Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 061/100] sched/wait: Fix add_wait_queue() behavioral change Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 060/100] locking/lockdep: Fix possible NULL deref Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 062/100] btrfs: Fix quota reservation leak on preallocated files Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 063/100] Btrfs: disable FUA if mounted with nobarrier Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 064/100] btrfs: Fix possible off-by-one in btrfs_search_path_in_tree Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 065/100] brcmfmac: Avoid build error with make W=1 Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 067/100] net: ethernet: arc: fix error handling in emac_rockchip_probe Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 066/100] virtio_net: fix return value check in receive_mergeable() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 069/100] net: dsa: mv88e6xxx: Unregister MDIO bus on error path Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 068/100] net: dsa: mv88e6xxx: Fix interrupt masking on removal Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 070/100] 509: fix printing uninitialized stack memory when OID is empty Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 072/100] scsi: lpfc: Use after free in lpfc_rq_buf_free() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 071/100] gianfar: Disable EEE autoneg by default Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 073/100] scsi: bfa: fix access to bfad_im_port_s Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 074/100] dmaengine: ioat: Fix error handling path Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 075/100] dmaengine: at_hdmac: fix potential NULL pointer dereference in atc_prep_dma_interleaved Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 076/100] xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0) Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 077/100] xfrm: Fix stack-out-of-bounds read on socket policy lookup Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 078/100] netfilter: nfnetlink_cthelper: Add missing permission checks Sasha Levin
2018-01-28 22:26 ` Sasha Levin [this message]
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 081/100] netfilter: xt_osf: " Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 080/100] clk: fix a panic error caused by accessing NULL pointer Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 082/100] staging: ccree: Uninitialized return in ssi_ahash_import() Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 083/100] ASoC: rockchip: disable clock on error Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 084/100] spi: sun4i: disable clocks in the remove function Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 085/100] IB/mlx4: Fix RSS hash fields restrictions Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 086/100] RDMA/netlink: Fix general protection fault Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 088/100] drm/armada: fix leak of crtc structure Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 087/100] xfrm: Fix stack-out-of-bounds with misconfigured transport mode policies Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 089/100] ASoC: rsnd: ssi: fix race condition in rsnd_ssi_pointer_update Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 090/100] drm/vc4: Release fence after signalling Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 091/100] dmaengine: jz4740: disable/unprepare clk if probe fails Sasha Levin
2018-01-28 22:26 ` [PATCH AUTOSEL for 4.14 092/100] usb: dwc3: gadget: Wait longer for controller to end command processing Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 093/100] usb: dwc3: of-simple: fix missing clk_disable_unprepare Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 095/100] x86/mm/kmmio: Fix mmiotrace for page unaligned addresses Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 097/100] xen: XEN_ACPI_PROCESSOR is Dom0-only Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 096/100] platform/x86: dell-laptop: Fix keyboard max lighting for Dell Latitude E6410 Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 098/100] PCI: rcar: Fix use-after-free in probe error path Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 099/100] powerpc/perf/imc: Fix nest-imc cpuhotplug callback failure Sasha Levin
2018-01-28 22:27 ` [PATCH AUTOSEL for 4.14 100/100] hippi: Fix a Fix a possible sleep-in-atomic bug in rr_close Sasha Levin

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=20180128222547.7398-79-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pablo@netfilter.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).