git: 8d14946edd56 - stable/15 - camcontrol: Require a reservation type for reserve, preempt and release

From: Kenneth D. Merry <ken_at_FreeBSD.org>
Date: Mon, 16 Nov 2026 21:00:44 UTC
The branch stable/15 has been updated by ken:

URL: https://cgit.FreeBSD.org/src/commit/?id=8d14946edd56ac57e6a2f0e82848dfef7d8d88ca

commit 8d14946edd56ac57e6a2f0e82848dfef7d8d88ca
Author:     Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-09 18:47:00 +0000
Commit:     Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-16 16:12:44 +0000

    camcontrol: Require a reservation type for reserve, preempt and release
    
    res_type was initialized to 0, but the checks that enforce the -T
    argument for the reserve, preempt and release reservation actions
    compare it against -1, so they could never fire and camcontrol
    silently sent a reservation type of 0, which is invalid.
    Initialize res_type to -1 so the checks work, and default the
    reservation type to 0 for the release action's clear variant,
    which does not take -T and ignores the field.
    
    Reported by:    llm-postcr
    Fixes:          ba75cf05727e
    MFC after:      1 week
    Sponsored by:   Spectra Logic
    Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
    
    (cherry picked from commit b95e2b2ce907cde89bc3e7be2ffeae03cfed55ab)
---
 sbin/camcontrol/nvres.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sbin/camcontrol/nvres.c b/sbin/camcontrol/nvres.c
index ab6132d45fde..1145278356c3 100644
--- a/sbin/camcontrol/nvres.c
+++ b/sbin/camcontrol/nvres.c
@@ -450,7 +450,7 @@ nvmepersist(struct cam_device *device, int argc, char **argv, char *combinedopt,
 	int eds = 0, cptpl = 0, iekey = 0;
 	int error = 0;
 	int in = 0, out = 0;
-	int opc = -1, op_action = -1, res_type = 0;
+	int opc = -1, op_action = -1, res_type = -1;
 	int c;
 
 	while ((c = getopt(argc, argv, combinedopt)) != -1) {
@@ -659,6 +659,9 @@ nvmepersist(struct cam_device *device, int argc, char **argv, char *combinedopt,
 				error = 1;
 				goto bailout;
 			}
+			/* The reservation type is ignored for a clear. */
+			if (res_type == -1)
+				res_type = 0;
 			break;
 		}