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, Jann Horn <jannh@google.com>,
	David Howells <dhowells@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 5.15 093/110] watch_queue: Fix filter limit check
Date: Mon, 14 Mar 2022 12:54:35 +0100	[thread overview]
Message-ID: <20220314112745.624808982@linuxfoundation.org> (raw)
In-Reply-To: <20220314112743.029192918@linuxfoundation.org>

From: David Howells <dhowells@redhat.com>

commit c993ee0f9f81caf5767a50d1faeba39a0dc82af2 upstream.

In watch_queue_set_filter(), there are a couple of places where we check
that the filter type value does not exceed what the type_filter bitmap
can hold.  One place calculates the number of bits by:

   if (tf[i].type >= sizeof(wfilter->type_filter) * 8)

which is fine, but the second does:

   if (tf[i].type >= sizeof(wfilter->type_filter) * BITS_PER_LONG)

which is not.  This can lead to a couple of out-of-bounds writes due to
a too-large type:

 (1) __set_bit() on wfilter->type_filter
 (2) Writing more elements in wfilter->filters[] than we allocated.

Fix this by just using the proper WATCH_TYPE__NR instead, which is the
number of types we actually know about.

The bug may cause an oops looking something like:

  BUG: KASAN: slab-out-of-bounds in watch_queue_set_filter+0x659/0x740
  Write of size 4 at addr ffff88800d2c66bc by task watch_queue_oob/611
  ...
  Call Trace:
   <TASK>
   dump_stack_lvl+0x45/0x59
   print_address_description.constprop.0+0x1f/0x150
   ...
   kasan_report.cold+0x7f/0x11b
   ...
   watch_queue_set_filter+0x659/0x740
   ...
   __x64_sys_ioctl+0x127/0x190
   do_syscall_64+0x43/0x90
   entry_SYSCALL_64_after_hwframe+0x44/0xae

  Allocated by task 611:
   kasan_save_stack+0x1e/0x40
   __kasan_kmalloc+0x81/0xa0
   watch_queue_set_filter+0x23a/0x740
   __x64_sys_ioctl+0x127/0x190
   do_syscall_64+0x43/0x90
   entry_SYSCALL_64_after_hwframe+0x44/0xae

  The buggy address belongs to the object at ffff88800d2c66a0
   which belongs to the cache kmalloc-32 of size 32
  The buggy address is located 28 bytes inside of
   32-byte region [ffff88800d2c66a0, ffff88800d2c66c0)

Fixes: c73be61cede5 ("pipe: Add general notification queue support")
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/linux/watch_queue.h |    3 ++-
 kernel/watch_queue.c        |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

--- a/include/linux/watch_queue.h
+++ b/include/linux/watch_queue.h
@@ -28,7 +28,8 @@ struct watch_type_filter {
 struct watch_filter {
 	union {
 		struct rcu_head	rcu;
-		unsigned long	type_filter[2];	/* Bitmask of accepted types */
+		/* Bitmask of accepted types */
+		DECLARE_BITMAP(type_filter, WATCH_TYPE__NR);
 	};
 	u32			nr_filters;	/* Number of filters */
 	struct watch_type_filter filters[];
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -320,7 +320,7 @@ long watch_queue_set_filter(struct pipe_
 		    tf[i].info_mask & WATCH_INFO_LENGTH)
 			goto err_filter;
 		/* Ignore any unknown types */
-		if (tf[i].type >= sizeof(wfilter->type_filter) * 8)
+		if (tf[i].type >= WATCH_TYPE__NR)
 			continue;
 		nr_filter++;
 	}
@@ -336,7 +336,7 @@ long watch_queue_set_filter(struct pipe_
 
 	q = wfilter->filters;
 	for (i = 0; i < filter.nr_filters; i++) {
-		if (tf[i].type >= sizeof(wfilter->type_filter) * BITS_PER_LONG)
+		if (tf[i].type >= WATCH_TYPE__NR)
 			continue;
 
 		q->type			= tf[i].type;



  parent reply	other threads:[~2022-03-14 12:11 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 11:53 [PATCH 5.15 000/110] 5.15.29-rc1 review Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 001/110] arm64: dts: qcom: sm8350: Describe GCC dependency clocks Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 002/110] arm64: dts: qcom: sm8350: Correct UFS symbol clocks Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 003/110] HID: elo: Revert USB reference counting Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 004/110] HID: hid-thrustmaster: fix OOB read in thrustmaster_interrupts Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 005/110] ARM: boot: dts: bcm2711: Fix HVS register range Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 006/110] clk: qcom: gdsc: Add support to update GDSC transition delay Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 007/110] clk: qcom: dispcc: Update the transition delay for MDSS GDSC Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 008/110] HID: vivaldi: fix sysfs attributes leak Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 009/110] arm64: dts: armada-3720-turris-mox: Add missing ethernet0 alias Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 010/110] tipc: fix kernel panic when enabling bearer Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 011/110] vdpa/mlx5: add validation for VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 012/110] vduse: Fix returning wrong type in vduse_domain_alloc_iova() Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 013/110] net: phy: meson-gxl: fix interrupt handling in forced mode Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 014/110] mISDN: Fix memory leak in dsp_pipeline_build() Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 015/110] vhost: fix hung thread due to erroneous iotlb entries Greg Kroah-Hartman
