kern/185626: virtio-scsi driver incorrectly encodes LUNs for device

Venkatesh Srinivas venkateshs at google.com
Fri Jan 10 01:50:00 UTC 2014


>Number:         185626
>Category:       kern
>Synopsis:       virtio-scsi driver incorrectly encodes LUNs for device
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 10 01:50:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Venkatesh Srinivas
>Release:        9.2-RELEASE
>Organization:
Google, Inc
>Environment:
FreeBSD freefall 9.2-RELEASE FreeBSD 9.2-RELEASE #0: Thu Jan  9 16:14:41 PST 2014     root at freefall:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
The virtio-scsi driver in FreeBSD 9.2-RELEASE (and in -current) encodes CAM LUN identifiers into virtio-scsi identifiers in vtscsi_set_request_lun(). vtscsi_set_request_lun constructs the low byte (lun[3]) of the transport-layer LUN incorrectly, resulting in mapping LUNs [0-255] to LUN 0.

For hypervisors and SCSI targets which emulate REPORT LUNs, this is harmless. For ones that do not, this may result in multiple CAM targets for a single physical target.
>How-To-Repeat:

>Fix:
Patch attached with fix.

Fix is tested on qemu from git -master, with REPORT LUNs disabled. Fix is also tested on Google Compute Engine hypervisor.

Patch attached with submission follows:

>From 847c465b06ffe0bb4a4f61c33bd0c76c45f62e33 Mon Sep 17 00:00:00 2001
From: Venkatesh Srinivas <venkateshs at google.com>
Date: Thu, 9 Jan 2014 16:13:44 -0800
Subject: [PATCH] virtio_scsi: Correct conversion of CAM-layer LUN to
 virtio-scsi LUN.

virtio_scsi was incorrectly shifting the CAM-layer LUN before
extracting the low byte. This would result in mapping LUNs [0-255]
to LUN 0.
---
 sys/dev/virtio/scsi/virtio_scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/virtio/scsi/virtio_scsi.c b/sys/dev/virtio/scsi/virtio_scsi.c
index e5f922be..ccee89a 100644
--- a/sys/dev/virtio/scsi/virtio_scsi.c
+++ b/sys/dev/virtio/scsi/virtio_scsi.c
@@ -1539,7 +1539,7 @@ vtscsi_set_request_lun(struct ccb_hdr *ccbh, uint8_t lun[])
 	lun[0] = 1;
 	lun[1] = ccbh->target_id;
 	lun[2] = 0x40 | ((ccbh->target_lun >> 8) & 0x3F);
-	lun[3] = (ccbh->target_lun >> 8) & 0xFF;
+	lun[3] = ccbh->target_lun & 0xFF;
 }
 
 static void
-- 
1.8.5.1



>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list