All of lore.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,
	syzbot+36712f50b0552615bf59@syzkaller.appspotmail.com,
	Leon Romanovsky <leonro@mellanox.com>,
	Jason Gunthorpe <jgg@mellanox.com>
Subject: [PATCH 4.15 23/72] RDMA/ucma: Ensure that CM_ID exists prior to access it
Date: Fri,  6 Apr 2018 15:23:58 +0200	[thread overview]
Message-ID: <20180406084351.310169723@linuxfoundation.org> (raw)
In-Reply-To: <20180406084349.367583460@linuxfoundation.org>

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

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

From: Leon Romanovsky <leonro@mellanox.com>

commit e8980d67d6017c8eee8f9c35f782c4bd68e004c9 upstream.

Prior to access UCMA commands, the context should be initialized
and connected to CM_ID with ucma_create_id(). In case user skips
this step, he can provide non-valid ctx without CM_ID and cause
to multiple NULL dereferences.

Also there are situations where the create_id can be raced with
other user access, ensure that the context is only shared to
other threads once it is fully initialized to avoid the races.

[  109.088108] BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
[  109.090315] IP: ucma_connect+0x138/0x1d0
[  109.092595] PGD 80000001dc02d067 P4D 80000001dc02d067 PUD 1da9ef067 PMD 0
[  109.095384] Oops: 0000 [#1] SMP KASAN PTI
[  109.097834] CPU: 0 PID: 663 Comm: uclose Tainted: G    B 4.16.0-rc1-00062-g2975d5de6428 #45
[  109.100816] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.0-0-g63451fca13-prebuilt.qemu-project.org 04/01/2014
[  109.105943] RIP: 0010:ucma_connect+0x138/0x1d0
[  109.108850] RSP: 0018:ffff8801c8567a80 EFLAGS: 00010246
[  109.111484] RAX: 0000000000000000 RBX: 1ffff100390acf50 RCX: ffffffff9d7812e2
[  109.114496] RDX: 1ffffffff3f507a5 RSI: 0000000000000297 RDI: 0000000000000297
[  109.117490] RBP: ffff8801daa15600 R08: 0000000000000000 R09: ffffed00390aceeb
[  109.120429] R10: 0000000000000001 R11: ffffed00390aceea R12: 0000000000000000
[  109.123318] R13: 0000000000000120 R14: ffff8801de6459c0 R15: 0000000000000118
[  109.126221] FS:  00007fabb68d6700(0000) GS:ffff8801e5c00000(0000) knlGS:0000000000000000
[  109.129468] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  109.132523] CR2: 0000000000000020 CR3: 00000001d45d8003 CR4: 00000000003606b0
[  109.135573] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[  109.138716] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[  109.142057] Call Trace:
[  109.144160]  ? ucma_listen+0x110/0x110
[  109.146386]  ? wake_up_q+0x59/0x90
[  109.148853]  ? futex_wake+0x10b/0x2a0
[  109.151297]  ? save_stack+0x89/0xb0
[  109.153489]  ? _copy_from_user+0x5e/0x90
[  109.155500]  ucma_write+0x174/0x1f0
[  109.157933]  ? ucma_resolve_route+0xf0/0xf0
[  109.160389]  ? __mod_node_page_state+0x1d/0x80
[  109.162706]  __vfs_write+0xc4/0x350
[  109.164911]  ? kernel_read+0xa0/0xa0
[  109.167121]  ? path_openat+0x1b10/0x1b10
[  109.169355]  ? fsnotify+0x899/0x8f0
[  109.171567]  ? fsnotify_unmount_inodes+0x170/0x170
[  109.174145]  ? __fget+0xa8/0xf0
[  109.177110]  vfs_write+0xf7/0x280
[  109.179532]  SyS_write+0xa1/0x120
[  109.181885]  ? SyS_read+0x120/0x120
[  109.184482]  ? compat_start_thread+0x60/0x60
[  109.187124]  ? SyS_read+0x120/0x120
[  109.189548]  do_syscall_64+0xeb/0x250
[  109.192178]  entry_SYSCALL_64_after_hwframe+0x21/0x86
[  109.194725] RIP: 0033:0x7fabb61ebe99
[  109.197040] RSP: 002b:00007fabb68d5e98 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
[  109.200294] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fabb61ebe99
[  109.203399] RDX: 0000000000000120 RSI: 00000000200001c0 RDI: 0000000000000004
[  109.206548] RBP: 00007fabb68d5ec0 R08: 0000000000000000 R09: 0000000000000000
[  109.209902] R10: 0000000000000000 R11: 0000000000000202 R12: 00007fabb68d5fc0
[  109.213327] R13: 0000000000000000 R14: 00007fff40ab2430 R15: 00007fabb68d69c0
[  109.216613] Code: 88 44 24 2c 0f b6 84 24 6e 01 00 00 88 44 24 2d 0f
b6 84 24 69 01 00 00 88 44 24 2e 8b 44 24 60 89 44 24 30 e8 da f6 06 ff
31 c0 <66> 41 83 7c 24 20 1b 75 04 8b 44 24 64 48 8d 74 24 20 4c 89 e7
[  109.223602] RIP: ucma_connect+0x138/0x1d0 RSP: ffff8801c8567a80
[  109.226256] CR2: 0000000000000020

