qemu-patch-raspberry4/tests
Daniel P. Berrangé 087ab8e775 block: always fill entire LUKS header space with zeros
When initializing the LUKS header the size with default encryption
parameters will currently be 2068480 bytes. This is rounded up to
a multiple of the cluster size, 2081792, with 64k sectors. If the
end of the header is not the same as the end of the cluster we fill
the extra space with zeros. This was forgetting that not even the
space allocated for the header will be fully initialized, as we
only write key material for the first key slot. The space left
for the other 7 slots is never written to.

An optimization to the ref count checking code:

  commit a5fff8d4b4 (refs/bisect/bad)
  Author: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  Date:   Wed Feb 27 16:14:30 2019 +0300

    qcow2-refcount: avoid eating RAM

made the assumption that every cluster which was allocated would
have at least some data written to it. This was violated by way
the LUKS header is only partially written, with much space simply
reserved for future use.

Depending on the cluster size this problem was masked by the
logic which wrote zeros between the end of the LUKS header and
the end of the cluster.

$ qemu-img create --object secret,id=cluster_encrypt0,data=123456 \
   -f qcow2 -o cluster_size=2k,encrypt.iter-time=1,\
               encrypt.format=luks,encrypt.key-secret=cluster_encrypt0 \
               cluster_size_check.qcow2 100M
  Formatting 'cluster_size_check.qcow2', fmt=qcow2 size=104857600
    encrypt.format=luks encrypt.key-secret=cluster_encrypt0
    encrypt.iter-time=1 cluster_size=2048 lazy_refcounts=off refcount_bits=16

$ qemu-img check --object secret,id=cluster_encrypt0,data=redhat \
    'json:{"driver": "qcow2", "encrypt.format": "luks", \
           "encrypt.key-secret": "cluster_encrypt0", \
           "file.driver": "file", "file.filename": "cluster_size_check.qcow2"}'
ERROR: counting reference for region exceeding the end of the file by one cluster or more: offset 0x2000 size 0x1f9000
Leaked cluster 4 refcount=1 reference=0
...snip...
Leaked cluster 130 refcount=1 reference=0

1 errors were found on the image.
Data may be corrupted, or further writes to the image may corrupt it.

127 leaked clusters were found on the image.
This means waste of disk space, but no harm to data.
Image end offset: 268288

The problem only exists when the disk image is entirely empty. Writing
data to the disk image payload will solve the problem by causing the
end of the file to be extended further.

The change fixes it by ensuring that the entire allocated LUKS header
region is fully initialized with zeros. The qemu-img check will still
fail for any pre-existing disk images created prior to this change,
unless at least 1 byte of the payload is written to.

