From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452401; b=2O5om4ZSnuMxQQae877ZBoyZgRe7FyAkNsCE7i8HNqRqxCBkkSacwmQD80MJ1SPoqNuk sA6RcQyfSz9vWUpjHIkmIJc9lVB/iZ/Dg9nwXtTzu+UEfnt+mmgSoHOH+2fLm8r2m3eP8 72Ua5McEe3d/T6sy4RpM4c1D92f8UuEITyYmVXt0dWn9Ig7fBvdNPXFraL1yP/QfikVKJ gP6WKQ9bsUSYYcdzD6ia8xa/C+xboeOpYFYNlpvqk3ccHJWXwxHitws+EGG4v+HZuDH4u mC8Pw2kcJ7Y8URftStCdJJc/x6BTRDCVzdGaMvu5g+HfFLfs+0YOxSQE5+u8wlbKFbA== 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=IKaaIfxRRM3rICtJKELTp7A+oJyp4UcvXiecLlEl1giAUb20zc2CO/n9V0bQZDqx03AT jd7maN5AzmeXSCg7cqVIzI1RUbeYRz7TpC0snYWT7h4v4tskSX1DBurZe2ImUToL++jkN eVL7M/59OOLPi4VnDd2Ia5C5dDONh/jXA1e1/fYekGnnGDWJb3xLqOp0A8EUvMjFZDhSK ytsnSq8HHNatHs591vjtk2yBcR265Bu2YbdTqgghfUzZexBIUkMDBYH9ikfMD0YwUR1jE pAw72beZS631V7dNj+Gs3mVoqJVK3EDF1LLEaZVB1ohLec+RUMURmx5hd0RQ9NPzdVA== 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.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 9425460A3833 for ; Sat, 5 Dec 2026 06:33:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9425460A3833 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-f182.google.com with SMTP id 5a478bee46e88-386bd881d39so2977669eec.1 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=PY4mCrIoheLFmxV4UVCdtnuvPCQhA0AImYbX7YNu0zvzRgO/e3jn2vH015c7udgIrK /Tmju5Q3wnaG0a598CXrIoFWUlllIBd9cz6rQ3mAqqw9o7c5xYGg0onw6Ixt0k5QNriu vjz/B3PYlH8CcU20dBCHkiM+VKSmE/BdKj/QUM/SeuVWX3tcAn+eLvY6wQOy5j3lSIeR Z30dq8apktudtPDd7jL3REk75kvcALahopzvpBBN54tyRfiPDGcjd4GJqYCTl+paf2OB RWp8VUTzCngFW1ezoGk8OYzgzMaQpaO97XDJw5ogSf6uuBQesOOFVuukNkvxxAeWDK9L Hgjw== X-Forwarded-Encrypted: i=1; AL+hErFRBUrHJIgtp1QM8ixmLiNOvSVVv3AA7ijIESTlDZLKA0bDpMuE1V51W++cImAORoIHCYTsOfk5XvVYr4Y=@vger.kernel.org X-Gm-Message-State: AB4q+uHDwlTBUeYSIGKdb36B8+pMkt5lyDiNmgC9xzoJzxt4KEFEsA/O auphRppYrsdVlfjPRAhwCcV3DF82Akh0+aSGyF6d034Byrt8YgDeQTjUmMS+0YUc X-Gm-Gg: AZFdTZd7TZfyPhV+zrA9cOLksa9hpDkgxDBjg//d5CIrrrFvXWMm1fAeJP8o6KmmXQz Y3FhMQ6qRzLEvFbCRrynbx1zIGn9Cq5iN4qkUF4YJpYOfkvHBVRcZVFOyxWsCIeWehaTVvHKzS0 3cnWin5upQHZIyjWjEauLKDa2pur3dW69T0eBHcjRWGxtXG4uZCgukfsXshBrBoirNvovQ0eJys 9hTO3AoXJpS4oYng9fo6PN3yQEriMfBv1eHme3F+h6DwprN3E8M4qXojdU2znWZeZ4BHm1ugYp/ 2jpHRDbdzuL4hZ1vbzBBh6Z6IJnWNKFTse+uhmtK9TUMeEVpgmKJgkIIrxk5lU15jQptjWtRXHT zmhDcB8p7YTG5qHIAIj8MijouI2K5qzc7FH3lZVUlYTXPEEyw09Vg9WgeXRf6/+ifxuAfK0P8Y6 kbfWSXyA99JZ7Ek19Tgz3YeP8vFhLiZgFFqE8IvM16hQkuo836brFhyuivUTtBwo7fRp8FnnSlZ RUGGf26qBBV2WGL16/cTOkZyTeJlnAvvwS8QQObG83KoeZD9DQhQbPGp6eQ4Hc65SuuNd1G3trq u3jWUsVBU6cXkg8eqmZF1gnVr6kiu+OIY6qhOUdD0aIyILrMEaWc+qvIo7FzWNNyRn8= 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: target-devel@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