public inbox for stable@vger.kernel.org
 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,
	Tatsuhiko Yasumatsu <th.yasumatsu@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 37/83] bpf: Fix integer overflow in prealloc_elems_and_freelist()
Date: Mon, 11 Oct 2021 15:45:57 +0200	[thread overview]
Message-ID: <20211011134509.662607187@linuxfoundation.org> (raw)
In-Reply-To: <20211011134508.362906295@linuxfoundation.org>

From: Tatsuhiko Yasumatsu <th.yasumatsu@gmail.com>

[ Upstream commit 30e29a9a2bc6a4888335a6ede968b75cd329657a ]

In prealloc_elems_and_freelist(), the multiplication to calculate the
size passed to bpf_map_area_alloc() could lead to an integer overflow.
As a result, out-of-bounds write could occur in pcpu_freelist_populate()
as reported by KASAN:

[...]
[   16.968613] BUG: KASAN: slab-out-of-bounds in pcpu_freelist_populate+0xd9/0x100
[   16.969408] Write of size 8 at addr ffff888104fc6ea0 by task crash/78
[   16.970038]
[   16.970195] CPU: 0 PID: 78 Comm: crash Not tainted 5.15.0-rc2+ #1
[   16.970878] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
[   16.972026] Call Trace:
[   16.972306]  dump_stack_lvl+0x34/0x44
[   16.972687]  print_address_description.constprop.0+0x21/0x140
[   16.973297]  ? pcpu_freelist_populate+0xd9/0x100
[   16.973777]  ? pcpu_freelist_populate+0xd9/0x100
[   16.974257]  kasan_report.cold+0x7f/0x11b
[   16.974681]  ? pcpu_freelist_populate+0xd9/0x100
[   16.975190]  pcpu_freelist_populate+0xd9/0x100
[   16.975669]  stack_map_alloc+0x209/0x2a0
[   16.976106]  __sys_bpf+0xd83/0x2ce0
[...]

The possibility of this overflow was originally discussed in [0], but
was overlooked.

Fix the integer overflow by changing elem_size to u64 from u32.

  [0] https://lore.kernel.org/bpf/728b238e-a481-eb50-98e9-b0f430ab01e7@gmail.com/

Fixes: 557c0c6e7df8 ("bpf: convert stackmap to pre-allocation")
Signed-off-by: Tatsuhiko Yasumatsu <th.yasumatsu@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210930135545.173698-1-th.yasumatsu@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/bpf/stackmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index ebf60848d5eb..4477873ac3a0 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -64,7 +64,8 @@ static inline int stack_map_data_size(struct bpf_map *map)
 
 static int prealloc_elems_and_freelist(struct bpf_stack_map *smap)
 {
-	u32 elem_size = sizeof(struct stack_map_bucket) + smap->map.value_size;
+	u64 elem_size = sizeof(struct stack_map_bucket) +
+			(u64)smap->map.value_size;
 	int err;
 
 	smap->elems = bpf_map_area_alloc(elem_size * smap->map.max_entries,
-- 
2.33.0




  parent reply	other threads:[~2021-10-11 13:57 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 13:45 [PATCH 5.10 00/83] 5.10.73-rc1 review Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 01/83] Partially revert "usb: Kconfig: using select for USB_COMMON dependency" Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 02/83] usb: chipidea: ci_hdrc_imx: Also search for phys phandle Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 03/83] USB: cdc-acm: fix racy tty buffer accesses Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 04/83] USB: cdc-acm: fix break reporting Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 05/83] usb: typec: tcpm: handle SRC_STARTUP state if cc changes Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 06/83] drm/nouveau/kms/tu102-: delay enabling cursor until after assign_windows Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 07/83] xen/privcmd: fix error handling in mmap-resource processing Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 08/83] mmc: meson-gx: do not use memcpy_to/fromio for dram-access-quirk Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 09/83] mmc: sdhci-of-at91: wait for calibration done before proceed Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 10/83] mmc: sdhci-of-at91: replace while loop with read_poll_timeout Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 11/83] ovl: fix missing negative dentry check in ovl_rename() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 12/83] ovl: fix IOCB_DIRECT if underlying fs doesnt support direct IO Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 13/83] nfsd: fix error handling of register_pernet_subsys() in init_nfsd() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 14/83] nfsd4: Handle the NFSv4 READDIR dircount hint being zero Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 15/83] SUNRPC: fix sign error causing rpcsec_gss drops Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 16/83] xen/balloon: fix cancelled balloon action Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 17/83] ARM: dts: omap3430-sdp: Fix NAND device node Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 18/83] ARM: dts: imx6dl-yapp4: Fix lp5562 LED driver probe Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 19/83] ARM: dts: qcom: apq8064: use compatible which contains chipid Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 20/83] riscv: Flush current cpu icache before other cpus Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 21/83] bus: ti-sysc: Add break in switch statement in sysc_init_soc() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 22/83] soc: qcom: socinfo: Fixed argument passed to platform_set_data() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 23/83] ARM: dts: qcom: apq8064: Use 27MHz PXO clock as DSI PLL reference Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 24/83] ARM: at91: pm: do not panic if ram controllers are not enabled Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 25/83] soc: qcom: mdt_loader: Drop PT_LOAD check on hash segment Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 26/83] ARM: dts: imx: Add missing pinctrl-names for panel on M53Menlo Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 27/83] ARM: dts: imx: Fix USB host power regulator polarity " Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 28/83] ARM: dts: imx6qdl-pico: Fix Ethernet support Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 29/83] PCI: hv: Fix sleep while in non-sleep context when removing child devices from the bus Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 30/83] ath5k: fix building with LEDS=m Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 31/83] arm64: dts: qcom: pm8150: use qcom,pm8998-pon binding Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 32/83] xtensa: use CONFIG_USE_OF instead of CONFIG_OF Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 33/83] xtensa: call irqchip_init only when CONFIG_USE_OF is selected Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 34/83] iwlwifi: pcie: add configuration of a Wi-Fi adapter on Dell XPS 15 Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 35/83] bpf, arm: Fix register clobbering in div/mod implementation Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 36/83] soc: ti: omap-prm: Fix external abort for am335x pruss Greg Kroah-Hartman
