xref: /openbmc/qemu/block/crypto.c (revision e3a99063)
1 /*
2  * QEMU block full disk encryption
3  *
4  * Copyright (c) 2015-2016 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include "qemu/osdep.h"
22 
23 #include "block/block_int.h"
24 #include "block/qdict.h"
25 #include "sysemu/block-backend.h"
26 #include "crypto/block.h"
27 #include "qapi/opts-visitor.h"
28 #include "qapi/qapi-visit-crypto.h"
29 #include "qapi/qobject-input-visitor.h"
30 #include "qapi/error.h"
31 #include "qemu/module.h"
32 #include "qemu/option.h"
33 #include "qemu/cutils.h"
34 #include "crypto.h"
35 
36 typedef struct BlockCrypto BlockCrypto;
37 
38 struct BlockCrypto {
39     QCryptoBlock *block;
40 };
41 
42 
43 static int block_crypto_probe_generic(QCryptoBlockFormat format,
44                                       const uint8_t *buf,
45                                       int buf_size,
46                                       const char *filename)
47 {
48     if (qcrypto_block_has_format(format, buf, buf_size)) {
49         return 100;
50     } else {
51         return 0;
52     }
53 }
54 
55 
56 static ssize_t block_crypto_read_func(QCryptoBlock *block,
57                                       size_t offset,
58                                       uint8_t *buf,
59                                       size_t buflen,
60                                       void *opaque,
61                                       Error **errp)
62 {
63     BlockDriverState *bs = opaque;
64     ssize_t ret;
65 
66     ret = bdrv_pread(bs->file, offset, buf, buflen);
67     if (ret < 0) {
68         error_setg_errno(errp, -ret, "Could not read encryption header");
69         return ret;
70     }
71     return ret;
72 }
73 
74 
75 struct BlockCryptoCreateData {
76     BlockBackend *blk;
77     uint64_t size;
78     PreallocMode prealloc;
79 };
80 
81 
82 static ssize_t block_crypto_write_func(QCryptoBlock *block,
83                                        size_t offset,
84                                        const uint8_t *buf,
85                                        size_t buflen,
86                                        void *opaque,
87                                        Error **errp)
88 {
89     struct BlockCryptoCreateData *data = opaque;
90     ssize_t ret;
91 
92     ret = blk_pwrite(data->blk, offset, buf, buflen, 0);
93     if (ret < 0) {
94         error_setg_errno(errp, -ret, "Could not write encryption header");
95         return ret;
96     }
97     return ret;
98 }
99 
100 
101 static ssize_t block_crypto_init_func(QCryptoBlock *block,
102                                       size_t headerlen,
103                                       void *opaque,
104                                       Error **errp)
105 {
106     struct BlockCryptoCreateData *data = opaque;
107 
108     if (data->size > INT64_MAX || headerlen > INT64_MAX - data->size) {
109         error_setg(errp, "The requested file size is too large");
110         return -EFBIG;
111     }
112 
113     /* User provided size should reflect amount of space made
114      * available to the guest, so we must take account of that
115      * which will be used by the crypto header
116      */
117     return blk_truncate(data->blk, data->size + headerlen, false,
118                         data->prealloc, 0, errp);
119 }
120 
121 
122 static QemuOptsList block_crypto_runtime_opts_luks = {
123     .name = "crypto",
124     .head = QTAILQ_HEAD_INITIALIZER(block_crypto_runtime_opts_luks.head),
125     .desc = {
126         BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""),
127         { /* end of list */ }
128     },
129 };
130 
131 
132 static QemuOptsList block_crypto_create_opts_luks = {
133     .name = "crypto",
134     .head = QTAILQ_HEAD_INITIALIZER(block_crypto_create_opts_luks.head),
135     .desc = {
136         {
137             .name = BLOCK_OPT_SIZE,
138             .type = QEMU_OPT_SIZE,
139             .help = "Virtual disk size"
140         },
141         BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""),
142         BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG(""),
143         BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE(""),
144         BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG(""),
145         BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG(""),
146         BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG(""),
147         BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME(""),
148         { /* end of list */ }
149     },
150 };
151 
152 
153 QCryptoBlockOpenOptions *
154 block_crypto_open_opts_init(QDict *opts, Error **errp)
155 {
156     Visitor *v;
157     QCryptoBlockOpenOptions *ret;
158 
159     v = qobject_input_visitor_new_flat_confused(opts, errp);
160     if (!v) {
161         return NULL;
162     }
163 
164     visit_type_QCryptoBlockOpenOptions(v, NULL, &ret, errp);
165 
166     visit_free(v);
167     return ret;
168 }
169 
170 
171 QCryptoBlockCreateOptions *
172 block_crypto_create_opts_init(QDict *opts, Error **errp)
173 {
174     Visitor *v;
175     QCryptoBlockCreateOptions *ret;
176 
177     v = qobject_input_visitor_new_flat_confused(opts, errp);
178     if (!v) {
179         return NULL;
180     }
181 
182     visit_type_QCryptoBlockCreateOptions(v, NULL, &ret, errp);
183 
184     visit_free(v);
185     return ret;
186 }
187 
188 
189 static int block_crypto_open_generic(QCryptoBlockFormat format,
190                                      QemuOptsList *opts_spec,
191                                      BlockDriverState *bs,
192                                      QDict *options,
193                                      int flags,
194                                      Error **errp)
195 {
196     BlockCrypto *crypto = bs->opaque;
197     QemuOpts *opts = NULL;
198     Error *local_err = NULL;
199     int ret = -EINVAL;
200     QCryptoBlockOpenOptions *open_opts = NULL;
201     unsigned int cflags = 0;
202     QDict *cryptoopts = NULL;
203 
204     bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file,
205                                false, errp);
206     if (!bs->file) {
207         return -EINVAL;
208     }
209 
210     bs->supported_write_flags = BDRV_REQ_FUA &
211         bs->file->bs->supported_write_flags;
212 
213     opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
214     qemu_opts_absorb_qdict(opts, options, &local_err);
215     if (local_err) {
216         error_propagate(errp, local_err);
217         goto cleanup;
218     }
219 
220     cryptoopts = qemu_opts_to_qdict(opts, NULL);
221     qdict_put_str(cryptoopts, "format", QCryptoBlockFormat_str(format));
222 
223     open_opts = block_crypto_open_opts_init(cryptoopts, errp);
224     if (!open_opts) {
225         goto cleanup;
226     }
227 
228     if (flags & BDRV_O_NO_IO) {
229         cflags |= QCRYPTO_BLOCK_OPEN_NO_IO;
230     }
231     crypto->block = qcrypto_block_open(open_opts, NULL,
232                                        block_crypto_read_func,
233                                        bs,
234                                        cflags,
235                                        1,
236                                        errp);
237 
238     if (!crypto->block) {
239         ret = -EIO;
240         goto cleanup;
241     }
242 
243     bs->encrypted = true;
244 
245     ret = 0;
246  cleanup:
247     qobject_unref(cryptoopts);
248     qapi_free_QCryptoBlockOpenOptions(open_opts);
249     return ret;
250 }
251 
252 
253 static int block_crypto_co_create_generic(BlockDriverState *bs,
254                                           int64_t size,
255                                           QCryptoBlockCreateOptions *opts,
256                                           PreallocMode prealloc,
257                                           Error **errp)
258 {
259     int ret;
260     BlockBackend *blk;
261     QCryptoBlock *crypto = NULL;
262     struct BlockCryptoCreateData data;
263 
264     blk = blk_new(bdrv_get_aio_context(bs),
265                   BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
266 
267     ret = blk_insert_bs(blk, bs, errp);
268     if (ret < 0) {
269         goto cleanup;
270     }
271 
272     if (prealloc == PREALLOC_MODE_METADATA) {
273         prealloc = PREALLOC_MODE_OFF;
274     }
275 
276     data = (struct BlockCryptoCreateData) {
277         .blk = blk,
278         .size = size,
279         .prealloc = prealloc,
280     };
281 
282     crypto = qcrypto_block_create(opts, NULL,
283                                   block_crypto_init_func,
284                                   block_crypto_write_func,
285                                   &data,
286                                   errp);
287 
288     if (!crypto) {
289         ret = -EIO;
290         goto cleanup;
291     }
292 
293     ret = 0;
294  cleanup:
295     qcrypto_block_free(crypto);
296     blk_unref(blk);
297     return ret;
298 }
299 
300 static int coroutine_fn
301 block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
302                          PreallocMode prealloc, BdrvRequestFlags flags,
303                          Error **errp)
304 {
305     BlockCrypto *crypto = bs->opaque;
306     uint64_t payload_offset =
307         qcrypto_block_get_payload_offset(crypto->block);
308 
309     if (payload_offset > INT64_MAX - offset) {
310         error_setg(errp, "The requested file size is too large");
311         return -EFBIG;
312     }
313 
314     offset += payload_offset;
315 
316     return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp);
317 }
318 
319 static void block_crypto_close(BlockDriverState *bs)
320 {
321     BlockCrypto *crypto = bs->opaque;
322     qcrypto_block_free(crypto->block);
323 }
324 
325 static int block_crypto_reopen_prepare(BDRVReopenState *state,
326                                        BlockReopenQueue *queue, Error **errp)
327 {
328     /* nothing needs checking */
329     return 0;
330 }
331 
332 /*
333  * 1 MB bounce buffer gives good performance / memory tradeoff
334  * when using cache=none|directsync.
335  */
336 #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024)
337 
338 static coroutine_fn int
339 block_crypto_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
340                        QEMUIOVector *qiov, int flags)
341 {
342     BlockCrypto *crypto = bs->opaque;
343     uint64_t cur_bytes; /* number of bytes in current iteration */
344     uint64_t bytes_done = 0;
345     uint8_t *cipher_data = NULL;
346     QEMUIOVector hd_qiov;
347     int ret = 0;
348     uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
349     uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
350 
351     assert(!flags);
352     assert(payload_offset < INT64_MAX);
353     assert(QEMU_IS_ALIGNED(offset, sector_size));
354     assert(QEMU_IS_ALIGNED(bytes, sector_size));
355 
356     qemu_iovec_init(&hd_qiov, qiov->niov);
357 
358     /* Bounce buffer because we don't wish to expose cipher text
359      * in qiov which points to guest memory.
360      */
361     cipher_data =
362         qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE,
363                                               qiov->size));
364     if (cipher_data == NULL) {
365         ret = -ENOMEM;
366         goto cleanup;
367     }
368 
369     while (bytes) {
370         cur_bytes = MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE);
371 
372         qemu_iovec_reset(&hd_qiov);
373         qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes);
374 
375         ret = bdrv_co_preadv(bs->file, payload_offset + offset + bytes_done,
376                              cur_bytes, &hd_qiov, 0);
377         if (ret < 0) {
378             goto cleanup;
379         }
380 
381         if (qcrypto_block_decrypt(crypto->block, offset + bytes_done,
382                                   cipher_data, cur_bytes, NULL) < 0) {
383             ret = -EIO;
384             goto cleanup;
385         }
386 
387         qemu_iovec_from_buf(qiov, bytes_done, cipher_data, cur_bytes);
388 
389         bytes -= cur_bytes;
390         bytes_done += cur_bytes;
391     }
392 
393  cleanup:
394     qemu_iovec_destroy(&hd_qiov);
395     qemu_vfree(cipher_data);
396 
397     return ret;
398 }
399 
400 
401 static coroutine_fn int
402 block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
403                         QEMUIOVector *qiov, int flags)
404 {
405     BlockCrypto *crypto = bs->opaque;
406     uint64_t cur_bytes; /* number of bytes in current iteration */
407     uint64_t bytes_done = 0;
408     uint8_t *cipher_data = NULL;
409     QEMUIOVector hd_qiov;
410     int ret = 0;
411     uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
412     uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
413 
414     assert(!(flags & ~BDRV_REQ_FUA));
415     assert(payload_offset < INT64_MAX);
416     assert(QEMU_IS_ALIGNED(offset, sector_size));
417     assert(QEMU_IS_ALIGNED(bytes, sector_size));
418 
419     qemu_iovec_init(&hd_qiov, qiov->niov);
420 
421     /* Bounce buffer because we're not permitted to touch
422      * contents of qiov - it points to guest memory.
423      */
424     cipher_data =
425         qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE,
426                                               qiov->size));
427     if (cipher_data == NULL) {
428         ret = -ENOMEM;
429         goto cleanup;
430     }
431 
432     while (bytes) {
433         cur_bytes = MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE);
434 
435         qemu_iovec_to_buf(qiov, bytes_done, cipher_data, cur_bytes);
436 
437         if (qcrypto_block_encrypt(crypto->block, offset + bytes_done,
438                                   cipher_data, cur_bytes, NULL) < 0) {
439             ret = -EIO;
440             goto cleanup;
441         }
442 
443         qemu_iovec_reset(&hd_qiov);
444         qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes);
445 
446         ret = bdrv_co_pwritev(bs->file, payload_offset + offset + bytes_done,
447                               cur_bytes, &hd_qiov, flags);
448         if (ret < 0) {
449             goto cleanup;
450         }
451 
452         bytes -= cur_bytes;
453         bytes_done += cur_bytes;
454     }
455 
456  cleanup:
457     qemu_iovec_destroy(&hd_qiov);
458     qemu_vfree(cipher_data);
459 
460     return ret;
461 }
462 
463 static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp)
464 {
465     BlockCrypto *crypto = bs->opaque;
466     uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
467     bs->bl.request_alignment = sector_size; /* No sub-sector I/O */
468 }
469 
470 
471 static int64_t block_crypto_getlength(BlockDriverState *bs)
472 {
473     BlockCrypto *crypto = bs->opaque;
474     int64_t len = bdrv_getlength(bs->file->bs);
475 
476     uint64_t offset = qcrypto_block_get_payload_offset(crypto->block);
477     assert(offset < INT64_MAX);
478 
479     if (offset > len) {
480         return -EIO;
481     }
482 
483     len -= offset;
484 
485     return len;
486 }
487 
488 
489 static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts,
490                                               BlockDriverState *in_bs,
491                                               Error **errp)
492 {
493     g_autoptr(QCryptoBlockCreateOptions) create_opts = NULL;
494     Error *local_err = NULL;
495     BlockMeasureInfo *info;
496     uint64_t size;
497     size_t luks_payload_size;
498     QDict *cryptoopts;
499 
500     /*
501      * Preallocation mode doesn't affect size requirements but we must consume
502      * the option.
503      */
504     g_free(qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC));
505 
506     size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
507 
508     if (in_bs) {
509         int64_t ssize = bdrv_getlength(in_bs);
510 
511         if (ssize < 0) {
512             error_setg_errno(&local_err, -ssize,
513                              "Unable to get image virtual_size");
514             goto err;
515         }
516 
517         size = ssize;
518     }
519 
520     cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
521             &block_crypto_create_opts_luks, true);
522     qdict_put_str(cryptoopts, "format", "luks");
523     create_opts = block_crypto_create_opts_init(cryptoopts, &local_err);
524     qobject_unref(cryptoopts);
525     if (!create_opts) {
526         goto err;
527     }
528 
529     if (!qcrypto_block_calculate_payload_offset(create_opts, NULL,
530                                                 &luks_payload_size,
531                                                 &local_err)) {
532         goto err;
533     }
534 
535     /*
536      * Unallocated blocks are still encrypted so allocation status makes no
537      * difference to the file size.
538      */
539     info = g_new(BlockMeasureInfo, 1);
540     info->fully_allocated = luks_payload_size + size;
541     info->required = luks_payload_size + size;
542     return info;
543 
544 err:
545     error_propagate(errp, local_err);
546     return NULL;
547 }
548 
549 
550 static int block_crypto_probe_luks(const uint8_t *buf,
551                                    int buf_size,
552                                    const char *filename) {
553     return block_crypto_probe_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS,
554                                       buf, buf_size, filename);
555 }
556 
557 static int block_crypto_open_luks(BlockDriverState *bs,
558                                   QDict *options,
559                                   int flags,
560                                   Error **errp)
561 {
562     return block_crypto_open_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS,
563                                      &block_crypto_runtime_opts_luks,
564                                      bs, options, flags, errp);
565 }
566 
567 static int coroutine_fn
568 block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp)
569 {
570     BlockdevCreateOptionsLUKS *luks_opts;
571     BlockDriverState *bs = NULL;
572     QCryptoBlockCreateOptions create_opts;
573     PreallocMode preallocation = PREALLOC_MODE_OFF;
574     int ret;
575 
576     assert(create_options->driver == BLOCKDEV_DRIVER_LUKS);
577     luks_opts = &create_options->u.luks;
578 
579     bs = bdrv_open_blockdev_ref(luks_opts->file, errp);
580     if (bs == NULL) {
581         return -EIO;
582     }
583 
584     create_opts = (QCryptoBlockCreateOptions) {
585         .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
586         .u.luks = *qapi_BlockdevCreateOptionsLUKS_base(luks_opts),
587     };
588 
589     if (luks_opts->has_preallocation) {
590         preallocation = luks_opts->preallocation;
591     }
592 
593     ret = block_crypto_co_create_generic(bs, luks_opts->size, &create_opts,
594                                          preallocation, errp);
595     if (ret < 0) {
596         goto fail;
597     }
598 
599     ret = 0;
600 fail:
601     bdrv_unref(bs);
602     return ret;
603 }
604 
605 static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv,
606                                                          const char *filename,
607                                                          QemuOpts *opts,
608                                                          Error **errp)
609 {
610     QCryptoBlockCreateOptions *create_opts = NULL;
611     BlockDriverState *bs = NULL;
612     QDict *cryptoopts;
613     PreallocMode prealloc;
614     char *buf = NULL;
615     int64_t size;
616     int ret;
617     Error *local_err = NULL;
618 
619     /* Parse options */
620     size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
621 
622     buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
623     prealloc = qapi_enum_parse(&PreallocMode_lookup, buf,
624                                PREALLOC_MODE_OFF, &local_err);
625     g_free(buf);
626     if (local_err) {
627         error_propagate(errp, local_err);
628         return -EINVAL;
629     }
630 
631     cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
632                                              &block_crypto_create_opts_luks,
633                                              true);
634 
635     qdict_put_str(cryptoopts, "format", "luks");
636     create_opts = block_crypto_create_opts_init(cryptoopts, errp);
637     if (!create_opts) {
638         ret = -EINVAL;
639         goto fail;
640     }
641 
642     /* Create protocol layer */
643     ret = bdrv_create_file(filename, opts, errp);
644     if (ret < 0) {
645         goto fail;
646     }
647 
648     bs = bdrv_open(filename, NULL, NULL,
649                    BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp);
650     if (!bs) {
651         ret = -EINVAL;
652         goto fail;
653     }
654 
655     /* Create format layer */
656     ret = block_crypto_co_create_generic(bs, size, create_opts, prealloc, errp);
657     if (ret < 0) {
658         goto fail;
659     }
660 
661     ret = 0;
662 fail:
663     /*
664      * If an error occurred, delete 'filename'. Even if the file existed
665      * beforehand, it has been truncated and corrupted in the process.
666      */
667     if (ret && bs) {
668         Error *local_delete_err = NULL;
669         int r_del = bdrv_co_delete_file(bs, &local_delete_err);
670         /*
671          * ENOTSUP will happen if the block driver doesn't support
672          * the 'bdrv_co_delete_file' interface. This is a predictable
673          * scenario and shouldn't be reported back to the user.
674          */
675         if ((r_del < 0) && (r_del != -ENOTSUP)) {
676             error_report_err(local_delete_err);
677         }
678     }
679 
680     bdrv_unref(bs);
681     qapi_free_QCryptoBlockCreateOptions(create_opts);
682     qobject_unref(cryptoopts);
683     return ret;
684 }
685 
686 static int block_crypto_get_info_luks(BlockDriverState *bs,
687                                       BlockDriverInfo *bdi)
688 {
689     BlockDriverInfo subbdi;
690     int ret;
691 
692     ret = bdrv_get_info(bs->file->bs, &subbdi);
693     if (ret != 0) {
694         return ret;
695     }
696 
697     bdi->unallocated_blocks_are_zero = false;
698     bdi->cluster_size = subbdi.cluster_size;
699 
700     return 0;
701 }
702 
703 static ImageInfoSpecific *
704 block_crypto_get_specific_info_luks(BlockDriverState *bs, Error **errp)
705 {
706     BlockCrypto *crypto = bs->opaque;
707     ImageInfoSpecific *spec_info;
708     QCryptoBlockInfo *info;
709 
710     info = qcrypto_block_get_info(crypto->block, errp);
711     if (!info) {
712         return NULL;
713     }
714     assert(info->format == Q_CRYPTO_BLOCK_FORMAT_LUKS);
715 
716     spec_info = g_new(ImageInfoSpecific, 1);
717     spec_info->type = IMAGE_INFO_SPECIFIC_KIND_LUKS;
718     spec_info->u.luks.data = g_new(QCryptoBlockInfoLUKS, 1);
719     *spec_info->u.luks.data = info->u.luks;
720 
721     /* Blank out pointers we've just stolen to avoid double free */
722     memset(&info->u.luks, 0, sizeof(info->u.luks));
723 
724     qapi_free_QCryptoBlockInfo(info);
725 
726     return spec_info;
727 }
728 
729 static const char *const block_crypto_strong_runtime_opts[] = {
730     BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET,
731 
732     NULL
733 };
734 
735 static BlockDriver bdrv_crypto_luks = {
736     .format_name        = "luks",
737     .instance_size      = sizeof(BlockCrypto),
738     .bdrv_probe         = block_crypto_probe_luks,
739     .bdrv_open          = block_crypto_open_luks,
740     .bdrv_close         = block_crypto_close,
741     /* This driver doesn't modify LUKS metadata except when creating image.
742      * Allow share-rw=on as a special case. */
743     .bdrv_child_perm    = bdrv_filter_default_perms,
744     .bdrv_co_create     = block_crypto_co_create_luks,
745     .bdrv_co_create_opts = block_crypto_co_create_opts_luks,
746     .bdrv_co_truncate   = block_crypto_co_truncate,
747     .create_opts        = &block_crypto_create_opts_luks,
748 
749     .bdrv_reopen_prepare = block_crypto_reopen_prepare,
750     .bdrv_refresh_limits = block_crypto_refresh_limits,
751     .bdrv_co_preadv     = block_crypto_co_preadv,
752     .bdrv_co_pwritev    = block_crypto_co_pwritev,
753     .bdrv_getlength     = block_crypto_getlength,
754     .bdrv_measure       = block_crypto_measure,
755     .bdrv_get_info      = block_crypto_get_info_luks,
756     .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
757 
758     .strong_runtime_opts = block_crypto_strong_runtime_opts,
759 };
760 
761 static void block_crypto_init(void)
762 {
763     bdrv_register(&bdrv_crypto_luks);
764 }
765 
766 block_init(block_crypto_init);
767