All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven <pl@kamp.de>,
	ronniesahlberg@gmail.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCHv3 10/10] iscsi: assert that sectors are aligned to LUN blocksize
Date: Thu, 11 Jul 2013 14:16:27 +0200	[thread overview]
Message-ID: <1373544987-20613-11-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1373544987-20613-1-git-send-email-pl@kamp.de>

if the blocksize of an iSCSI LUN is bigger than the BDRV_SECTOR_SIZE
it is possible that sector_num or nb_sectors are not correctly
alligned.

to avoid corruption we fail requests which are misaligned.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/block/iscsi.c b/block/iscsi.c
index 903f2fb..2b8fab9 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -292,6 +292,18 @@ static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun)
     return sector * iscsilun->block_size / BDRV_SECTOR_SIZE;
 }
 
+static bool is_request_lun_aligned(int64_t sector_num, int nb_sectors,
+                                      IscsiLun *iscsilun)
+{
+    if ((sector_num * BDRV_SECTOR_SIZE) % iscsilun->block_size ||
+        (nb_sectors * BDRV_SECTOR_SIZE) % iscsilun->block_size) {
+            error_report("iSCSI misaligned request: iscsilun->block_size %u, sector_num %ld, nb_sectors %d",
+                         iscsilun->block_size, sector_num, nb_sectors);
+            return 0;
+    }
+    return 1;
+}
+
 static int
 iscsi_aio_writev_acb(IscsiAIOCB *acb)
 {
@@ -376,6 +388,10 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num,
     IscsiLun *iscsilun = bs->opaque;
     IscsiAIOCB *acb;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        return NULL;
+    }
+
     acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque);
     trace_iscsi_aio_writev(iscsilun->iscsi, sector_num, nb_sectors, opaque, acb);
 
@@ -507,6 +523,10 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
     IscsiLun *iscsilun = bs->opaque;
     IscsiAIOCB *acb;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        return NULL;
+    }
+
     acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque);
     trace_iscsi_aio_readv(iscsilun->iscsi, sector_num, nb_sectors, opaque, acb);
 
@@ -774,6 +794,12 @@ static int coroutine_fn iscsi_co_is_allocated(BlockDriverState *bs,
     ret = 1;
     *pnum = nb_sectors;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        ret = 0;
+        *pnum = 0;
+        goto out;
+    }
+
     /* LUN does not support logical block provisioning */
     if (iscsilun->lbpme == 0) {
         goto out;
@@ -853,6 +879,10 @@ coroutine_fn iscsi_co_discard(BlockDriverState *bs, int64_t sector_num,
     struct unmap_list list;
     uint32_t nb_blocks;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        return -EINVAL;
+    }
+
     if (!iscsilun->lbpu) {
         return 0;
     }
@@ -903,6 +933,10 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
 {
     IscsiLun *iscsilun = bs->opaque;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        return -EINVAL;
+    }
+
     if (!iscsilun->lbprz || !iscsilun->lbpu ||
         !(bs->open_flags & BDRV_O_UNMAP)) {
         /* fall back to writev */
-- 
1.7.9.5

  parent reply	other threads:[~2013-07-11 12:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-11 12:16 [Qemu-devel] [PATCHv3 00/10] iscsi/qemu-img/block-migration enhancements Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 01/10] iscsi: add logical block provisioning information to iscsilun Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 02/10] iscsi: add .bdrv_co_is_allocated Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 03/10] iscsi: add .bdrv_co_discard Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 04/10] iscsi: add .bdrv_write_zeroes Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 05/10] block: add bdrv_write_zeroes() Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 06/10] block/raw: add bdrv_co_write_zeroes Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 07/10] iscsi: fix -ENOSPC in iscsi_create() Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 08/10] iscsi: factor out sector conversions Peter Lieven
2013-07-11 12:16 ` [Qemu-devel] [PATCHv3 09/10] iscsi: remove support for misaligned nb_sectors in aio_readv Peter Lieven
2013-07-11 12:16 ` Peter Lieven [this message]
2013-07-17 15:05 ` [Qemu-devel] [PATCHv3 00/10] iscsi/qemu-img/block-migration enhancements Paolo Bonzini
2013-07-18  8:24   ` Peter Lieven
2013-07-18  6:36 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373544987-20613-11-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.