From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452396; b=vxxp5EY8RIUBlPA9ELzbkuppFGeNQhrovuL3thnCRWYcW5M7aEGk1PNKlTJbZfaU1iLD AwGYbYXApP6hxkk+8WzQoA4Gea+35JCWQIey2GB3DisMN0XbL7poFCDKiusCQJ3O/dcTp AlYlfJsGAKxCgrqh7ul/ZJjH3yuVxBU2M6oGKf6SesPl/fge5QA3gkQDMfyLG5gzTE+B0 lMmh9DN1ay/2iLuV5hmeFxCqlnmm/A+AYxgFsGa2ERgFPD7GRajYcvzm/Shbze3TiXfEi 4kCtVfI8OoFGhgMmvTwBWmvjkpUdqsDhmwnCeb0tRv5CmycsqCiH1wxe2lcXdNp8bWQ== 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=CNHauu58oV0w4KlOFynqAR7vdUg/YMwaaxidgAi6qve33aL2P/8M5fy6k0sCQCX+THYe kxzIgJQ8XBWtCbU4G7JCxZ33t+rhwb22B2ry8cllkxkiN/Gog5H2rlLZD56uCHH7BZT4w X4Z6mY6qK6L9KG//EG+qAMcfs3J577IpnJHrjrW1tpK3TEmNeFJaDIQhQK/mBQMdhj5nm MkjHCYY2au+6Y9CpuopQmMcKR68AbvCGEpm9+yaZxg8kyAAvKCqZkMphNyHjVRRqP3DiX m/0wtwKg8uspHY/wNtxtsIOxsGuJUIUYmFCAssGGtzZrsDHAP8kX8rWQ9L7swGy4bFw== 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.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 71208606A6A2 for ; Sat, 5 Dec 2026 06:33:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 71208606A6A2 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-f173.google.com with SMTP id 5a478bee46e88-385d8a00598so2345406eec.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=D6vAxaGxzDLBy5tZumnP9z9foxPdneOXnDDADFQj+nvX1OnlDlpMdIHGDp1pV8n/Tl QMhZHMhPbgtxDHAWc21xsDQQtnF8WJ37RdClDpGKDnZAwTMjYSqV/HBdfMhKZUEBWbAF jijzXiF4qI+9XgWeE4RZYTq9QVioulmDmVlRI9yGqfr9OPNvHoSgq7mhXbiLsHu4Hhwu 5Osu00ExBEDmjBjCPS5uDfHRsw266CGy9n0/JIP/PZbtIyORZ4Qi1N9Wpx0xGuZKj/Is YNJjYOhBNbOlnc/MzX/bgB9RjcwULOlN924xJXglIUUkkUiOx30osdL9P5zY4ttOiZ9O FeGQ== X-Forwarded-Encrypted: i=1; AL+hErHUDAE11LeZCRFNoV7I1rN+ckXcYYSD6Zx24QeVk/urplqLGbQTXbPgggnlaOroLB/JWzUUOd6rol9Y@vger.kernel.org X-Gm-Message-State: AB4q+uEO4ppf2sJY7126svBFwUWZ8rxJXN9wpL8x5SWM3D0QtAAGxr0L D6HUCq70+XxQL2ENZZSzvKJkVZV/jOaz9VmsrwmNsMo9qbv27daS5MiS X-Gm-Gg: AZFdTZe8FwFzT4VUg+6F/fHpVmyWO8EL+f0ElbtrYp2CyWjCfkxk3IIwUFZRxvM/bhJ UbIufAYFdjx2tlEGO8ng+bKaVR2WklhHwn+Yy10BMyxu/1Gfoq3JSILzLANogOiixMQfwI6hCj2 h2f61jEr58sf2MOiYhxHhxOld3v85gkbdhaNplj0vay2k0s3mLq3o8RInrZPmiU+SpRv35I62ac L2CL4XQE1LLwBMCOHwFf5N6kf++I10MYPoRHqhUSWbLwinJahKjO1gyp9mXZVJ7OpYqyuOUDu8y mDYPpvl+I1Wc1QrWILWnffmIrZjIrdqNKZySOXCcTwYd7p0sE3W+AyC4OsFQUfzbAHHNVIlMqIf 1fQB/tKTO1dLOk0PAjnhvLqFTASFY/gu3Hsa3K/NswT1Vl/XiyIqigNOy8lJ1B2dfzJM23pWhvK E4PgwRTcy1XMPGTTDtJBqJX0IFfe0lHzc2Gs7irPJxYgvDqZre1l0octpbzbSORq+qUGqnpPd4B uFidV4L556c4mchXM8astt9iCIKKxltewnS11KDYnllvZrVuDfNMlV/vlNVGGw5jQPG4yG5km2m 2Yzsg+DVO7JjwZwQw1AWs6XmxyPN5okiwnHsqGxsKV3YRSgUJN+bWY1PRpsTXa3Ve5ci7p81y4s rL8NmCG/0ya04 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-scsi@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