stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Dan Carpenter <dan.carpenter@linaro.org>,
	Leon Romanovsky <leon@kernel.org>
Subject: [PATCH 5.4 88/93] RDMA/uverbs: Prevent integer overflow issue
Date: Mon,  6 Jan 2025 16:18:04 +0100	[thread overview]
Message-ID: <20250106151132.024284049@linuxfoundation.org> (raw)
In-Reply-To: <20250106151128.686130933@linuxfoundation.org>

5.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Dan Carpenter <dan.carpenter@linaro.org>

commit d0257e089d1bbd35c69b6c97ff73e3690ab149a9 upstream.

In the expression "cmd.wqe_size * cmd.wr_count", both variables are u32
values that come from the user so the multiplication can lead to integer
wrapping.  Then we pass the result to uverbs_request_next_ptr() which also
could potentially wrap.  The "cmd.sge_count * sizeof(struct ib_uverbs_sge)"
multiplication can also overflow on 32bit systems although it's fine on
64bit systems.

This patch does two things.  First, I've re-arranged the condition in
uverbs_request_next_ptr() so that the use controlled variable "len" is on
one side of the comparison by itself without any math.  Then I've modified
all the callers to use size_mul() for the multiplications.

Fixes: 67cdb40ca444 ("[IB] uverbs: Implement more commands")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://patch.msgid.link/b8765ab3-c2da-4611-aae0-ddd6ba173d23@stanley.mountain
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/infiniband/core/uverbs_cmd.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -161,7 +161,7 @@ static const void __user *uverbs_request
 {
 	const void __user *res = iter->cur;
 
-	if (iter->cur + len > iter->end)
+	if (len > iter->end - iter->cur)
 		return (void __force __user *)ERR_PTR(-ENOSPC);
 	iter->cur += len;
 	return res;
@@ -2024,11 +2024,13 @@ static int ib_uverbs_post_send(struct uv
 	ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
 	if (ret)
 		return ret;
-	wqes = uverbs_request_next_ptr(&iter, cmd.wqe_size * cmd.wr_count);
+	wqes = uverbs_request_next_ptr(&iter, size_mul(cmd.wqe_size,
+						       cmd.wr_count));
 	if (IS_ERR(wqes))
 		return PTR_ERR(wqes);
-	sgls = uverbs_request_next_ptr(
-		&iter, cmd.sge_count * sizeof(struct ib_uverbs_sge));
+	sgls = uverbs_request_next_ptr(&iter,
+				       size_mul(cmd.sge_count,
+						sizeof(struct ib_uverbs_sge)));
 	if (IS_ERR(sgls))
 		return PTR_ERR(sgls);
 	ret = uverbs_request_finish(&iter);
@@ -2213,11 +2215,11 @@ ib_uverbs_unmarshall_recv(struct uverbs_
 	if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
 		return ERR_PTR(-EINVAL);
 
-	wqes = uverbs_request_next_ptr(iter, wqe_size * wr_count);
+	wqes = uverbs_request_next_ptr(iter, size_mul(wqe_size, wr_count));
 	if (IS_ERR(wqes))
 		return ERR_CAST(wqes);
-	sgls = uverbs_request_next_ptr(
-		iter, sge_count * sizeof(struct ib_uverbs_sge));
+	sgls = uverbs_request_next_ptr(iter, size_mul(sge_count,
+						      sizeof(struct ib_uverbs_sge)));
 	if (IS_ERR(sgls))
 		return ERR_CAST(sgls);
 	ret = uverbs_request_finish(iter);



  parent reply	other threads:[~2025-01-06 16:02 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 15:16 [PATCH 5.4 00/93] 5.4.289-rc1 review Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 01/93] net: sched: fix ordering of qlen adjustment Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 02/93] usb: dwc2: gadget: Dont write invalid mapped sg entries into dma_desc with iommu enabled Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 03/93] PCI/AER: Disable AER service on suspend Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 04/93] ALSA: usb: Fix UBSAN warning in parse_audio_unit() Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 05/93] PCI: Add ACS quirk for Broadcom BCM5760X NIC Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 06/93] i2c: pnx: Fix timeout in wait functions Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 07/93] drm/i915: Fix memory leak by correcting cache object name in error handler Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 08/93] erofs: fix order >= MAX_ORDER warning due to crafted negative i_size Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 09/93] erofs: fix incorrect symlink detection in fast symlink Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 10/93] net/smc: check sndbuf_space again after NOSPACE flag is set in smc_poll Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 11/93] ionic: use ee->offset when returning sprom data Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 12/93] net: hinic: Fix cleanup in create_rxqs/txqs() Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 13/93] net: ethernet: bgmac-platform: fix an OF node reference leak Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 14/93] netfilter: ipset: Fix for recursive locking warning Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 15/93] mmc: sdhci-tegra: Remove SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC quirk Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 16/93] chelsio/chtls: prevent potential integer overflow on 32bit Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 17/93] i2c: riic: Always round-up when calculating bus period Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 18/93] efivarfs: Fix error on non-existent file Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 19/93] USB: serial: option: add TCL IK512 MBIM & ECM Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 20/93] USB: serial: option: add MeiG Smart SLM770A Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 21/93] USB: serial: option: add Netprisma LCUK54 modules for WWAN Ready Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 22/93] USB: serial: option: add MediaTek T7XX compositions Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 23/93] USB: serial: option: add Telit FE910C04 rmnet compositions Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 24/93] sh: clk: Fix clk_enable() to return 0 on NULL clk Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 25/93] zram: refuse to use zero sized block device as backing device Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 26/93] btrfs: tree-checker: reject inline extent items with 0 ref count Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 27/93] NFS/pnfs: Fix a live lock between recalled layouts and layoutget Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 28/93] of/irq: Fix using uninitialized variable @addr_len in API of_irq_parse_one() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 29/93] nilfs2: prevent use of deleted inode Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 30/93] udmabuf: also check for F_SEAL_FUTURE_WRITE Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 31/93] of: Fix error path in of_parse_phandle_with_args_map() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 32/93] of: Fix refcount leakage for OF node returned by __of_get_dma_parent() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 33/93] media: dvb-frontends: dib3000mb: fix uninit-value in dib3000_write_reg Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 34/93] bpf: Check negative offsets in __bpf_skb_min_len() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 35/93] nfsd: restore callback functionality for NFSv4.0 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 36/93] mtd: diskonchip: Cast an operand to prevent potential overflow Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 37/93] phy: core: Fix an OF node refcount leakage in _of_phy_get() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 38/93] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 39/93] phy: core: Fix that API devm_phy_put() fails to release the phy Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 40/93] phy: core: Fix that API devm_phy_destroy() fails to destroy " Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 41/93] dmaengine: mv_xor: fix child node refcount handling in early exit Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 42/93] dmaengine: at_xdmac: avoid null_prt_deref in at_xdmac_prep_dma_memset Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 43/93] mtd: rawnand: fix double free in atmel_pmecc_create_user() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 44/93] tracing/kprobe: Make trace_kprobes module callback called after jump_label update Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 45/93] scsi: qla1280: Fix hw revision numbering for ISP1020/1040 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 46/93] scsi: megaraid_sas: Fix for a potential deadlock Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 47/93] regmap: Use correct format specifier for logging range errors Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 48/93] platform/x86: asus-nb-wmi: Ignore unknown event 0xCF Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 49/93] scsi: mpt3sas: Diag-Reset when Doorbell-In-Use bit is set during driver load time Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 50/93] virtio-blk: dont keep queue frozen during system suspend Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 51/93] epoll: Add synchronous wakeup support for ep_poll_callback Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 52/93] MIPS: Probe toolchain support of -msym32 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 53/93] skbuff: introduce skb_expand_head() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 54/93] ipv6: use skb_expand_head in ip6_finish_output2 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 55/93] ipv6: use skb_expand_head in ip6_xmit Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 56/93] ipv6: fix possible UAF in ip6_finish_output2() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 57/93] bpf: fix recursive lock when verdict program return SK_PASS Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 58/93] tracing: Constify string literal data member in struct trace_event_call Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 59/93] btrfs: avoid monopolizing a core when activating a swap file Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 60/93] skb_expand_head() adjust skb->truesize incorrectly Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 61/93] ipv6: prevent possible UAF in ip6_xmit() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 62/93] selinux: ignore unknown extended permissions Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 63/93] Drivers: hv: util: Avoid accessing a ringbuffer not initialized yet Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 64/93] IB/mlx5: Introduce and use mlx5_core_is_vf() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 65/93] net/mlx5: Make API mlx5_core_is_ecpf accept const pointer Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 66/93] RDMA/mlx5: Enforce same type port association for multiport RoCE Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 67/93] RDMA/bnxt_re: Add check for path mtu in modify_qp Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 68/93] RDMA/bnxt_re: Fix reporting hw_ver in query_device Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 69/93] RDMA/bnxt_re: Fix max_qp_wrs reported Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 70/93] drm: bridge: adv7511: Enable SPDIF DAI Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 71/93] drm/bridge: adv7511_audio: Update Audio InfoFrame properly Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 72/93] netrom: check buffer length before accessing it Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 73/93] netfilter: Replace zero-length array with flexible-array member Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 74/93] netfilter: nft_set_hash: unaligned atomic read on struct nft_set_ext Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 75/93] net: llc: reset skb->transport_header Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 76/93] ALSA: usb-audio: US16x08: Initialize array before use Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 77/93] af_packet: fix vlan_get_tci() vs MSG_PEEK Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 78/93] af_packet: fix vlan_get_protocol_dgram() " Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 79/93] ila: serialize calls to nf_register_net_hooks() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 80/93] wifi: mac80211: wake the queues in case of failure in resume Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 81/93] sound: usb: format: dont warn that raw DSD is unsupported Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 82/93] bpf: fix potential error return Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 83/93] net: usb: qmi_wwan: add Telit FE910C04 compositions Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 84/93] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 85/93] ARC: build: Try to guess GCC variant of cross compiler Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 86/93] modpost: fix input MODULE_DEVICE_TABLE() built for 64-bit on 32-bit host Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 87/93] modpost: fix the missed iteration for the max bit in do_input() Greg Kroah-Hartman
