Received: by 10.223.185.116 with SMTP id b49csp943946wrg; Wed, 21 Feb 2018 09:24:29 -0800 (PST) X-Google-Smtp-Source: AH8x225YkBlslM2+EuWbWPctZeaPvd6FiRHhT/cHW8V17s+zl8F1d9wHXLh0ZXmy4vmIreDAOhkl X-Received: by 10.99.113.90 with SMTP id b26mr3265660pgn.10.1519233869189; Wed, 21 Feb 2018 09:24:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519233869; cv=none; d=google.com; s=arc-20160816; b=beaWpPfJMTx5huGB1D+StMpVgjk5zjpBRGfB0k4frvfkSgz/fvgH6gRVAFFflKP9uE sFUFPMEIIBgnpKtZMaTKDi8m4qC6RtBI55VLBjo9+87BgINUTvWRVGjOZLhcmyRj449x ZcQRvmXX/9Pu56tvvhrb6yOfs8gDYIIXON1Z8Fsc1RFfb3NbvfdZl/vnNoF5JIATNC1j 8D3hzB5uAZF1Qb3SLDxatvsqvHQGUcYSAtc2I5JOllFuQDGAfIgijIZrkz9vQW+5AVsi rWUmpG/aNeI9dr6n/rAVz1ynbeAdozBWMirlYyQhJFHjGH642EzKRlz0znnbsv3Lu30A bwMQ== 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=M0+ZOJmjhZ9j9ypa+bdwWTM5G/3iF5tVhfLygwwaZrg=; b=s3J5ngpb8uSBIXiRKiduJiYnFy1voOO4Ll9be3cEoubFQgcWt7fO9Bq4CK/sY516ju /x7ZyIPeA+2XnV4TT/TPwaecV7qX07C5QTSEY7cnDPCOybLuusRtgEmkBardTBxgV5jp r3hE4yIVgRDVwxoBcayBfLXwbrOvlIjQDnEtCNGeHlpPyPolRA7fObnJGLsMK5wta2hi s1Kyrr1OSgMTLadiEipxV7PFvPkjZGBP1e4t/Tmab5qrKsc5oSby4McgC199//d3OFyn 9NcDTxh64VebXG2Tje9h+j9kn3Sbp3KUWW5zsB3yvHW/OBc/wv1ESxe8xZmKyQKXx6OH IgbQ== 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 y96-v6si104376plh.796.2018.02.21.09.24.14; Wed, 21 Feb 2018 09:24:29 -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 S935010AbeBUM7A (ORCPT + 99 others); Wed, 21 Feb 2018 07:59:00 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36312 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934977AbeBUM6y (ORCPT ); Wed, 21 Feb 2018 07:58:54 -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 0E89D94F; Wed, 21 Feb 2018 12:58:53 +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.14 003/167] IB/umad: Fix use of unprotected device pointer Date: Wed, 21 Feb 2018 13:46:54 +0100 Message-Id: <20180221124524.804122868@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124524.639039577@linuxfoundation.org> References: <20180221124524.639039577@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.14-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);