All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-block@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Bandan Das" <bsd@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>
Subject: [PATCH v2 2/2] block/null: Enable 'read-zeroes' mode by default
Date: Thu, 11 Feb 2021 15:26:56 +0100	[thread overview]
Message-ID: <20210211142656.3818078-3-philmd@redhat.com> (raw)
In-Reply-To: <20210211142656.3818078-1-philmd@redhat.com>

The null-co driver is meant for (performance) testing.
By default, read operation does nothing, the provided buffer
is not filled with zero values and its content is unchanged.

This performance 'feature' becomes an issue from a security
perspective.  For example, using the default null-co driver,
buf[] is uninitialized, the blk_pread() call succeeds and we
then access uninitialized memory:

  static int guess_disk_lchs(BlockBackend *blk,
                             int *pcylinders, int *pheads,
                             int *psectors)
  {
      uint8_t buf[BDRV_SECTOR_SIZE];
      ...

      if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE) < 0) {
          return -1;
      }
      /* test msdos magic */
      if (buf[510] != 0x55 || buf[511] != 0xaa) {
          return -1;
      }

We could audit all the uninitialized buffers and the
bdrv_co_preadv() handlers, but it is simpler to change the
default of this testing driver. Performance tests will have
to adapt and use 'null-co,read-zeroes=off'.

Suggested-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 block/null.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/null.c b/block/null.c
index cc9b1d4ea72..f9658fd70ac 100644
--- a/block/null.c
+++ b/block/null.c
@@ -93,7 +93,7 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,
         error_setg(errp, "latency-ns is invalid");
         ret = -EINVAL;
     }
-    s->read_zeroes = qemu_opt_get_bool(opts, NULL_OPT_ZEROES, false);
+    s->read_zeroes = qemu_opt_get_bool(opts, NULL_OPT_ZEROES, true);
     qemu_opts_del(opts);
     bs->supported_write_flags = BDRV_REQ_FUA;
     return ret;
-- 
2.26.2



  parent reply	other threads:[~2021-02-11 14:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 14:26 [PATCH v2 0/2] block: Use 'read-zeroes=true' mode by default with 'null-co' driver Philippe Mathieu-Daudé
2021-02-11 14:26 ` [PATCH v2 1/2] block: Explicit null-co uses 'read-zeroes=false' Philippe Mathieu-Daudé
2021-02-11 16:29   ` Vladimir Sementsov-Ogievskiy
2021-02-11 19:19     ` Philippe Mathieu-Daudé
2021-02-11 22:40   ` Eric Blake
2021-02-11 23:49     ` Philippe Mathieu-Daudé
2021-02-12 11:34     ` Vladimir Sementsov-Ogievskiy
2021-02-12 19:06   ` Eric Blake
2021-02-11 14:26 ` Philippe Mathieu-Daudé [this message]
2021-02-11 16:22   ` [PATCH v2 2/2] block/null: Enable 'read-zeroes' mode by default Stefan Hajnoczi
2021-02-11 15:42 ` [PATCH v2 0/2] block: Use 'read-zeroes=true' mode by default with 'null-co' driver Alexander Bulekov
2021-02-12 14:32   ` Philippe Mathieu-Daudé
2021-02-13 21:54 ` Fam Zheng
2021-02-19 11:07   ` Max Reitz
2021-02-19 14:09     ` Philippe Mathieu-Daudé
2021-02-22 17:35       ` Fam Zheng
2021-02-22 17:55         ` Philippe Mathieu-Daudé
2021-02-23  9:21           ` Fam Zheng
2021-02-23 16:01             ` Max Reitz
2021-02-23 17:21               ` Fam Zheng
2021-02-22 18:15       ` Daniel P. Berrangé
2021-02-22 18:36         ` Philippe Mathieu-Daudé
2021-02-23  8:44         ` Max Reitz
2021-02-23  9:29           ` Daniel P. Berrangé

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=20210211142656.3818078-3-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=alxndr@bu.edu \
    --cc=armbru@redhat.com \
    --cc=bsd@redhat.com \
    --cc=crosa@redhat.com \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=wainersm@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.