2025-01-06 15:18 ` Greg Kroah-Hartman [this message]
2025-01-06 15:18 ` [PATCH 5.4 89/93] pinctrl: mcp23s08: Fix sleeping in atomic context due to regmap locking Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 90/93] sky2: Add device ID 11ab:4373 for Marvell 88E8075 Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 91/93] net/sctp: Prevent autoclose integer overflow in sctp_association_init() Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 92/93] drm: adv7511: Drop dsi single lane support Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 93/93] mm: vmscan: account for free pages to prevent infinite Loop in throttle_direct_reclaim() Greg Kroah-Hartman
2025-01-06 18:58 ` [PATCH 5.4 00/93] 5.4.289-rc1 review Florian Fainelli
2025-01-07 12:43 ` Jon Hunter
2025-01-07 13:50 ` Naresh Kamboju
2025-01-07 23:16 ` Shuah Khan
2025-01-08 13:00 ` Muhammad Usama Anjum
2025-01-09 10:12   ` Greg Kroah-Hartman
2025-01-09 14:10     ` Muhammad Usama Anjum
2025-01-09 14:14       ` Mark Brown
2025-01-08 14:13 ` Harshit Mogalapalli

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=20250106151132.024284049@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=dan.carpenter@linaro.org \
    --cc=leon@kernel.org \
    --cc=patches@lists.linux.dev \
    --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).