From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452396; b=puo1UTopIcjL8zeA2s3rsAXBRQeFD4eXppijCXg0Boi5tJ9wAXcZm6UcVkDwYoFNtTpg uEbgdMV3yPCbEdmE45ou+WpYvV3J2u2wMPdTdcIuZ5a4AVg8ZhtAwKxAepVDRLaEMgyvn uAkpO54JuXJNuxgXPDf7BZs8ACi9B5BavktFVBUur+Um3WFqcLD5pC+aYrfU+K91V9WjF gVs1Jxt5vpz0RDNxTXoA+mAOnFSw2mWnb2Jt7LenvQvSlbE4E0w+8yq8Y+j7ptXgqyWiM CZYEWC01Z+t9DatcuCi4gb7iGzRmItM8Esw1sOtTWWTtoOnrcUjsVx57GzCkRltLumA== 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=Om8qPn/w4i7D0Xb7Ov90Y/E8qFt/QlhraS6j1jCQaMYgYItOjwxN3HeL8lnkQvPkk4Kx zKE85HZjzoyUY4aDAuMnjUCJ2NcbCIYMsllA7kWfKYPWiODtzHgrJTZLbN8vLOGVC0E4y XLsX1ZntimxXadu3/lz7qNWSH4272kloT2siq5D9bz/uf/nl0Q7cl/ZT/wMfPfztwEhLC QHFxzGUfJm6jZgYhKOE8zGwPcLg2olLRyUUrVB3EfZk6FFZ0ZkqPjbtkQwPio7WPAYPog sN6vfe1wPrjw0m+7Xy89u+qlIijWeEhlfaHyY8YYqci0BdHZpLtFliJOi2Kh/VxWC0g== 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.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (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 58F2D606A69F for ; Sat, 5 Dec 2026 06:33:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 58F2D606A69F 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-f174.google.com with SMTP id 5a478bee46e88-385d8a00598so2345407eec.1 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=YRYF5RYASHJuY5V3esGmK8DrkhFT2AhGmK6t7Ot/K+gVbeCqT0ZaIWAcF68OXiwLLZ Z2v8zXxeTopRbE+Yn2uuPCHFFB2CiKZ334tEWBiG3FltXGt2E8apxR1qiXGD3r2gskVf RPA0ltldW9qA/Bnubuahu+YmOy4axNwOSbEBNE0CMWQmQmbXu3CdooHgg3ENTKcHxXh9 UBk9/38T6W69BaHce4Dui8RyFpyDW3odHiODNyR/fZNY3tf5dYYq/fkQntu58HiwMdzw kQfHr+OkqcsSeiIdjHQkK2b04o0/O7Tqg9I1CGRry6w+MgGhyCXYVFhnKAm7T/RHYTGM FobA== X-Forwarded-Encrypted: i=1; AL+hErG/XEdHTs6dlUnpBmGRA86FXYZI+V9vjTw3LflhIwM8+N8YRFgiFIj8BEed2QGGiEf2XlBbVUM=@vger.kernel.org X-Gm-Message-State: AB4q+uHMqG4wrcH14Ktf8YvBR6C/JZlPxVue1FjbskyyZYmyCTv20id5 FAczNDPDkh9AFr45MVPxhI6o5AX0/ykcC8sIHG+tIRd60fo47qTpsdVs X-Gm-Gg: AZFdTZdYNiVi68n7aF5vmG/rcdI3G80NaMA8Hvs2ojkqQNP0NHVqiWsk9wz/zfl9Ovl 0Fa2L4ulNFvdAuzDiE7d7ltsYH0wKBWQwUHS+OtfgbCGUV+sY5CVzFIM9WuWZj5j42TTLj6JfPY 1rvcJ6d8/kB08NM00GR3quyjUOIvdj1FFIsPXxzG9/z3x3/Yh7BQypfkYnNI5CAmm/quDV2/p4v OijqzXF6xE/vRnVG2eq3M2XnlPJApbvUFmCtzdZ3wiIRcPpTo7l1sgsltPF49JrFr4SyLSohx/0 ZMkCEC31jpcw8Xw6geLYVxWKx1KAoBYa/70/pGJV4kLVDqk8qbkvgl3P8MwDx6knDUEWitwxI9y rB0lnDzY+Jhu0lOssqvLx1q7hgzhmMoCTSVI19L92u9RRtyUs9I1esBkOInLcTUvaRlkLgRSom5 PuNkndcgU3ycRm8UUNZwBnAMe1QkdNdpLlL1imgGlDa51NMF5Jag96TwgqnQ1Tq2UCzpxN82pIb Ygg+Qb+sjPibvXi7p+0AWwd3RMXsws2gzX0oy/DH/du0pdtNqtQoaalFM5dXp414K9GzdViBrvC vylWHfCL9zP+IjP2Sc7Tm1SCU6LJ+BRTYxGABoSPegw/f0/GWY5JeCQTdL5soRyH1UYjNmqLASG lPfSdfKvcLPv+ 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: stable@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