Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2481912imm; Mon, 24 Sep 2018 05:14:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV61NrSc1uPWZHah+3dFxZBS1wSmrSmYHhM+OGmnw8hlb3EAL2lxevhSmR5tiQkN53PZdc5MT X-Received: by 2002:a63:dc17:: with SMTP id s23-v6mr9394047pgg.40.1537791295170; Mon, 24 Sep 2018 05:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537791295; cv=none; d=google.com; s=arc-20160816; b=kWQPaT7pLCdEmsFcb6+k1nf0izygpUpxtQkKtCbCUdAVMRiEN/FpCCoXT+rB1PEK9P ngng7mo814oZQWi/bI88NH0jXn9asrjASNixZ/NSeCXvjXfe7eMFVj6Jt+qQOTj1qYHr WuI6UKNbiEJdm7hXcjTE5/Y6iUQPaFfwmOA6mgquR5xEY3hJtzPs58YK0vJCYn7F6pqy Q+Mxr5eh3Yisf+SIng2WkahBac3l8iGHzvkECoV9FKyqPv7YVOMOwkkpkEUy4sG/HQlQ EVXYcHhejNHIFovbESW6rQTdeZmcVGekx4+EgisqHvXf6QOrAgQwMkK/hVgSdH826su0 42bw== 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; bh=kurtabvuhUGYrLi2IBh6l94S7zm1qcuicQPSV8o8D3M=; b=DyGClU77dx16fLe6WfTDdbPyR5x39cb4WsSi1rdgkzQKbH+p81GiR6ESR1UDn3RuoA 79uoSRcncZ2A33cd8Ei9cgzryCuAG+q0EA2PVfwvKmo8vtTTipzLFQA1HeYbVJ+1PJ5m X9e/Yz32kpGBG08gUn/3fQZgFtoa846Aistghrrt8mXvg3MIHGgrgE/GqNQ5LVD381PZ /TooIN5zzsb3IzDJjjRXSLSutU4aF1PzTF0XuExggiMBQwcKURXZUFVRGRog6r/lC9Tq oYuGomXnGbMeVDWT6X6Y60LPU0t3L0xun5T7fKWELuIcXOULhgV3OxFcoXDX/i9jOquQ sKgw== 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 h16-v6si33870599pgj.611.2018.09.24.05.14.39; Mon, 24 Sep 2018 05:14:55 -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; 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 S1731442AbeIXSOY (ORCPT + 99 others); Mon, 24 Sep 2018 14:14:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55044 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbeIXSOX (ORCPT ); Mon, 24 Sep 2018 14:14:23 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E5D94107D; Mon, 24 Sep 2018 12:12:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Morgenstein , Feras Daoud , Saeed Mahameed Subject: [PATCH 4.14 002/173] net/mlx5: Fix use-after-free in self-healing flow Date: Mon, 24 Sep 2018 13:50:36 +0200 Message-Id: <20180924113114.625280820@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113114.334025954@linuxfoundation.org> References: <20180924113114.334025954@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jack Morgenstein [ Upstream commit 76d5581c870454be5f1f1a106c57985902e7ea20 ] When the mlx5 health mechanism detects a problem while the driver is in the middle of init_one or remove_one, the driver needs to prevent the health mechanism from scheduling future work; if future work is scheduled, there is a problem with use-after-free: the system WQ tries to run the work item (which has been freed) at the scheduled future time. Prevent this by disabling work item scheduling in the health mechanism when the driver is in the middle of init_one() or remove_one(). Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Signed-off-by: Jack Morgenstein Reviewed-by: Feras Daoud Signed-off-by: Saeed Mahameed Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/health.c | 10 +++++++++- drivers/net/ethernet/mellanox/mlx5/core/main.c | 6 +++--- include/linux/mlx5/driver.h | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/health.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c @@ -333,9 +333,17 @@ void mlx5_start_health_poll(struct mlx5_ add_timer(&health->timer); } -void mlx5_stop_health_poll(struct mlx5_core_dev *dev) +void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health) { struct mlx5_core_health *health = &dev->priv.health; + unsigned long flags; + + if (disable_health) { + spin_lock_irqsave(&health->wq_lock, flags); + set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags); + set_bit(MLX5_DROP_NEW_RECOVERY_WORK, &health->flags); + spin_unlock_irqrestore(&health->wq_lock, flags); + } del_timer_sync(&health->timer); } --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1227,7 +1227,7 @@ err_cleanup_once: mlx5_cleanup_once(dev); err_stop_poll: - mlx5_stop_health_poll(dev); + mlx5_stop_health_poll(dev, boot); if (mlx5_cmd_teardown_hca(dev)) { dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n"); goto out_err; @@ -1286,7 +1286,7 @@ static int mlx5_unload_one(struct mlx5_c mlx5_free_irq_vectors(dev); if (cleanup) mlx5_cleanup_once(dev); - mlx5_stop_health_poll(dev); + mlx5_stop_health_poll(dev, cleanup); err = mlx5_cmd_teardown_hca(dev); if (err) { dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n"); @@ -1548,7 +1548,7 @@ static int mlx5_try_fast_unload(struct m * with the HCA, so the health polll is no longer needed. */ mlx5_drain_health_wq(dev); - mlx5_stop_health_poll(dev); + mlx5_stop_health_poll(dev, false); ret = mlx5_cmd_force_teardown_hca(dev); if (ret) { --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -950,7 +950,7 @@ int mlx5_cmd_free_uar(struct mlx5_core_d void mlx5_health_cleanup(struct mlx5_core_dev *dev); int mlx5_health_init(struct mlx5_core_dev *dev); void mlx5_start_health_poll(struct mlx5_core_dev *dev); -void mlx5_stop_health_poll(struct mlx5_core_dev *dev); +void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health); void mlx5_drain_health_wq(struct mlx5_core_dev *dev); void mlx5_trigger_health_work(struct mlx5_core_dev *dev); void mlx5_drain_health_recovery(struct mlx5_core_dev *dev);