From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452401; b=FoVj+luHzose3z+il7pZwopy3Odu5Tk/k1Npya1uMFQn8HSzSwqq007Y0HFASKmMhmbQ YuMubDJoS7euqNPad5rpa0ZLfXX2PQukhaFznvroACu0E/IZXt8mJeh+a8PkwJ3da1oIn nisL95OjcQpxKGjWiGxaO55T3gunLxzijUf6u5Kh4Sm2ZYXQ3eATIUwHA7cFfEJxi6Cu/ 4yxU1lZRKCOyEZtD88aHu1o2jtLbSCQV6+02uvq3D2RR+2+UFo+9aFG4uSRwVc/pp8ixt 8gTuAA81huLdpOpFyYpm1bK3ue7iYVDcOf8xh48ZgRc/qmETiMVLewd6Fu7zkFeeE6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452401; 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=CK0jKg9IJ5dAAXqDkdTf9AHdqPxpMKCdzHO9W13pO4s=; b=wSqys2qiJz2JUTqWT8+A1bq/hGTfcc0iviPMe2kMp9E1My5tLVLFTBSXOcGt+BB4N5t1 vfbhUcQsTJSSJF+sWVBrsSK32RbSQPDANoVVOGz4dCQ43vXF6h+1OfpDv8S8xfcqtz5lG 9WoB73f6osrq8RAUwxLpRkhondDrpXn96Api3XFlZpv2xurreGyjRQnl6uUV4HdMDytlQ bqaUQrHyPO4PVvV10rBhOuO8kM70swoMN+oQFtZc9kZE2kCD4mO06bHMd5bBgukHXRpAc KFAbZfKGoWzPcxDZtBv0+y64Iqlijiv1z5TAYPRPRsSmc46OqJRg2ixktr6r/oiZSmw== 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=svVAYAd7; arc=none smtp.remote-ip=74.125.82.171 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 81A8660A382E for ; Sat, 5 Dec 2026 06:33:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 81A8660A382E 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=svVAYAd7 Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso3775604eec.0 for ; Fri, 04 Dec 2026 22:33:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452401; x=1797057201; 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=CK0jKg9IJ5dAAXqDkdTf9AHdqPxpMKCdzHO9W13pO4s=; b=svVAYAd7vmc++W3Akmg6CI2vkD/gAouZjbO49QBkyi4YW/yTqzHBv1PQ3WHz/+p36A tbBEio7xP9Eatm/XgA378dZSvdDUhCuvDiRYH3pvHpA0tgyNe/tjkVvYD+wQRfXi+Uim KYoPmJ0pPOyIYyKHRj5ZbROvmBO0doUjTzLwslZNm3NS7gMdcqLP5maKYyVqJsu5FtMm YJiBWGr30L3dRUbDZAZQ1cjrtJzGmYBZSFKmXj3MxcC4XyQcnR0y/e4jRT6F8pmsUh8Z tUgDmmsPw5YLMniLmjnRrpDE5iJw+pR8cf/cxQybiY/T51O+fCMt2TQ00/Y4D/z21CxQ n6fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452401; x=1797057201; 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=CK0jKg9IJ5dAAXqDkdTf9AHdqPxpMKCdzHO9W13pO4s=; b=hZY6X0KkeDfX9IO33bRuR27sy5K7We3tiTxsfYEWDzMtqhzUsp7/+HWVKxnhDIJdG9 pBb6rj42Vzcx0uRV7cXhcOo/I2joQ5vIeYdq4b0x1MSIbZIiBTcV8q3R9BBxpQRukwsr YWk0R/003GjqY12XPDR1+Be2hLtli97FudE/PoVR69/M9Ih9j8Pf+u6CwofVuFk7sjVo tANeNpDSgR2aEkdCCCJUJTTmUDr6feO8zaVvVPDOc/nwR0mImCA5ZUgALZhyR1NPwAsF ka5+YilKL6VJ1VOnE+g+RSad4Ikhkqi3l6F/LOc+fsBj4wRfkQ5fGnDFWnC9d0vEAMGD Yk1w== X-Forwarded-Encrypted: i=1; AL+hErF7wwW7CumzQORj71VspFR3JZu4SBsZYWiY2okExHOoiA4k6nsUGfpsGnmKaqx2TdmmWbdLVRo=@vger.kernel.org X-Gm-Message-State: AB4q+uGFcOtJm86YwT+etb/EhDrEZgXzWbj5T6taM9aQJIe4d3qdZjyZ muola3D8HNmvV8Fj0uHZjOIz/naVDlqwQwfhE4PKhcGN29/zw2excu9v X-Gm-Gg: AZFdTZelctRxkqr9gPn8Ae0yNvICNjv7tX1jcm7QDhm1XW48TcU2et97GkxQs5oqfnm 9AG7NQ3BYBlgKq6RLidiTyCtP+ehc7dxFgMQl33lt6RdE+A4tJzhZXCS284wn1zrTKwhc9eHrCu OPCLAGiYWE+/5a2/gjoHd97d5QsayX1KMDNYd+AeioA9aPStDHv9SPho8olTQ+2Qo9V4O4Ya1Qj vr381CATPTj61XH37o1f5VtIbst3JmzrRl0NdhtmH+LO+orqBDlVGIY2I796qsGuded59xkEu8d LvPkRSqapJ5Qv93cWveImtj9WlPC0C+rI72HPRhrJjVuYUAt9Zz6rHsqabIKGMwzTa3h9vpEGbl r+GzcxQPLfb+8b4O1qDU+v2zVMZN8439sSwAKOzFkwzz1epOUJzDvUI05P0ixuXwSNUrJsoztgc KIeXwGJwFSuh7/M+Ksv2NJGJF8UNYbw/2J9jyVU5BO06urSmp67Lw/YqGeJZYOjwZh6uXlAc5S8 /58cwzbnArrZoR/MM9XYd4Xi0ie1ds7JhDWQuEp8Dc55rpFFQ1kgivskwF4MW6pjtw2ILNpZ/9+ gxrIBvG1rJkSK6OfjeerNqIU1fEfZ6ehtfRfRJCvBucXsPjBOMrAPz/37991/vl+D+g= X-Received: by 2002:a05:7300:d704:b0:385:c28b:a4d5 with SMTP id 5a478bee46e88-38752105afbmr6362828eec.17.1796452400643; Fri, 04 Dec 2026 22:33:20 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:33:20 -0800 (PST) From: Praneeth Balasubramanian To: "Martin K. Petersen" Cc: Praneeth Balasubramanian , stable@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE Date: Fri, 4 Dec 2026 22:32:29 -0800 Message-Id: <20261205063229.2518424-10-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 __core_scsi3_add_registration() increments dev->t10_pr.pr_generation with no lock held when it runs for a REGISTER AND MOVE. The old comment says dev_reservation_lock is already held in that case. That is not true. core_scsi3_emulate_pro_register_and_move() drops the lock before calling core_scsi3_alloc_registration() because the allocation can sleep. It only takes it back afterwards. The unlocked increment can race with core_scsi3_pr_generation(), which updates the same counter under dev_reservation_lock for a plain REGISTER. Both updates can read the same value and one increment is lost. READ KEYS then reports an incorrect PRgeneration. The effect is functional only and it takes a remote initiator to trigger it. Always take the generation from core_scsi3_pr_generation() and drop the register_move special case along with the stale comment. No caller of __core_scsi3_add_registration() holds dev_reservation_lock here. The register_move=0 path in the same function already calls core_scsi3_pr_generation() in this spot, so taking the lock cannot deadlock. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6") 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 and checked against the source 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 did not write a reproducer. drivers/target/target_core_pr.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 0f2ff9d42150..3283fa5ee298 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -1095,15 +1095,8 @@ static void __core_scsi3_add_registration( /* * Increment PRgeneration counter for struct se_device upon a successful * REGISTER, see spc4r17 section 6.3.2 READ_KEYS service action - * - * Also, when register_move = 1 for PROUT REGISTER_AND_MOVE service - * action, the struct se_device->dev_reservation_lock will already be held, - * so we do not call core_scsi3_pr_generation() which grabs the lock - * for the REGISTER. */ - pr_reg->pr_res_generation = (register_move) ? - dev->t10_pr.pr_generation++ : - core_scsi3_pr_generation(dev); + pr_reg->pr_res_generation = core_scsi3_pr_generation(dev); spin_lock(&pr_tmpl->registration_lock); list_add_tail(&pr_reg->pr_reg_list, &pr_tmpl->registration_list); -- 2.25.1