Received: by 10.192.165.156 with SMTP id m28csp1199051imm; Wed, 11 Apr 2018 14:24:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx49XAdGhXqpJv8npzYRKEPEVEvDx5NIYkrgAntE1ek/Pv83DJutZXt4enYVEqTzcbGCuhLlq X-Received: by 10.98.35.202 with SMTP id q71mr5383938pfj.9.1523481870094; Wed, 11 Apr 2018 14:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523481870; cv=none; d=google.com; s=arc-20160816; b=kprQkY/95K1v9JMTjhhUnLjJK9dsbRhEu9Ujtm/UkrDIKEmMPczldH38Dvknb1Uk5c UHXOJp7aebkJK5jSISst6yWxi0jc3Rg47nwzzlbTdG0HTmTYIAS1YneKmY5bMKswryBZ mpB1+8kkSHpWXTLNPXjPgL+1blP4VZDSkFM6dtNSfWXYtw3sLClUmrQvGyrHe2v7M4e/ dYvbo7hJGnq/i3xD+HTZcCkA2PAbllhEEf/aAXr2CINlG2jZtaTHh+wZS0i+ULzkUzyV pZZp0zlu9NADzNYFZdVhnDWKYN4oHf9uRqSDZF068xyYrrdFhowBP/1Tz3hQSjWkhevP 7QIA== 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=+VMNPVbrWELmTiUVamMr5PDI8YRTMDZfb2+MBGqUW0w=; b=vRufhmDPezLljXuVXFqqgur7Jy9tREZCZRzH90+KVHhuE0rG0ytUbWeciuhQXo8JKX okJAqyThIoqFprWcsDgNnX8F1NN2D8pfuArUcY2qELJ3T6LCzY4MGcGsUxP5hj1Fe+xX ahjBW9bdZskEJ9SjYTDi1mAWKJIum3p9wRiYDuXm6Gp9xWC0t2X8qsyrqY6KStGKI2Oq cnqXC3gHem04ULvtKFyj1HHQZMbbGiL2Ok+j3E0nJoZTe2B5iydo3MtaFdd4b8hqK6lf nZtOSRrWOe8FUl2u/4jKuPg2+aA2TjlukLTRjLlKaTLJkHTA0G+nsnOUIsffmm9sKT7H r4Sw== 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 b63si1448625pfj.30.2018.04.11.14.23.53; Wed, 11 Apr 2018 14:24:30 -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 S1754446AbeDKSjg (ORCPT + 99 others); Wed, 11 Apr 2018 14:39:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56110 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754424AbeDKSje (ORCPT ); Wed, 11 Apr 2018 14:39:34 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 53A50D0A; Wed, 11 Apr 2018 18:39:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maurizio Lombardi , Chad Dupuis , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 3.18 042/121] scsi: bnx2fc: fix race condition in bnx2fc_get_host_stats() Date: Wed, 11 Apr 2018 20:35:45 +0200 Message-Id: <20180411183458.981855529@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183456.195010921@linuxfoundation.org> References: <20180411183456.195010921@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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maurizio Lombardi [ Upstream commit c2dd893a3b0772d1c680e109b9d5715d7f73022b ] If multiple tasks attempt to read the stats, it may happen that the start_req_done completion is re-initialized while still being used by another task, causing a list corruption. This patch fixes the bug by adding a mutex to serialize the calls to bnx2fc_get_host_stats(). WARNING: at lib/list_debug.c:48 list_del+0x6e/0xa0() (Not tainted) Hardware name: PowerEdge R820 list_del corruption. prev->next should be ffff882035627d90, but was ffff884069541588 Pid: 40267, comm: perl Not tainted 2.6.32-642.3.1.el6.x86_64 #1 Call Trace: [] ? warn_slowpath_common+0x91/0xe0 [] ? warn_slowpath_fmt+0x46/0x60 [] ? list_del+0x6e/0xa0 [] ? wait_for_common+0x14d/0x180 [] ? default_wake_function+0x0/0x20 [] ? wait_for_completion_timeout+0x13/0x20 [] ? bnx2fc_get_host_stats+0xa1/0x280 [bnx2fc] [] ? fc_stat_show+0x90/0xc0 [scsi_transport_fc] [] ? show_fcstat_tx_frames+0x16/0x20 [scsi_transport_fc] [] ? dev_attr_show+0x27/0x50 [] ? __get_free_pages+0xe/0x50 [] ? sysfs_read_file+0x111/0x200 [] ? vfs_read+0xb5/0x1a0 [] ? fget_light_pos+0x16/0x50 [] ? sys_read+0x51/0xb0 [] ? __audit_syscall_exit+0x25e/0x290 [] ? system_call_fastpath+0x16/0x1b Signed-off-by: Maurizio Lombardi Acked-by: Chad Dupuis Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/bnx2fc/bnx2fc.h | 1 + drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) --- a/drivers/scsi/bnx2fc/bnx2fc.h +++ b/drivers/scsi/bnx2fc/bnx2fc.h @@ -191,6 +191,7 @@ struct bnx2fc_hba { struct bnx2fc_cmd_mgr *cmd_mgr; spinlock_t hba_lock; struct mutex hba_mutex; + struct mutex hba_stats_mutex; unsigned long adapter_state; #define ADAPTER_STATE_UP 0 #define ADAPTER_STATE_GOING_DOWN 1 --- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c +++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c @@ -641,15 +641,17 @@ static struct fc_host_statistics *bnx2fc if (!fw_stats) return NULL; + mutex_lock(&hba->hba_stats_mutex); + bnx2fc_stats = fc_get_host_stats(shost); init_completion(&hba->stat_req_done); if (bnx2fc_send_stat_req(hba)) - return bnx2fc_stats; + goto unlock_stats_mutex; rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ)); if (!rc) { BNX2FC_HBA_DBG(lport, "FW stat req timed out\n"); - return bnx2fc_stats; + goto unlock_stats_mutex; } BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt); bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt; @@ -671,6 +673,9 @@ static struct fc_host_statistics *bnx2fc memcpy(&hba->prev_stats, hba->stats_buffer, sizeof(struct fcoe_statistics_params)); + +unlock_stats_mutex: + mutex_unlock(&hba->hba_stats_mutex); return bnx2fc_stats; } @@ -1303,6 +1308,7 @@ static struct bnx2fc_hba *bnx2fc_hba_cre } spin_lock_init(&hba->hba_lock); mutex_init(&hba->hba_mutex); + mutex_init(&hba->hba_stats_mutex); hba->cnic = cnic;