From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452402; b=WRV8twjVtuIMz+BXNal3ytBwy75pQRovwne+PjcBIrD1RU/ZJzVk1Pv4l5+hZWOigqGM K0QxmZxgQER8lkp80S2kpXpBu5ltsyEWrUg1BKlyEL8BlH4B7XBfB9fllrM7dF4CuAZmb mwC+bin7EJShY06EFWG1yGQWR3AgdYZmmHPwrC6DI9w0oOn6A2sjkNJQ2p6FXjDVM+vsL ObEyLU84HwjkQDMBE6NbbrficB6tEyI8PPfRUnZnoYoba1CODzwbAae8waYirpmaVfa8O o8pD9eef+9eCj5rU/gD4FJ1auQRGnpKNW/bAQDKM21MrMZOL8wMJ9S3Ehy2YO5uGWBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452402; 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=q0U6Aa4He6tG4KZG/AllWcQegLgAwydBXGMYOWcu1ouaQ9eoGUwel4kdKKO+Y27VIQNU 8oP6aOMlpcwmLMB2xHfdfeZBVH2P78eEq+NToeajH2HtF8Qc0DPNMyUu0vYTroFGk+fJl 2N4Wu8b7mduFiP4X/WodXB/GmyXa4oWlooFs9591hezxtQ1Uwua+FV80SSZ4gC/c6BwDx VTeNeg3XN9LRvqgXjYUOVk25gP/J1nqGXJCgZB+fAqI0Ajs0DDcY3hEFZUM8KJvIk6s3C iNKeB5xjcNtdrXhDcDOoyaOdnBGIEPrRa4JJjOy5/CBFy8Xivs159FUmfijPD4nIjiQ== 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.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (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 7C0ED60A3819 for ; Sat, 5 Dec 2026 06:33:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7C0ED60A3819 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-dl1-f51.google.com with SMTP id a92af1059eb24-170135e43c7so3931125c88.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=jrY2honOCVIN5GGETYDurbEpZF+A0/58QhOAM5+alBrLFH4TsbnZ9RmmYcxr0wtg3s NkVSuRcLPQxpR5q8gXZOBLcYo34UQ8Bwfh7gIrN/E02qtGiXydXzd+JN1/WX4AVZwMdn VnvjpDG7wnSyVzDqzUiMmImhwrKLPAt/nnKR3J9H1lVK4qoOXNFaohVXfSsXRuRVpG/A D5JvIjQLWIu+S7vVQ+IRImW46bXa9QvBm7lux0Yv+egaJbTX2Tvml51v1zLcKfBbGlCJ TLyMJW0SpPYbY+UT3ydB7E8CA7AIXcsIarnIapyJ/BKWclVx4UDL9nqPkjvryAYPq2WF iv+g== X-Forwarded-Encrypted: i=1; AL+hErGBQ+P9rxTsJzxMI0NuOIZYYRrKOkVFaQSPZWIAl8oeLZMsaA04jSVkYrgSMyIgfVVJqy5abNxFuvXcFYg=@vger.kernel.org X-Gm-Message-State: AB4q+uGA8kN1Dj+bLNPDTRUNUMk/g/gH37ssswyp7jkkrrVpCy+uXkjB MpvOySiGXHYYRqzrlEZ3vvu+W44IodNdkZ/uy7Ph6H55ZdQ+d/97mbZO X-Gm-Gg: AZFdTZdXVapwyy8n6KGo7z82/RjMxfZK/m92d0ABYRoTWGalodrA1NFe5Wn2v8EL+Sj D2SZPbxt5B/wFaJezlHKW3F7Nb6vsICgiPQxZGB9rP55Bux4AvEmFQeHj60Sh5Z+D/qS2TDJitY uxEXeX8IxLtoTlchsWc0S0RPfElEqSKkR2Qs5vl4ZQcrjcWSLlsEF71LfiC0RN6AYw+yb99yLXK CEfRY0QqkgStLABekMn1icfcSsJmddbHMRdXruL6n/GTvi4Yah08OqWoz+an89NA6AKhuTs/E8b 8QMDVYL5fXd7b9DRY7sFRbK0mffr3n7xRzBSH01uXp00gjo24LXlUrU0mTicOZL/eIz1VR9c+FF pKYSJOVwj25XIliYyxQ/p1bPEP/LbzXpCp/G7WXCrMHgGU9s+07lVno4fArFm2e5pJU+9d852qc fE3a8vFY+wDb6wPJTif9nw2ecIon0R3uNyCjbKMI+4lrGIqPyt41tBp9l89HIkaRzIcHnGliAAO Zaww6ioLlM+CbLaI4F2dok8bBHKmWHai2i+g4sgGOvbxELDfJgYHbM7dAE9dPtBdirngXadfodR Vbvc/Kjr5dqxJ9nWXVuKmkbX0yIVLl5nNtf7iQKNNNrKLl5eQXtBHUWQwcVHzTcpTQ8= 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: 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 __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