2021-10-11 13:45 ` Greg Kroah-Hartman [this message]
2021-10-11 13:45 ` [PATCH 5.10 38/83] net/mlx5e: IPSEC RX, enable checksum complete Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 39/83] net/mlx5: E-Switch, Fix double allocation of acl flow counter Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 40/83] phy: mdio: fix memory leak Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 41/83] net_sched: fix NULL deref in fifo_set_limit() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 42/83] powerpc/fsl/dts: Fix phy-connection-type for fm1mac3 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 43/83] ptp_pch: Load module automatically if ID matches Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 44/83] arm64: dts: ls1028a: add missing CAN nodes Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 45/83] dt-bindings: drm/bridge: ti-sn65dsi86: Fix reg value Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 46/83] ARM: imx6: disable the GIC CPU interface before calling stby-poweroff sequence Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 47/83] net: bridge: use nla_total_size_64bit() in br_get_linkxstats_size() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 48/83] net: bridge: fix under estimation " Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 49/83] net/sched: sch_taprio: properly cancel timer from taprio_destroy() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 50/83] net: sfp: Fix typo in state machine debug string Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 51/83] netlink: annotate data races around nlk->bound Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 52/83] perf jevents: Tidy error handling Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 53/83] bus: ti-sysc: Use CLKDM_NOAUTO for dra7 dcan1 for errata i893 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 54/83] drm/sun4i: dw-hdmi: Fix HDMI PHY clock setup Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 55/83] video: fbdev: gbefb: Only instantiate device when built for IP32 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 56/83] drm/nouveau: avoid a use-after-free when BO init fails Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 57/83] drm/nouveau/kms/nv50-: fix file release memory leak Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 58/83] drm/nouveau/debugfs: " Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 59/83] gve: Correct available tx qpl check Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 60/83] gve: Avoid freeing NULL pointer Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 61/83] rtnetlink: fix if_nlmsg_stats_size() under estimation Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 62/83] gve: fix gve_get_stats() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 63/83] gve: report 64bit tx_bytes counter from gve_handle_report_stats() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 64/83] i40e: fix endless loop under rtnl Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 65/83] i40e: Fix freeing of uninitialized misc IRQ vector Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 66/83] net: prefer socket bound to interface when not in VRF Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 67/83] powerpc/iommu: Report the correct most efficient DMA mask for PCI devices Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 68/83] i2c: acpi: fix resource leak in reconfiguration device addition Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 69/83] i2c: mediatek: Add OFFSET_EXT_CONF setting back Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 70/83] riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for write killable Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 71/83] bpf, s390: Fix potential memory leak about jit_data Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 72/83] RISC-V: Include clone3() on rv32 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 73/83] powerpc/bpf: Fix BPF_MOD when imm == 1 Greg Kroah-Hartman
2021-10-11 17:29   ` Naresh Kamboju
2021-10-11 17:34     ` Naresh Kamboju
2021-10-11 13:46 ` [PATCH 5.10 74/83] powerpc/bpf: Fix BPF_SUB when imm == 0x80000000 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 75/83] powerpc/64s: fix program check interrupt emergency stack path Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 76/83] pseries/eeh: Fix the kdump kernel crash during eeh_pseries_init Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 77/83] x86/platform/olpc: Correct ifdef symbol to intended CONFIG_OLPC_XO15_SCI Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 78/83] x86/Kconfig: Correct reference to MWINCHIP3D Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 79/83] x86/sev: Return an error on a returned non-zero SW_EXITINFO1[31:0] Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 80/83] x86/entry: Correct reference to intended CONFIG_64_BIT Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 81/83] x86/entry: Clear X86_FEATURE_SMAP when CONFIG_X86_SMAP=n Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 82/83] x86/hpet: Use another crystalball to evaluate HPET usability Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 83/83] scsi: ufs: core: Fix task management completion Greg Kroah-Hartman
2021-10-11 15:03   ` Hunter, Adrian
2021-10-11 15:30     ` Greg Kroah-Hartman
2021-10-11 16:16 ` [PATCH 5.10 00/83] 5.10.73-rc1 review Florian Fainelli

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=20211011134509.662607187@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=th.yasumatsu@gmail.com \
    /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