Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp266125img; Mon, 18 Mar 2019 02:38:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFSv//puEpB1+mzuuwUuvvE5hjChC3vsPHpaOzldb6Lq99pwJmRvF/uNkt23ImapRRAgGL X-Received: by 2002:a62:449b:: with SMTP id m27mr18379507pfi.79.1552901884066; Mon, 18 Mar 2019 02:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901884; cv=none; d=google.com; s=arc-20160816; b=yXz7ymldNwmqUrG9bcC5MtCLXJr/KlUppJvy/BW7q12owkkEyY3z84Em01g3gZYLQI vXw+WrUcg7DlfjY+UIefpdfnAIgesXhlWnzk/6kZllVuz+tpOkjenTJnRwU/RTRjDcGa pB/D+PQtcWKNcj1z3dWq7vHvSeSlbCTl/cNKrBGuJ80NrJoNdk0n+ikClDrTwftJ8YS6 PfIzvvpm//jfPt3vHCDteTIao86sbIZ4Ly4Qr37dWHeeQMGZot571gvS4sJbN2XgIgwH qiwCgpAQDM90734yU8VLMr540hUWkhzHJ9n8ucjouXrOfBV54qInf/MAYn9OR3gPvhUo C2Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jEwKyj26aQtsIhbBDB1qqFLosahhIi70WkX3qhtxE0c=; b=IvkJc4D1zipNwGU9/XtGZH80twajNg5+KetG/bEhTWXZcg/zj/qPCxM2oOtboScKDl 53+jLK0RuhxQqvOPHlt7oIgNZjKtNqcrEi2kIlDnexEbmpFCABZCZeBubrk5fRfoUCz2 6LbdWgLzF0D5/yC8+xgGqiCa0pPn/dLFWyey8RMZPtXQRGo4vOlfxlRhKMipAanO5AoW jr4kWgOAg8SVg8otN50clfRFqhN4/Ojn2qi4skaB9Zy65RzPbcbkDk8tsoHRrnhMdCQI pw1lHrjZAT6RkDTtapFxWF+ctqBY1F/Vv3bbSPWjIVlO9u0q/ACViIbFI5Yfza/Dn6kI CuYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Uu8pInKh; 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 m18si1136723pgl.483.2019.03.18.02.37.49; Mon, 18 Mar 2019 02:38:04 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=Uu8pInKh; 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 S2387674AbfCRJgb (ORCPT + 99 others); Mon, 18 Mar 2019 05:36:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:44796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387665AbfCRJg1 (ORCPT ); Mon, 18 Mar 2019 05:36:27 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 68F4021738; Mon, 18 Mar 2019 09:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901786; bh=76+w88JO2TX69a7yZ/jmI5t/ROT0uqb4BtaSarIw1Nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uu8pInKhqfrcaG7so4dPvvvvIfTbw/hZrnfSE5HovO8PY0OetJfFQ8heGwjdWLPBx o+BJQv684SQ84f0BkQSbWjmX6X51LJqAVyRBDImhp99N6vnTLSHqAwIilCnN43gzSf 8BuEx91BZLGnY0R+y98Xo4ldZhQ4C0qaagAerXAQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Morgenstein , Tariq Toukan , "David S. Miller" Subject: [PATCH 4.9 14/31] net/mlx4_core: Fix reset flow when in command polling mode Date: Mon, 18 Mar 2019 10:25:49 +0100 Message-Id: <20190318084210.968316214@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084210.397476003@linuxfoundation.org> References: <20190318084210.397476003@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jack Morgenstein [ Upstream commit e15ce4b8d11227007577e6dc1364d288b8874fbe ] As part of unloading a device, the driver switches from FW command event mode to FW command polling mode. Part of switching over to polling mode is freeing the command context array memory (unfortunately, currently, without NULLing the command context array pointer). The reset flow calls "complete" to complete all outstanding fw commands (if we are in event mode). The check for event vs. polling mode here is to test if the command context array pointer is NULL. If the reset flow is activated after the switch to polling mode, it will attempt (incorrectly) to complete all the commands in the context array -- because the pointer was not NULLed when the driver switched over to polling mode. As a result, we have a use-after-free situation, which results in a kernel crash. For example: BUG: unable to handle kernel NULL pointer dereference at (null) IP: [] __wake_up_common+0x2e/0x90 PGD 0 Oops: 0000 [#1] SMP Modules linked in: netconsole nfsv3 nfs_acl nfs lockd grace ... CPU: 2 PID: 940 Comm: kworker/2:3 Kdump: loaded Not tainted 3.10.0-862.el7.x86_64 #1 Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS 090006 04/28/2016 Workqueue: events hv_eject_device_work [pci_hyperv] task: ffff8d1734ca0fd0 ti: ffff8d17354bc000 task.ti: ffff8d17354bc000 RIP: 0010:[] [] __wake_up_common+0x2e/0x90 RSP: 0018:ffff8d17354bfa38 EFLAGS: 00010082 RAX: 0000000000000000 RBX: ffff8d17362d42c8 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000003 RDI: ffff8d17362d42c8 RBP: ffff8d17354bfa70 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000298 R11: ffff8d173610e000 R12: ffff8d17362d42d0 R13: 0000000000000246 R14: 0000000000000000 R15: 0000000000000003 FS: 0000000000000000(0000) GS:ffff8d1802680000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 00000000f16d8000 CR4: 00000000001406e0 Call Trace: [] complete+0x3c/0x50 [] mlx4_cmd_wake_completions+0x70/0x90 [mlx4_core] [] mlx4_enter_error_state+0xe1/0x380 [mlx4_core] [] mlx4_comm_cmd+0x29b/0x360 [mlx4_core] [] __mlx4_cmd+0x441/0x920 [mlx4_core] [] ? __slab_free+0x81/0x2f0 [] ? __radix_tree_lookup+0x84/0xf0 [] mlx4_free_mtt_range+0x5b/0xb0 [mlx4_core] [] mlx4_mtt_cleanup+0x17/0x20 [mlx4_core] [] mlx4_free_eq+0xa7/0x1c0 [mlx4_core] [] mlx4_cleanup_eq_table+0xde/0x130 [mlx4_core] [] mlx4_unload_one+0x118/0x300 [mlx4_core] [] mlx4_remove_one+0x91/0x1f0 [mlx4_core] The fix is to set the command context array pointer to NULL after freeing the array. Fixes: f5aef5aa3506 ("net/mlx4_core: Activate reset flow upon fatal command cases") Signed-off-by: Jack Morgenstein Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx4/cmd.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -2677,6 +2677,7 @@ void mlx4_cmd_use_polling(struct mlx4_de down(&priv->cmd.event_sem); kfree(priv->cmd.context); + priv->cmd.context = NULL; up(&priv->cmd.poll_sem); up_write(&priv->cmd.switch_sem);