Received: by 10.223.185.116 with SMTP id b49csp722131wrg; Wed, 21 Feb 2018 05:58:55 -0800 (PST) X-Google-Smtp-Source: AH8x226POqD1Ra9o3AuaVs+kBDi0gZww13OUDAhvoFZftNTSGbBFqrqgupCizduSbHZdsn6Imfcs X-Received: by 10.99.156.17 with SMTP id f17mr2864174pge.12.1519221535687; Wed, 21 Feb 2018 05:58:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519221535; cv=none; d=google.com; s=arc-20160816; b=iv7gnqv/qXNwuIbpePOv+tKZam8U8BjXT6CFjXHvvWxcjrjElNJ0k5DgQje0WlX71w ikzghPM/XGHbez3iy/m72oQJHSNVZNBq2A19qAqXyCRYEuJFQfEr6wV0Sprjsw6o6xMf rxeHZSUd+dV4PuD1gZXjkZSM0TMS75icmlf4RTtJi1MFES+xSAboF5i4cyPhDZ6Xr5+/ uq+rcbOitJoS7daPTbi/askf463Un8jReX8j7o8KrLWW9vksZ5vnDv5Scpaz0Dob+7e+ 2TCKM4DHChb7RC1p18vyrI4kEqV6bMKUXAd9hjbqmn3XlySfeRGKrrlviC1Bv2Ww6aoR L6SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=y80s4MZGfPV3sGUwrz3BIrahDQXQ1rHq/xFfAJmEfL0=; b=Dikz24nnjwbAFbAllj8+tdCqYKPyDRQck2wU7DfIAc9iQda5FnDj18tkw3svXbu8At AsaVw7dVa4fwkJK2SP5htJKGnY3DN9RXT6XiNs19IVFV4B3a7g6j8eD0QrBMx/qhVORW BYXksFnaG78APaw8zkE1l05KdRXmKXUGREscSSGrm8sekBqyze7GzqiEA2qCIffWIPtF xIIr11R5P8aGKNL5uuoze31YtgzrzmiXoSj0FblABLeBJLGsRjLzUoYOATu2iEjxQEDs rffmrXF1TXSigBXFrH4OkWZY471Rh8E1PEKfQczK/tEtIROmlnCJ4ZKa4QUyaCZk5T4P kZ3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p187si11071400pfb.175.2018.02.21.05.58.41; Wed, 21 Feb 2018 05:58:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936706AbeBUNsB (ORCPT + 99 others); Wed, 21 Feb 2018 08:48:01 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40630 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751948AbeBUNGQ (ORCPT ); Wed, 21 Feb 2018 08:06:16 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7FF8411D6; Wed, 21 Feb 2018 13:06:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Morgenstein , Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 4.15 002/163] IB/umad: Fix use of unprotected device pointer Date: Wed, 21 Feb 2018 13:47:11 +0100 Message-Id: <20180221124530.075643868@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jack Morgenstein commit f23a5350e43c810ca36b26d4ed4ecd9a08686f47 upstream. The ib_write_umad() is protected by taking the umad file mutex. However, it accesses file->port->ib_dev -- which is protected only by the port's mutex (field file_mutex). The ib_umad_remove_one() calls ib_umad_kill_port() which sets port->ib_dev to NULL under the port mutex (NOT the file mutex). It then sets the mad agent to "dead" under the umad file mutex. This is a race condition -- because there is a window where port->ib_dev is NULL, while the agent is not "dead". As a result, we saw stack traces like: [16490.678059] BUG: unable to handle kernel NULL pointer dereference at 00000000000000b0 [16490.678246] IP: ib_umad_write+0x29c/0xa3a [ib_umad] [16490.678333] PGD 0 P4D 0 [16490.678404] Oops: 0000 [#1] SMP PTI [16490.678466] Modules linked in: rdma_ucm(OE) ib_ucm(OE) rdma_cm(OE) iw_cm(OE) ib_ipoib(OE) ib_cm(OE) ib_uverbs(OE) ib_umad(OE) mlx4_en(OE) ptp pps_core mlx4_ib(OE-) ib_core(OE) mlx4_core(OE) mlx_compat (OE) memtrack(OE) devlink mst_pciconf(OE) mst_pci(OE) netconsole nfsv3 nfs_acl nfs lockd grace fscache cfg80211 rfkill esp6_offload esp6 esp4_offload esp4 sunrpc kvm_intel kvm ppdev parport_pc irqbypass parport joydev i2c_piix4 virtio_balloon cirrus drm_kms_helper ttm drm e1000 serio_raw virtio_pci virtio_ring virtio ata_generic pata_acpi qemu_fw_cfg [last unloaded: mlxfw] [16490.679202] CPU: 4 PID: 3115 Comm: sminfo Tainted: G OE 4.14.13-300.fc27.x86_64 #1 [16490.679339] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu2 04/01/2014 [16490.679477] task: ffff9cf753890000 task.stack: ffffaf70c26b0000 [16490.679571] RIP: 0010:ib_umad_write+0x29c/0xa3a [ib_umad] [16490.679664] RSP: 0018:ffffaf70c26b3d90 EFLAGS: 00010202 [16490.679747] RAX: 0000000000000010 RBX: ffff9cf75610fd80 RCX: 0000000000000000 [16490.679856] RDX: 0000000000000001 RSI: 00007ffdf2bfd714 RDI: ffff9cf6bb2a9c00 In the above trace, ib_umad_write is trying to dereference the NULL file->port->ib_dev pointer. Fix this by using the agent's device pointer (the device field in struct ib_mad_agent) -- which IS protected by the umad file mutex. Fixes: 44c58487d51a ("IB/core: Define 'ib' and 'roce' rdma_ah_attr types") Signed-off-by: Jack Morgenstein Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/user_mad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -500,7 +500,7 @@ static ssize_t ib_umad_write(struct file } memset(&ah_attr, 0, sizeof ah_attr); - ah_attr.type = rdma_ah_find_type(file->port->ib_dev, + ah_attr.type = rdma_ah_find_type(agent->device, file->port->port_num); rdma_ah_set_dlid(&ah_attr, be16_to_cpu(packet->mad.hdr.lid)); rdma_ah_set_sl(&ah_attr, packet->mad.hdr.sl);