Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2241057rdg; Sun, 15 Oct 2023 19:04:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaJrf8+ZM1XowzCoSoRcWEiUDhawf/i/iYHQ3Y4ZZ+LX7wcML6rxXzSJZEDQc/UBDHsKWF X-Received: by 2002:a17:902:ea82:b0:1c9:c733:67c1 with SMTP id x2-20020a170902ea8200b001c9c73367c1mr12443870plb.14.1697421882258; Sun, 15 Oct 2023 19:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697421882; cv=none; d=google.com; s=arc-20160816; b=LnzP24mMGIQm5uAnv8CL5fw9M+9mVqrrySXRCmM5PF0qdb0nFSYlkv+kt4C0/UfmHE 2OpyymD3PQ7CSXa7fDn/kMoEXZu09Sovi+AFKuIRYl9gI1TVoNbgnCqv5zFqu2DauTK1 WrSeuC63Mts5GJgmeQKqp7DNIn0X81Ka3jfCZE6cchB9NFfs0BBimG45x8Orbv8rurc8 U7YF8D238hMgGCg5Hldnz/ykuZORjvY3k6PV64Vc4qwYR9rJhdrCSfwhz3veBK7hYJva T44sWxrPCXc0b1bgoljJyeDODDdWq72adZuqxdMldhr5fQFM1chR9iLYKXN8tXOzldDw F5pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=G8udQ0pF8FR5Qf8H1klqpSe+/RrH35jrGc6Tl54PFmM=; fh=ZDcIlyYggP5K3GvQBQF3K/GzUnCJV+bQb/1GDPxM7E4=; b=TEBgsBa8rJEwf7ZwKAzbNv5tYfyW0STgSzP2blUjCsYeRJedHno6y3lKhub1csSOap v6Emrq2VkT0BRwp+lIGbVbrcC+BPQJYoIrZDjybAuA/oK9zwRKGTp6FHOkp+G7Yr0TFI cyWldqQ3DSf4s6hu7ptPi3KGX0nPIcf8YTYzL7o3Jiu5MItxcISUh+qn4rGkrPm42Lyc dvkhZYbivCeaXeWghrEz/4Mlb7oE2Xqt7Gcp3O9Kxhv+iZVsDagZsS3tUMiS5dLjsIPm EoQaFHW2Pd2tB0LwBk/V9NzLUQUXAC96548O+batZ5l07Exy2PAe9lfvMBmbC0KPK5xl tAXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id n15-20020a170903110f00b001ca336f48bdsi4416020plh.556.2023.10.15.19.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 19:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id DDA8C8060CB7; Sun, 15 Oct 2023 19:04:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbjJPCDx (ORCPT + 99 others); Sun, 15 Oct 2023 22:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbjJPCDn (ORCPT ); Sun, 15 Oct 2023 22:03:43 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64770C1; Sun, 15 Oct 2023 19:03:42 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S80fc1qVPzNnxT; Mon, 16 Oct 2023 09:59:36 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 16 Oct 2023 10:03:34 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: , , Wenchao Hao Subject: [PATCH v3 3/4] scsi: scsi_error: Fix device reset is not triggered Date: Mon, 16 Oct 2023 10:03:13 +0800 Message-ID: <20231016020314.1269636-4-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231016020314.1269636-1-haowenchao2@huawei.com> References: <20231016020314.1269636-1-haowenchao2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 15 Oct 2023 19:04:40 -0700 (PDT) shost_for_each_device() would skip devices which is in progress of removing, so scsi_try_bus_device_reset() for these devices would be skipped in scsi_eh_bus_device_reset() with following order: T1: T2:scsi_error_handle __scsi_remove_device scsi_device_set_state(sdev, SDEV_DEL) // would skip device with SDEV_DEL state shost_for_each_device() scsi_try_bus_device_reset flush all commands ... releasing and free scsi_device Some drivers like smartpqi only implement eh_device_reset_handler, if device reset is skipped, the commands which had been sent to firmware or devices hardware are not cleared. The error handle would flush all these commands in scsi_unjam_host(). When the commands are finished by hardware, use after free issue is triggered. Fix this issue by using shost_for_each_device_include_deleted() to iterate devices in scsi_eh_bus_device_reset(). Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 2550f8cd182a..57e3cc556549 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1568,7 +1568,7 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, struct scsi_device *sdev; enum scsi_disposition rtn; - shost_for_each_device(sdev, shost) { + shost_for_each_device_include_deleted(sdev, shost) { if (scsi_host_eh_past_deadline(shost)) { SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, -- 2.32.0