Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp178743lqr; Wed, 5 Jun 2024 02:43:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyU2Hb9uXkoD3l+sSyG78hi2R9i/t7SYCVFHrPfpH/EnZ2gc+t4xvT+8PFaeycFjogGRuCQcptAVBBEk42fJfS52jzfsPhAfpaOEMDGg== X-Google-Smtp-Source: AGHT+IH4GQaH2YeOlQFlnhGHk8l1cyUQLau5JGboP51defKbVkZOScvIS0u2odaVYH47pp8+xxs8 X-Received: by 2002:a05:6a00:4b4c:b0:702:7b3b:f5da with SMTP id d2e1a72fcca58-703e4bfdc39mr3163625b3a.10.1717580588557; Wed, 05 Jun 2024 02:43:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717580588; cv=pass; d=google.com; s=arc-20160816; b=nxJir3gabgM7r4Cl0//R/LqwfKbflGznKMaXWb7rCXKhaqNR14kVCenwbmMVJYO+GV gJll6K14JlZRzZpgw6PeByuAD+K0YVoAJcmiCoSMW2VakUQMPgzwtjYSffgqPptvfgf8 JnfQtp0AJrzswoaKmsZMTuquUFTcKyAa6n3s9hJQxQ9hHls5OnNB8LNhiS9axr3cQEJ8 okrd4wLBF2Hm8xbJs2rfbgG7aaQMWopHKMH/1ofDf9pFjEoW3Y6WSdks9iCdbX61sgig wepsZapVOvHwpoHBHwd59A9jXb+xohTrFeL+tqZruRDRfbvvVRZDS/FvkDKuCW0/FO6h qnEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rb8TvlwBPqPDumdC3j6Umh6H2xQnXI3Qx2U5XQXVFps=; fh=6ZS93kiJDnSrN3cDPUv0FciQSbJDzMochqrFiWUAupw=; b=YtUlE/RPOFWVJHkUeKmx75DEC3MOK99XUBlwBDsj4Ml20shnk5jEE1eOgiMhlS24T4 uePXR5wWZYG0Qf+7xEY1V2s4CgPkLqY16zt5qhGeosXZ5Ey46Jdd82S3DPw2mOCR0Iaq Yj+CF7RxnWslsKrJcePdARMX0xLJ96FeJkXWl51MUef+32xn/EdOgh7gXS7tFWoJ+PTT T+gDO08gi0tXwZSMEm4TObaPQVdSxaPU7Jvw4BkO788LjJL3nrBARzGxdhAzTWM7/in4 r1QZErN6OEBFkWBeD7X89cK5hB6DMA1g8rBOqkX2H6ZlAmLI2y2EUJlovtlk4kxjXGw2 VJEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PxFlksZA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-202074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70242e64198si2169170b3a.391.2024.06.05.02.43.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:43:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PxFlksZA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-202074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D3F50B26F6F for ; Wed, 5 Jun 2024 09:19:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 034821946A9; Wed, 5 Jun 2024 09:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PxFlksZA" Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A01190051; Wed, 5 Jun 2024 09:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579075; cv=none; b=YfdOqzD594/nVRFkHC123QvNRIH1lqTAt37z8bhkfGVgWes+gism5ZGK1kEVe1l46mvUxd7xGazo3eNhdJmBqyUKDBwSNmGLv8iYVnJYo8W+2YpdhrDXMZCudlvLIYehjhUHVGGRT2p42LjmWzrA9b1V2b6A+HTfwf5H3tu4SsI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579075; c=relaxed/simple; bh=QU/idcVM4otdxk+iVm4L+rSCGwk9/9AmyQ9pVxLqVA0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UANh9IfGa6KYUHQGToucSY+5bjbYVxD4uvD2nHwXYeNPw3iIt9QuU+/oK8nP/mSZ+iQTJokWLxxMGgTTeP4IFc0m/2vhi74F2h9LMa6JopRiOVwevQCfvVfe0XAoGNabVm3to4c7yTZ4MD0Czwiq66hMVU5wrllPnkshvJ+yPQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PxFlksZA; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70260814b2dso617886b3a.1; Wed, 05 Jun 2024 02:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717579073; x=1718183873; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rb8TvlwBPqPDumdC3j6Umh6H2xQnXI3Qx2U5XQXVFps=; b=PxFlksZAOAHwhmd/a9xBq/n1VJ8pJErcMpBABopOKk/iXCmPCgUYjOAjV1lFNGHRlL KUe9PoCi9WNTAhf7Gn0uhnuId3HAKSbZ4P3O4L6Jt4u2PjDr0sPvugzFgpo/Ch/dXzLg B+sx5rgebWR/djdfs3lDTswUmQqMVdtM6JUxMmba9UnFckhY7WhGTEt/IIyRh4Ku+uQn 8curO5h3gXTWq1B1y0Abz1HdMQa4OXRBkvRKEdq9pnB1AMuCKZIrOqdK2XcCvgj31Qog 6r3Q2KXKF0YBbYUsbJeaGhHwHNiiuBH+tPeiOACRWL/C4uw/IbaX7axMoNX/tNB2K3mT Teug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717579073; x=1718183873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rb8TvlwBPqPDumdC3j6Umh6H2xQnXI3Qx2U5XQXVFps=; b=vDBgFt6e1bzv27lILafHibE5UV7jtKJDb+tqX6OVBAMfpWG6SJRMYfkQUh/3GkFVbo 92nCmUgqWYk6ocK3TprEIIAhTYk2a+ImpIcCLdzLpAJdkD1Ij9EcaGY3oN6P/3hya6Dj y+VQOQZme5IpPlwURrM/EUOnqsNLTCQrqmv2l+M0XPchYP7tUj6MAoGg2ahpu0hLfFLC B2zYVPJkhvgR/e8Sk6IbzKVaOUDTuSvycZZoxKQjkm2m0b6oi8aCg/+4/hwKByK3N/ro o6cdi5Oj0xg6jzQN22QcDW6qJIJ3rF7dk1/dK7JSeX9yF5pPlfdjTV8GauSjqplIyeMl jzaQ== X-Forwarded-Encrypted: i=1; AJvYcCWOpHR+V7s36I+Pk1PRbRm2dFbb88xpQlvBWjYt0CwzmbMRStEnwj8JMVDW30BAph2exwHvaz/DrClTAAjY0rBuPAU7XTuyqbSXC6lcKr58QCXecMNZoCq9/jc4KokgtxLPKOVIhNaomw== X-Gm-Message-State: AOJu0Yxu0+4BIzDo5LNwSKK942EAI7VNGIpLBTNne+smRmX0FQ0cBl6J jbju3jNfiq7P2qNdIwlNekTtaG5Dl8bHfGeV2XSzdG6iBe0PImcM X-Received: by 2002:a05:6a21:18e:b0:1b2:b183:69f6 with SMTP id adf61e73a8af0-1b2b6fd4d89mr3503703637.16.1717579073106; Wed, 05 Jun 2024 02:17:53 -0700 (PDT) Received: from localhost (97.64.23.41.16clouds.com. [97.64.23.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702423da888sm8265740b3a.60.2024.06.05.02.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:17:52 -0700 (PDT) From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wenchao Hao Subject: [PATCH v5 3/3] scsi: scsi_error: Fix device reset is not triggered Date: Wed, 5 Jun 2024 17:17:31 +0800 Message-Id: <20240605091731.3111195-4-haowenchao22@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240605091731.3111195-1-haowenchao22@gmail.com> References: <20240605091731.3111195-1-haowenchao22@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") 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 a61fd8af3b1f..ab4a58f92838 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1571,7 +1571,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.38.1