Fixes: 75216638572f ("RDMA/cma: Export rdma cm interface to userspace")
Reported-by: <syzbot+36712f50b0552615bf59@syzkaller.appspotmail.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/infiniband/core/ucma.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -132,7 +132,7 @@ static inline struct ucma_context *_ucma
 	ctx = idr_find(&ctx_idr, id);
 	if (!ctx)
 		ctx = ERR_PTR(-ENOENT);
-	else if (ctx->file != file)
+	else if (ctx->file != file || !ctx->cm_id)
 		ctx = ERR_PTR(-EINVAL);
 	return ctx;
 }
@@ -456,6 +456,7 @@ static ssize_t ucma_create_id(struct ucm
 	struct rdma_ucm_create_id cmd;
 	struct rdma_ucm_create_id_resp resp;
 	struct ucma_context *ctx;
+	struct rdma_cm_id *cm_id;
 	enum ib_qp_type qp_type;
 	int ret;
 
@@ -476,10 +477,10 @@ static ssize_t ucma_create_id(struct ucm
 		return -ENOMEM;
 
 	ctx->uid = cmd.uid;
-	ctx->cm_id = rdma_create_id(current->nsproxy->net_ns,
-				    ucma_event_handler, ctx, cmd.ps, qp_type);
-	if (IS_ERR(ctx->cm_id)) {
-		ret = PTR_ERR(ctx->cm_id);
+	cm_id = rdma_create_id(current->nsproxy->net_ns,
+			       ucma_event_handler, ctx, cmd.ps, qp_type);
+	if (IS_ERR(cm_id)) {
+		ret = PTR_ERR(cm_id);
 		goto err1;
 	}
 
@@ -489,10 +490,12 @@ static ssize_t ucma_create_id(struct ucm
 		ret = -EFAULT;
 		goto err2;
 	}
+
+	ctx->cm_id = cm_id;
 	return 0;
 
 err2:
-	rdma_destroy_id(ctx->cm_id);
+	rdma_destroy_id(cm_id);
 err1:
 	mutex_lock(&mut);
 	idr_remove(&ctx_idr, ctx->id);

  parent reply	other threads:[~2018-04-06 13:23 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 13:23 [PATCH 4.15 00/72] 4.15.16-stable review Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 01/72] ARM: OMAP: Fix SRAM W+X mapping Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 02/72] ARM: 8746/1: vfp: Go back to clearing vfp_current_hw_state[] Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 03/72] ARM: dts: sun6i: a31s: bpi-m2: improve pmic properties Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 04/72] ARM: dts: sun6i: a31s: bpi-m2: add missing regulators Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 05/72] mtd: jedec_probe: Fix crash in jedec_read_mfr() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 06/72] mtd: nand: atmel: Fix get_sectorsize() function Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 07/72] ALSA: usb-audio: Add native DSD support for TEAC UD-301 Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 08/72] ALSA: pcm: Use dma_bytes as size parameter in dma_mmap_coherent() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 09/72] ALSA: pcm: potential uninitialized return values Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 10/72] x86/platform/uv/BAU: Add APIC idt entry Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 11/72] perf/hwbp: Simplify the perf-hwbp code, fix documentation Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 12/72] ceph: only dirty ITER_IOVEC pages for direct read Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 13/72] ipc/shm.c: add split function to shm_vm_ops Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 14/72] i2c: i2c-stm32f7: fix no check on returned setup Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 15/72] powerpc/mm: Add tracking of the number of coprocessors using a context Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 16/72] powerpc/mm: Workaround Nest MMU bug with TLB invalidations Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 17/72] powerpc/64s: Fix lost pending interrupt due to race causing lost update to irq_happened Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 18/72] powerpc/64s: Fix i-side SLB miss bad address handler saving nonvolatile GPRs Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 19/72] partitions/msdos: Unable to mount UFS 44bsd partitions Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 20/72] xfrm_user: uncoditionally validate esn replay attribute struct Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 21/72] RDMA/ucma: Check AF family prior resolving address Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 4.15 22/72] RDMA/ucma: Fix use-after-free access in ucma_close Greg Kroah-Hartman
