0a122b
From bcf0f4b1f226bcb27e154cc14850f67229b22d90 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <bcf0f4b1f226bcb27e154cc14850f67229b22d90.1389014116.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Date: Mon, 9 Dec 2013 14:09:24 +0100
0a122b
Subject: [PATCH 36/50] scsi-disk: reject ANCHOR=1 for UNMAP and WRITE SAME
0a122b
 commands
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-39-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56075
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 38/52] scsi-disk: reject ANCHOR=1 for UNMAP and WRITE SAME commands
0a122b
Bugzilla: 1007815
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
Since we report ANC_SUP==0 in VPD page B2h, we need to return
0a122b
an error (ILLEGAL REQUEST/INVALID FIELD IN CDB) for all WRITE SAME
0a122b
requests with ANCHOR==1.
0a122b
0a122b
Inspired by a similar patch to the LIO in-kernel target.
0a122b
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 823bd7391c96ba675f20fd6d952d1cb6e1ffb851)
0a122b
---
0a122b
 hw/scsi/scsi-disk.c | 12 +++++++++++-
0a122b
 1 file changed, 11 insertions(+), 1 deletion(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 hw/scsi/scsi-disk.c | 12 +++++++++++-
0a122b
 1 file changed, 11 insertions(+), 1 deletion(-)
0a122b
0a122b
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
0a122b
index 4138268..0640bb0 100644
0a122b
--- a/hw/scsi/scsi-disk.c
0a122b
+++ b/hw/scsi/scsi-disk.c
0a122b
@@ -1548,6 +1548,11 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
0a122b
     int len = r->req.cmd.xfer;
0a122b
     UnmapCBData *data;
0a122b
 
0a122b
+    /* Reject ANCHOR=1.  */
0a122b
+    if (r->req.cmd.buf[1] & 0x1) {
0a122b
+        goto invalid_field;
0a122b
+    }
0a122b
+
0a122b
     if (len < 8) {
0a122b
         goto invalid_param_len;
0a122b
     }
0a122b
@@ -1578,6 +1583,10 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
0a122b
 
0a122b
 invalid_param_len:
0a122b
     scsi_check_condition(r, SENSE_CODE(INVALID_PARAM_LEN));
0a122b
+    return;
0a122b
+
0a122b
+invalid_field:
0a122b
+    scsi_check_condition(r, SENSE_CODE(INVALID_FIELD));
0a122b
 }
0a122b
 
0a122b
 static void scsi_disk_emulate_write_data(SCSIRequest *req)
0a122b
@@ -1856,8 +1865,9 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
0a122b
 
0a122b
         /*
0a122b
          * We only support WRITE SAME with the unmap bit set for now.
0a122b
+         * Reject UNMAP=0 or ANCHOR=1.
0a122b
          */
0a122b
-        if (!(req->cmd.buf[1] & 0x8)) {
0a122b
+        if (!(req->cmd.buf[1] & 0x8) || (req->cmd.buf[1] & 0x10)) {
0a122b
             goto illegal_request;
0a122b
         }
0a122b
 
0a122b
-- 
0a122b
1.7.11.7
0a122b