2022-03-14 16:14   ` Anirudh Rayabharam
2022-03-15  9:19     ` Greg Kroah-Hartman
2022-03-15 11:50       ` Michael S. Tsirkin
2022-03-15 12:39         ` Greg Kroah-Hartman
2022-03-15 13:30           ` Michael S. Tsirkin
2022-03-14 11:53 ` [PATCH 5.15 016/110] virtio-blk: Dont use MAX_DISCARD_SEGMENTS if max_discard_seg is zero Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 017/110] vdpa: fix use-after-free on vp_vdpa_remove Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 018/110] isdn: hfcpci: check the return value of dma_set_mask() in setup_hw() Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 019/110] net: qlogic: check the return value of dma_alloc_coherent() in qed_vf_hw_prepare() Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 020/110] esp: Fix possible buffer overflow in ESP transformation Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 021/110] esp: Fix BEET mode inter address family tunneling on GSO Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 022/110] qed: return status of qed_iov_get_link Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 023/110] smsc95xx: Ignore -ENODEV errors when device is unplugged Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 024/110] gpiolib: acpi: Convert ACPI value of debounce to microseconds Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 025/110] drm/sun4i: mixer: Fix P010 and P210 format numbers Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 026/110] net: dsa: mt7530: fix incorrect test in mt753x_phylink_validate() Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 027/110] ARM: dts: aspeed: Fix AST2600 quad spi group Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 028/110] iavf: Fix handling of vlan strip virtual channel messages Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 029/110] i40e: stop disabling VFs due to PF error responses Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 030/110] ice: " Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 031/110] ice: Fix error with handling of bonding MTU Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 032/110] ice: Dont use GFP_KERNEL in atomic context Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 033/110] ice: Fix curr_link_speed advertised speed Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 034/110] ethernet: Fix error handling in xemaclite_of_probe Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 035/110] tipc: fix incorrect order of state message data sanity check Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 036/110] net: ethernet: ti: cpts: Handle error for clk_enable Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 037/110] net: ethernet: lpc_eth: " Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 038/110] net: marvell: prestera: Add missing of_node_put() in prestera_switch_set_base_mac_addr Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 039/110] ax25: Fix NULL pointer dereference in ax25_kill_by_device Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 040/110] net/mlx5: Fix size field in bufferx_reg struct Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 041/110] net/mlx5: Fix a race on command flush flow Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 042/110] net/mlx5e: Lag, Only handle events from highest priority multipath entry Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 043/110] NFC: port100: fix use-after-free in port100_send_complete Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 044/110] selftests: pmtu.sh: Kill tcpdump processes launched by subshell Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 045/110] selftests: pmtu.sh: Kill nettest processes launched in subshell Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 046/110] gpio: ts4900: Do not set DAT and OE together Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 047/110] gianfar: ethtool: Fix refcount leak in gfar_get_ts_info Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 048/110] net: phy: DP83822: clear MISR2 register to disable interrupts Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 049/110] sctp: fix kernel-infoleak for SCTP sockets Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 050/110] net: bcmgenet: Dont claim WOL when its not available Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 051/110] net: phy: meson-gxl: improve link-up behavior Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 052/110] selftests/bpf: Add test for bpf_timer overwriting crash Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 053/110] swiotlb: fix info leak with DMA_FROM_DEVICE Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 054/110] usb: dwc3: pci: add support for the Intel Raptor Lake-S Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 055/110] pinctrl: tigerlake: Revert "Add Alder Lake-M ACPI ID" Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 056/110] KVM: Fix lockdep false negative during host resume Greg Kroah-Hartman
2022-03-14 11:53 ` [PATCH 5.15 057/110] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 058/110] spi: rockchip: Fix error in getting num-cs property Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 059/110] spi: rockchip: terminate dma transmission when slave abort Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 060/110] drm/vc4: hdmi: Unregister codec device on unbind Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 061/110] x86/kvm: Dont use pv tlb/ipi/sched_yield if on 1 vCPU Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 062/110] net-sysfs: add check for netdevice being present to speed_show Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 063/110] hwmon: (pmbus) Clear pmbus fault/warning bits after read Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 064/110] PCI: Mark all AMD Navi10 and Navi14 GPU ATS as broken Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 065/110] gpio: Return EPROBE_DEFER if gc->to_irq is NULL Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 066/110] drm/amdgpu: bypass tiling flag check in virtual display case (v2) Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 067/110] Revert "xen-netback: remove hotplug-status once it has served its purpose" Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 068/110] Revert "xen-netback: Check for hotplug-status existence before watching" Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 069/110] ipv6: prevent a possible race condition with lifetimes Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 070/110] tracing: Ensure trace buffer is at least 4096 bytes large Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 071/110] tracing/osnoise: Make osnoise_main to sleep for microseconds Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 072/110] selftest/vm: fix map_fixed_noreplace test failure Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 073/110] selftests/memfd: clean up mapping in mfd_fail_write Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 074/110] ARM: Spectre-BHB: provide empty stub for non-config Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 075/110] fuse: fix fileattr op failure Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 076/110] fuse: fix pipe buffer lifetime for direct_io Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 077/110] staging: rtl8723bs: Fix access-point mode deadlock Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 078/110] staging: gdm724x: fix use after free in gdm_lte_rx() Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 079/110] net: macb: Fix lost RX packet wakeup race in NAPI receive Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 080/110] riscv: alternative only works on !XIP_KERNEL Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 081/110] mmc: meson: Fix usage of meson_mmc_post_req() Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 082/110] riscv: Fix auipc+jalr relocation range checks Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 083/110] tracing/osnoise: Force quiescent states while tracing Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 084/110] arm64: dts: marvell: armada-37xx: Remap IO space to bus address 0x0 Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 085/110] arm64: Ensure execute-only permissions are not allowed without EPAN Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 086/110] arm64: kasan: fix include error in MTE functions Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 087/110] swiotlb: rework "fix info leak with DMA_FROM_DEVICE" Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 088/110] KVM: x86/mmu: kvm_faultin_pfn has to return false if pfh is returned Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 089/110] virtio: unexport virtio_finalize_features Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 090/110] virtio: acknowledge all features before access Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 091/110] net/mlx5: Fix offloading with ESWITCH_IPV4_TTL_MODIFY_ENABLE Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 092/110] ARM: fix Thumb2 regression with Spectre BHB Greg Kroah-Hartman
2022-03-14 11:54 ` Greg Kroah-Hartman [this message]
2022-03-14 11:54 ` [PATCH 5.15 094/110] watch_queue, pipe: Free watchqueue state after clearing pipe ring Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 095/110] watch_queue: Fix to release page in ->release() Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 096/110] watch_queue: Fix to always request a pow-of-2 pipe ring size Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 097/110] watch_queue: Fix the alloc bitmap size to reflect notes allocated Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 098/110] watch_queue: Free the alloc bitmap when the watch_queue is torn down Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 099/110] watch_queue: Fix lack of barrier/sync/lock between post and read Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 100/110] watch_queue: Make comment about setting ->defunct more accurate Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 101/110] x86/boot: Fix memremap of setup_indirect structures Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 102/110] x86/boot: Add setup_indirect support in early_memremap_is_setup_data() Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 103/110] x86/sgx: Free backing memory after faulting the enclave page Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 104/110] x86/traps: Mark do_int3() NOKPROBE_SYMBOL Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 105/110] drm/panel: Select DRM_DP_HELPER for DRM_PANEL_EDP Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 106/110] btrfs: make send work with concurrent block group relocation Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 107/110] drm/i915: Workaround broken BIOS DBUF configuration on TGL/RKL Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 108/110] riscv: dts: k210: fix broken IRQs on hart1 Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 109/110] block: drop unused includes in <linux/genhd.h> Greg Kroah-Hartman
2022-03-14 11:54 ` [PATCH 5.15 110/110] Revert "net: dsa: mv88e6xxx: flush switchdev FDB workqueue before removing VLAN" Greg Kroah-Hartman
2022-03-14 22:37 ` [PATCH 5.15 000/110] 5.15.29-rc1 review Florian Fainelli
2022-03-14 22:43 ` Ron Economos
2022-03-15  0:53 ` Guenter Roeck
2022-03-15  5:13 ` Naresh Kamboju
2022-03-15  9:04 ` Jon Hunter
2022-03-15 10:58 ` Bagas Sanjaya
2022-03-15 12:32 ` Sudip Mukherjee
2022-03-15 13:49 ` Fox Chen

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=20220314112745.624808982@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=dhowells@redhat.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).