2018-04-06 13:23 ` Greg Kroah-Hartman [this message]
2018-04-06 13:23 ` [PATCH 4.15 24/72] RDMA/rdma_cm: Fix use after free race with process_one_req Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 25/72] RDMA/ucma: Check that device is connected prior to access it Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 26/72] RDMA/ucma: Check that device exists prior to accessing it Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 27/72] RDMA/ucma: Introduce safer rdma_addr_size() variants Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 28/72] ipv6: fix possible deadlock in rt6_age_examine_exception() Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 29/72] net: xfrm: use preempt-safe this_cpu_read() in ipcomp_alloc_tfms() Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 30/72] xfrm: Refuse to insert 32 bit userspace socket policies on 64 bit systems Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 31/72] percpu: add __GFP_NORETRY semantics to the percpu balancing path Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 32/72] netfilter: x_tables: make allocation less aggressive Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 33/72] netfilter: bridge: ebt_among: add more missing match size checks Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 34/72] l2tp: fix races with ipv4-mapped ipv6 addresses Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 35/72] netfilter: drop template ct when conntrack is skipped Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 36/72] netfilter: x_tables: add and use xt_check_proc_name Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 37/72] phy: qcom-ufs: add MODULE_LICENSE tag Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 38/72] Bluetooth: Fix missing encryption refresh on Security Request Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 39/72] drm/i915/dp: Write to SET_POWER dpcd to enable MST hub Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 40/72] bitmap: fix memset optimization on big-endian systems Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 41/72] USB: serial: ftdi_sio: add RT Systems VX-8 cable Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 42/72] USB: serial: ftdi_sio: add support for Harman FirmwareHubEmulator Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 43/72] USB: serial: cp210x: add ELDAT Easywave RX09 id Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 44/72] serial: 8250: Add Nuvoton NPCM UART Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 45/72] mei: remove dev_err message on an unsupported ioctl Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 46/72] /dev/mem: Avoid overwriting "err" in read_mem() Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 47/72] media: usbtv: prevent double free in error case Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 48/72] parport_pc: Add support for WCH CH382L PCI-E single parallel port card Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 49/72] crypto: lrw - Free rctx->ext with kzfree Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 50/72] crypto: talitos - dont persistently map req_ctx->hw_context and req_ctx->buf Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 51/72] crypto: inside-secure - fix clock management Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 52/72] crypto: testmgr - Fix incorrect values in PKCS#1 test vector Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 53/72] crypto: talitos - fix IPsec cipher in length Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 54/72] crypto: ahash - Fix early termination in hash walk Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 55/72] crypto: caam - Fix null dereference at error path Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 56/72] crypto: ccp - return an actual key size from RSA max_size callback Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 57/72] crypto: arm,arm64 - Fix random regeneration of S_shipped Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 58/72] crypto: x86/cast5-avx - fix ECB encryption when long sg follows short one Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 59/72] Btrfs: fix unexpected cow in run_delalloc_nocow Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 60/72] staging: comedi: ni_mio_common: ack ai fifo error interrupts Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 61/72] Revert "base: arch_topology: fix section mismatch build warnings" Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 62/72] Input: ALPS - fix TrackStick detection on Thinkpad L570 and Latitude 7370 Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 63/72] Input: i8042 - add Lenovo ThinkPad L460 to i8042 reset list Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 64/72] Input: i8042 - enable MUX on Sony VAIO VGN-CS series to fix touchpad Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 65/72] vt: change SGR 21 to follow the standards Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 66/72] ARM: dts: DRA76-EVM: Set powerhold property for tps65917 Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 67/72] net: hns: Fix ethtool private flags Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 68/72] Fix slab name "biovec-(1<<(21-12))" Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 69/72] Revert "ARM: dts: am335x-pepper: Fix the audio CODECs reset pin" Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 70/72] Revert "ARM: dts: omap3-n900: " Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 71/72] Revert "cpufreq: Fix governor module removal race" Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 4.15 72/72] Revert "ip6_vti: adjust vti mtu according to mtu of lower device" Greg Kroah-Hartman
2018-04-06 14:38 ` [PATCH 4.15 00/72] 4.15.16-stable review Naresh Kamboju
2018-04-06 17:42 ` kernelci.org bot
2018-04-06 20:20 ` Thadeu Lima de Souza Cascardo
2018-04-07  6:10   ` Greg Kroah-Hartman
2018-04-06 22:08 ` Shuah Khan

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=20180406084351.310169723@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=jgg@mellanox.com \
    --cc=leonro@mellanox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+36712f50b0552615bf59@syzkaller.appspotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.