Fully writing zeros to the entire LUKS header is a good idea regardless
as it ensures that space has been allocated on the host filesystem (or
whatever block storage backend is used).

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200207135520.2669430-1-berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-02-20 16:43:42 +01:00
..
acceptance tests/acceptance: Remove shebang header 2020-02-07 15:12:48 +01:00
data virt/acpi: update golden masters for DSDT update 2020-02-13 14:14:53 +00:00
decode decodetree: Allow !function with no input bits 2019-08-19 08:03:41 -07:00
docker drop "from __future__ import print_function" 2020-02-07 15:15:16 +01:00
fp testing: don't nest build for fp-test 2020-01-09 11:41:29 +00:00
guest-debug drop "from __future__ import print_function" 2020-02-07 15:15:16 +01:00
image-fuzzer image-fuzzer: Use OSerror.strerror instead of tuple subscript 2019-11-05 16:36:11 +01:00
keys
migration drop "from __future__ import print_function" 2020-02-07 15:15:16 +01:00
multiboot tests/multiboot: Fix load address of test kernels 2019-07-30 12:25:43 +02:00
perf/block/qcow2 tests/perf: Test lseek influence on qcow2 block-status 2019-06-04 15:20:41 +02:00
plugin tcg plugins: expose an API version concept 2019-11-12 14:32:55 +00:00
qapi-schema drop "from __future__ import print_function" 2020-02-07 15:15:16 +01:00
qemu-iotests block: always fill entire LUKS header space with zeros 2020-02-20 16:43:42 +01:00
qtest qapi: Split control.json off misc.json 2020-02-17 13:53:47 +01:00
rocker
tcg tests/tcg: gate pauth-% tests on having compiler support 2020-02-04 17:13:29 +00:00
uefi-test-tools edk2 build scripts: work around TianoCore#1607 without forcing Python 2 2019-10-07 15:14:15 +02:00
vm drop "from __future__ import print_function" 2020-02-07 15:15:16 +01:00
vmstate-static-checker-data
.gitignore qapi: Generate command registration stuff into separate files 2020-01-14 11:01:58 +01:00
atomic64-bench.c tests: use g_usleep instead of rem = sleep(time) 2019-01-14 14:52:30 +00:00
atomic_add-bench.c tests: use g_usleep instead of rem = sleep(time) 2019-01-14 14:52:30 +00:00
benchmark-crypto-cipher.c tests: benchmark crypto with fixed data size, not time period 2019-10-28 13:32:21 +01:00
benchmark-crypto-hash.c tests: benchmark crypto with fixed data size, not time period 2019-10-28 13:32:21 +01:00
benchmark-crypto-hmac.c
check-block-qdict.c
check-block.sh build: move TARGET_GPROF to config-host.mak 2020-02-12 16:29:27 +01:00
check-qdict.c tests: Move qdict-test-data.txt to tests/data/qobject/ 2019-03-07 22:05:54 +01:00
check-qjson.c test: Use g_strndup instead of plain strndup 2019-08-21 10:27:13 +02:00
check-qlist.c
check-qlit.c
check-qnull.c
check-qnum.c
check-qobject.c
check-qom-interface.c qom: make interface types abstract 2018-12-11 15:45:22 -02:00
check-qom-proplist.c tests/qom-proplist: check class properties iterator 2018-10-05 16:27:09 +04:00
check-qstring.c
crypto-tls-psk-helpers.c
crypto-tls-psk-helpers.h Supply missing header guards 2019-06-12 13:20:21 +02:00
crypto-tls-x509-helpers.c
crypto-tls-x509-helpers.h Supply missing header guards 2019-06-12 13:20:21 +02:00
dbus-vmstate-daemon.sh tests: add dbus-vmstate-test 2020-01-06 18:41:32 +04:00
io-channel-helpers.c
io-channel-helpers.h Normalize position of header guard 2019-06-12 13:20:20 +02:00
iothread.c tests/iothread: Always connect iothread GSource to a GMainContext 2020-01-07 14:32:57 +00:00
iothread.h
Makefile.include tests/Makefile: Fix inclusion of the qos dependency files 2020-02-04 09:00:57 +01:00
pkix_asn1_tab.c
ptimer-test-stubs.c util/qemu-timer: refactor deadline calculation for external timers 2019-08-20 17:26:21 +02:00
ptimer-test.c tests/ptimer: Remove unnecessary inclusion of libqtest.h 2020-01-12 11:42:40 +01:00
ptimer-test.h
qht-bench.c tests: use g_usleep instead of rem = sleep(time) 2019-01-14 14:52:30 +00:00
rcutorture.c
requirements.txt Acceptance tests: use avocado.utils.ssh for SSH interaction 2019-09-20 17:13:41 -04:00
socket-helpers.c tests: specify the address family when checking bind 2019-08-22 17:30:25 +04:00
socket-helpers.h tests: specify the address family when checking bind 2019-08-22 17:30:25 +04:00
test-aio-multithread.c tests: Do not use "\n" in g_test_message() strings 2019-03-07 22:16:22 +01:00
test-aio.c
test-authz-list.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-authz-listfile.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-authz-pam.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-authz-simple.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-base64.c
test-bdrv-drain.c job: drop job_drain 2019-09-10 08:58:43 +02:00
test-bdrv-graph-mod.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
test-bitcnt.c
test-bitmap.c tests: use g_test_rand_int 2019-12-17 09:05:23 +01:00
test-bitops.c
test-block-backend.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
test-block-iothread.c block: Add @exact parameter to bdrv_co_truncate() 2019-10-28 12:00:07 +01:00
test-blockjob-txn.c job: drop job_drain 2019-09-10 08:58:43 +02:00
test-blockjob.c tests-blockjob: Use error_free_or_abort() 2019-12-18 08:36:16 +01:00
test-bufferiszero.c
test-char.c chardev: Use QEMUChrEvent enum in IOEventHandler typedef 2020-01-08 11:15:35 +01:00
test-clone-visitor.c tests: Rename UserDefNativeListUnion to UserDefListUnion 2019-03-05 14:43:11 +01:00
test-coroutine.c tests: Do not use "\n" in g_test_message() strings 2019-03-07 22:16:22 +01:00
test-crypto-afsplit.c
test-crypto-block.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-crypto-cipher.c
test-crypto-hash.c
test-crypto-hmac.c
test-crypto-ivgen.c
test-crypto-pbkdf.c test: execute g_test_run when tests are skipped 2019-01-11 13:57:25 +01:00
test-crypto-secret.c
test-crypto-tlscredsx509.c glib: use portable g_setenv() 2019-12-17 09:05:23 +01:00
test-crypto-tlssession.c glib: use portable g_setenv() 2019-12-17 09:05:23 +01:00
test-crypto-xts.c crypto: add testing for unaligned buffers with XTS cipher mode 2018-10-24 19:03:37 +01:00
test-cutils.c cutils: Fix qemu_strtosz() & friends to reject non-finite sizes 2018-12-13 19:10:06 +01:00
test-hbitmap.c util/hbitmap: strict hbitmap_reset 2019-10-17 17:02:32 -04:00
test-image-locking.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
test-int128.c
test-io-channel-buffer.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-io-channel-command.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-io-channel-file.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-io-channel-socket.c socket: Add num connections to qio_channel_socket_async() 2019-09-03 23:24:42 +02:00
test-io-channel-tls.c glib: use portable g_setenv() 2019-12-17 09:05:23 +01:00
test-io-task.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
test-iov.c
test-keyval.c test-keyval: Tighten test of trailing crap after size 2019-12-18 12:28:44 +01:00
test-logging.c test-logging: Fix -Werror=maybe-uninitialized warning 2020-02-04 09:00:57 +01:00
test-mul64.c
test-opts-visitor.c
test-qapi-util.c
test-qdev-global-props.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
test-qdist.c
test-qemu-opts.c
test-qga.c tests: use g_test_rand_int 2019-12-17 09:05:23 +01:00
test-qgraph.c tests: test-qgraph: fix a memory leak 2019-03-11 16:33:49 +01:00
test-qht-par.c
test-qht.c qht: drop ht argument from qht iterators 2018-09-26 08:55:54 -07:00
test-qmp-cmds.c qapi: Generate command registration stuff into separate files 2020-01-14 11:01:58 +01:00
test-qmp-event.c qapi: Generate QAPIEvent stuff into separate files 2019-02-18 14:44:04 +01:00
test-qobject-input-visitor.c tests: Rename UserDefNativeListUnion to UserDefListUnion 2019-03-05 14:43:11 +01:00
test-qobject-output-visitor.c tests: Clean up initialization of Error *err variables 2019-12-18 08:36:15 +01:00
test-rcu-list.c qemu/queue.h: leave head structs anonymous unless necessary 2019-01-11 15:46:55 +01:00
test-rcu-simpleq.c
test-rcu-tailq.c
test-replication.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
test-shift128.c
test-string-input-visitor.c tests: Fix uninitialized byte in test_visitor_in_fuzz 2019-08-20 17:26:19 +02:00
test-string-output-visitor.c tests: Clean up initialization of Error *err variables 2019-12-18 08:36:15 +01:00
test-thread-pool.c test-thread-pool: be more reliable 2019-06-03 14:03:00 +02:00
test-throttle.c test-throttle: Fix uninitialized use of burst_length 2019-08-20 17:26:19 +02:00
test-timed-average.c
test-util-filemonitor.c tests/test-util-filemonitor: Skip test on non-x86 Travis containers 2019-12-18 20:17:45 +00:00
test-util-sockets.c socket: Add backlog parameter to socket_listen 2019-09-03 23:24:42 +02:00
test-uuid.c
test-visitor-serialization.c
test-vmstate.c migration: Support QLIST migration 2020-01-20 09:10:23 +01:00
test-write-threshold.c
test-x86-cpuid.c i386: Update new x86_apicid parsing rules with die_offset support 2019-07-05 17:08:03 -03:00
test-xbzrle.c
vhost-user-bridge.c core: replace getpagesize() with qemu_real_host_page_size 2019-10-26 15:38:06 +02:00