Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5126644imm; Wed, 12 Sep 2018 01:18:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbJAG6Fo/AehS0CXR9EzikycXhSaScdeX6EJj9hNHarOgrZZNY0iH2m2LAi9aIaEYTXsxNJ X-Received: by 2002:a17:902:8b8b:: with SMTP id ay11-v6mr831734plb.1.1536740289939; Wed, 12 Sep 2018 01:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536740289; cv=none; d=google.com; s=arc-20160816; b=LuhuyuZA9WTrGRZ7r06OCcSDIVAidqx8Fb4nnpc5wmoyFj1gJ6vNrZPvkEn8InKMUc i45dwKX/p3IXZudEoiB2tdlZi//cbVTno/8ulwVkjDHXxtwbsdtgKazJ0njZj+E+BZvX hZC1PBlZ5ecs2dkqjcP+r++7zXxTvcFv/aBQOQ8lASJPU8rzuSMpcbPoNwtr+rdmgGV/ 4MSp2icog7dQiaVCQxlynJpxR9MrowEq0CSZbW1Q9GTAH/3t3z9OjzjblzuPnl3w3XER rytHwoGNWSoeQPvBN2tlx1RTKkogHyEywKaP2dPEB6TYck4PLZ3od40FlYW79MHESYKG pDRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=pymxR+sgudK6y0ExqtAMXWKNKJi2T16aH08XLsgT7lk=; b=k6dUTRaC6MdF9kD+8S/ZfCv7kjYF6CUKYSJOSz/HR4Zvq+61LYaw6aHWyoW/7COVHF hY7locAmktKurd4ECx6Hxc8H6ualrvWoRntMe+dJWbYWbJ2oHZyxsLGNB+yBGY1+SHb8 HWQPkS8g9SGWmJwUwynTcueutUoinbPcXi4M4x1N6u04jgnZj8uqAjt5iEe08JvHzYM4 EGl0H9MGYS5QhsQ+CVtUSLmvB3cAWtOywhfxSF1Ocy83lcSQI/FzLFO9nRWXU6t4MqqC pZ8jK851cLFVRjbUIfenaoqZGqPkSuj7hqSwP74LBU+lA82GyDbRtQOLWhEWCe5GnH0s j7ow== 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 62-v6si304729ply.520.2018.09.12.01.17.55; Wed, 12 Sep 2018 01:18:09 -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 S1727966AbeILNVE (ORCPT + 99 others); Wed, 12 Sep 2018 09:21:04 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:11691 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726471AbeILNVD (ORCPT ); Wed, 12 Sep 2018 09:21:03 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1D756B5CD530B; Wed, 12 Sep 2018 16:17:33 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.399.0; Wed, 12 Sep 2018 16:17:26 +0800 From: Jason Yan To: , CC: , , , , , , , , , , , Jason Yan , Ewan Milne , Tomas Henzl Subject: [PATCH 5/5] scsi: libsas: fix a race condition when smp task timeout Date: Wed, 12 Sep 2018 16:29:46 +0800 Message-ID: <20180912082946.34814-6-yanaijie@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180912082946.34814-1-yanaijie@huawei.com> References: <20180912082946.34814-1-yanaijie@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the lldd is processing the complete sas task in interrupt and set the task stat as SAS_TASK_STATE_DONE, the smp timeout timer is able to be triggered at the same time. And smp_task_timedout() will complete the task wheter the SAS_TASK_STATE_DONE is set or not. Then the sas task may freed before lldd end the interrupt process. Thus a use-after-free will happen. Fix this by calling the complete() only when SAS_TASK_STATE_DONE is not set. And remove the check of the return value of the del_timer(). Reported-by: chenxiang Signed-off-by: Jason Yan CC: John Garry CC: Johannes Thumshirn CC: Ewan Milne CC: Christoph Hellwig CC: Tomas Henzl CC: Dan Williams CC: Hannes Reinecke --- drivers/scsi/libsas/sas_expander.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index 52222940d398..0d1f72752ca2 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -48,17 +48,16 @@ static void smp_task_timedout(struct timer_list *t) unsigned long flags; spin_lock_irqsave(&task->task_state_lock, flags); - if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) + if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { task->task_state_flags |= SAS_TASK_STATE_ABORTED; + complete(&task->slow_task->completion); + } spin_unlock_irqrestore(&task->task_state_lock, flags); - - complete(&task->slow_task->completion); } static void smp_task_done(struct sas_task *task) { - if (!del_timer(&task->slow_task->timer)) - return; + del_timer(&task->slow_task->timer); complete(&task->slow_task->completion); } -- 2.14.4