From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452396; b=0IxYQtHhAR4rEUEN6Jw5gD32jf4yIBxjgoA11g+FnWiELCtJNUbT5ycxkcOYTQVnepam 3klHJ+m6ijkVGLiXS6P0SyYHZJSp0ldL2zVGHBy6lN4P8p2TyL8vCi1j6Fikc7WKFTztk m32fse++39t34USEo5xG6uGJXDglvIunZnSlI49XJXK7U4HEVY2XlNOcZ85tss54UH3tZ loCXKhHucJidEDAPG9oSt5CDiMuelCixNlwwyB8bqQCNGt/aCwyualgssW2aIMaF0Foay d4dP+4kluQbWmiyoSrB/8Ui1O/woaBE+ILBm3/P07hfjK/UStKlZpOKqCJgy5hUxNKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452396; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=C3d7VGjNOTr2nuTn1RfXi0uNL5+C84Q2UgdUCdy58ec=; b=q8YqdmTRs52A+/ntfs0/JCPoyLBIfOy1MrdQK2TVAejkYJCEdSEC9PXA4+tzKIIuo9qk Ao0RQEQULNIm92gAsGPFy/HqJ1LhMOdv4U88Ftf+ZL0sB89xIL9nbzE4LWk+QZOONx8uf LtYv96es7CV5NsA6QFzFwSOZ7aSVunEWzih8qaj0ggM63xCqUqdUtYGVuM++EKDY3UwOn 7c9JJy4fezQa4QK3eI4YqZxHBs0mFIYVLEg6n8BKxQck8cl0Zv8gdoyiO6FHphzMCgbmt GQYpWAoc76gw4NJFRdftieJHCarZUC4D/KycFG5UmwWnSONq0eBknUjAXsk1btmZhfg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=twGXZVjl; arc=none smtp.remote-ip=74.125.82.176 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49338606A69D for ; Sat, 5 Dec 2026 06:33:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 49338606A69D 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=twGXZVjl Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-38747f42472so2768644eec.0 for ; Fri, 04 Dec 2026 22:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452395; x=1797057195; 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:content-type; bh=C3d7VGjNOTr2nuTn1RfXi0uNL5+C84Q2UgdUCdy58ec=; b=twGXZVjlcmvJZHHxBdoWl8f9PheB1lGUx7CJTt47tB4AntqwDAOqkL3Ibc+5fWmPJy LiCUC0EU3OtX+IUAuwDBkdKQXAQOmfCFc7wXpL0K0o0GWfnJ6+ChFaeDaw/hwaSklowi GnMHH+FZEOpI0lkw9SaaRTLSwLvHLmVjAND32rR7EjbTM4qz6w2Y9vMenL1bHHf9Yyqw mvbfaeZ6cDpBI0B/N5c0mTkrWQN8zzM86kfR8qmxuo/PPTe3qq/Zru1Zg7nphi8HlbMl W9JNKIzuEjJA5UXGrAIfhg3mOojCBKYxNrgcl27QEwTZanZu/Lpkoe/qsSuQFYyyGd8J R8bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452395; x=1797057195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=C3d7VGjNOTr2nuTn1RfXi0uNL5+C84Q2UgdUCdy58ec=; b=wPTLZVIXukQpWEwTjMdLueWLGBsZKsjSuHMOioa7kfb3GlSGT2MGgm/jZKqWUszb50 2rQBhsDCDIRPSjzh4i8KA9iOfR0qc3TsxQusRYjV3dRVX2w/jamk9b4/uuYbAsyo01ph 6oOe3+g/Q1z/8OgttP633vys55/4lqjUOn5K7wW7p7jRIHxycbD5Qoyl7XcB4aOZJabS CROkpW9zbu05clo29147G9q7Zq7brYrIR//NSN8LVeGmq68jJ51BKycBGeJWN7BGZV0V DKzAgwb6TUj7u1nIXOK8GCxwKhJCUX6O4j6MI8I+kFojpmn3RwkU5VQdSeqU9k4onB8/ BldA== X-Forwarded-Encrypted: i=1; AL+hErG1hkgPrCMsuHpWOfsofQLbyW+L76XW9hW9XQFRX9uO8eqqsIEWhw25aG/MmQYyenVTuv70KcUqPADkZNQ=@vger.kernel.org X-Gm-Message-State: AB4q+uFjMjmcCwv08U8YIL3h6agFzuGU9BW5/84+chpm2GRbPVHmquLM H/Nr0EieqedHKKk/mwvTThhLqT1MdKXtd+nHbQ1qKSgIeZKN+Vd7iQCM X-Gm-Gg: AZFdTZe+tNZ6M/3BLJocWY5QHLb8ADZOE9tILERyUAiwynfET2gaSxWiz0N8ysZuUG6 AYxQv3fAMrEQTOmhrpwfPAJFeHXogseaoJQJm0ZAWDiD6FyfukKkMp/LX72F6d/ir+K5rIgIo42 mUiKF40NkBYoewfJV3tmGsVDpvY/RaUNfcuu6KY2FWPrO0V1uRB8h0AX5EmoTmA4YG6sl6nEkzJ yBujwPmBIDcXRt/d8i+YxyevIhgRGUkTiy1t62ufK2aOviI3wBZJ7rHabDdgZ8jyMKd0FWG60sc NqTKg6Sldv9cwDktwyS2scr5hf0xtK4k3S8TuLrW82PuTRKdldVf6NoYohj1s55JSDI/YxmQ2DL dYkkBQ8nNvbab3pwgaBs/OCohO8AdrCp/4m+Aw2CXASWD3Xk5wMPdNBTCEWClyqcGgdaeNolhz2 McmV2g5UdaOBrl4iVYwfbDtPd3q4O2jBbCKPL3yuvLyfEe+ShHO7Dy5AtoDQkWSPGv0OGaGd5Ux QlgnpJSKzNQVGt4G2J/eWa2C+b4hjy+95NSItfg80KVIKxGe5ZetTpoiKeyRAXmCp5pGJQRqppC n3JKFeOCFkzU048FHQ+b3IOn5/BUQ/egLeHEorf3L6S+lrdPgN+kNU7ILUd6f/aX5sbuMJsV8su 1mpvSX6Bi9j7K X-Received: by 2002:a05:7301:4892:b0:386:a8de:2bfc with SMTP id 5a478bee46e88-38752139e71mr3676666eec.6.1796452395467; Fri, 04 Dec 2026 22:33:15 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bb842sm14612341eec.15.2026.12.04.22.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:33:15 -0800 (PST) From: Praneeth Balasubramanian To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Praneeth Balasubramanian , stable@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset() Date: Fri, 4 Dec 2026 22:32:23 -0800 Message-Id: <20261205063229.2518424-4-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20261205063229.2518424-1-praneethb2002@gmail.com> References: <20261205063229.2518424-1-praneethb2002@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit scsi_report_bus_reset() iterates the host device list with __shost_for_each_device(). That form of the iterator requires the caller to hold host_lock. pmcraid calls it from two places without the lock. pmcraid_handle_error_log() runs in the tasklet completion path. pmcraid_error_handler() also runs from the tasklet and holds no lock. Without the lock a concurrent path that removes a device, such as a configuration change handled by the worker, can free an scsi_device while the unlocked iteration is on it. That is a use-after-free read. Add spin_lock_irqsave()/spin_unlock_irqrestore() around scsi_report_bus_reset() in both pmcraid_handle_error_log() and pmcraid_error_handler(). The other callers of scsi_report_bus_reset() in this driver already hold host_lock and are unchanged. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Fixes: 89a368104150 ("[SCSI] pmcraid: PMC-Sierra MaxRAID driver to support 6Gb/s SAS RAID controller") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64 allmodconfig), clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no reproducer. I do not have this hardware. This is against linux-next, where Scsi_Host embeds host_lock. Mainline still has a pointer there. drivers/scsi/pmcraid.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c index 34f10dfc2bd0..85c06103c88d 100644 --- a/drivers/scsi/pmcraid.c +++ b/drivers/scsi/pmcraid.c @@ -1696,6 +1696,7 @@ static void pmcraid_ioasc_logger(u32 ioasc, struct pmcraid_cmd *cmd) static void pmcraid_handle_error_log(struct pmcraid_instance *pinstance) { struct pmcraid_hcam_ldn *hcam_ldn; + unsigned long lock_flags; u32 ioasc; hcam_ldn = (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam; @@ -1724,9 +1725,13 @@ static void pmcraid_handle_error_log(struct pmcraid_instance *pinstance) ioasc == PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER) { dev_info(&pinstance->pdev->dev, "UnitAttention due to IOA Bus Reset\n"); + spin_lock_irqsave(&pinstance->host->host_lock, + lock_flags); scsi_report_bus_reset( pinstance->host, RES_BUS(hcam_ldn->error_log.fd_ra)); + spin_unlock_irqrestore(&pinstance->host->host_lock, + lock_flags); } return; @@ -2586,6 +2591,7 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd) u32 ioasc = le32_to_cpu(ioasa->ioasc); u32 masked_ioasc = ioasc & PMCRAID_IOASC_SENSE_MASK; bool sense_copied = false; + unsigned long lock_flags; if (!res) { pmcraid_info("resource pointer is NULL\n"); @@ -2628,9 +2634,14 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd) case PMCRAID_IOASC_UA_BUS_WAS_RESET: case PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER: - if (!res->reset_progress) + if (!res->reset_progress) { + spin_lock_irqsave(&pinstance->host->host_lock, + lock_flags); scsi_report_bus_reset(pinstance->host, scsi_cmd->device->channel); + spin_unlock_irqrestore(&pinstance->host->host_lock, + lock_flags); + } scsi_cmd->result |= (DID_ERROR << 16); break; -- 2.25.1