"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/lib/utils_dm.h" (13 Jan 2022, 9870 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "utils_dm.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.3.6_vs_2.4.0.

    1 /*
    2  * libdevmapper - device-mapper backend for cryptsetup
    3  *
    4  * Copyright (C) 2004 Jana Saout <jana@saout.de>
    5  * Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
    6  * Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
    7  * Copyright (C) 2009-2021 Milan Broz
    8  *
    9  * This program is free software; you can redistribute it and/or
   10  * modify it under the terms of the GNU General Public License
   11  * as published by the Free Software Foundation; either version 2
   12  * of the License, or (at your option) any later version.
   13  *
   14  * This program is distributed in the hope that it will be useful,
   15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  * GNU General Public License for more details.
   18  *
   19  * You should have received a copy of the GNU General Public License
   20  * along with this program; if not, write to the Free Software
   21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   22  */
   23 
   24 #ifndef _UTILS_DM_H
   25 #define _UTILS_DM_H
   26 
   27 /* device-mapper library helpers */
   28 #include <stddef.h>
   29 #include <stdint.h>
   30 
   31 struct crypt_device;
   32 struct volume_key;
   33 struct crypt_params_verity;
   34 struct device;
   35 struct crypt_params_integrity;
   36 
   37 /* Device mapper internal flags */
   38 #define DM_RESUME_PRIVATE      (1 << 4) /* CRYPT_ACTIVATE_PRIVATE */
   39 #define DM_SUSPEND_SKIP_LOCKFS (1 << 5)
   40 #define DM_SUSPEND_WIPE_KEY    (1 << 6)
   41 #define DM_SUSPEND_NOFLUSH     (1 << 7)
   42 
   43 static inline uint32_t act2dmflags(uint32_t act_flags)
   44 {
   45     return (act_flags & DM_RESUME_PRIVATE);
   46 }
   47 
   48 /* Device mapper backend - kernel support flags */
   49 #define DM_KEY_WIPE_SUPPORTED (1 << 0)  /* key wipe message */
   50 #define DM_LMK_SUPPORTED      (1 << 1)  /* lmk mode */
   51 #define DM_SECURE_SUPPORTED   (1 << 2)  /* wipe (secure) buffer flag */
   52 #define DM_PLAIN64_SUPPORTED  (1 << 3)  /* plain64 IV */
   53 #define DM_DISCARDS_SUPPORTED (1 << 4)  /* discards/TRIM option is supported */
   54 #define DM_VERITY_SUPPORTED   (1 << 5)  /* dm-verity target supported */
   55 #define DM_TCW_SUPPORTED      (1 << 6)  /* tcw (TCRYPT CBC with whitening) */
   56 #define DM_SAME_CPU_CRYPT_SUPPORTED (1 << 7) /* same_cpu_crypt */
   57 #define DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED (1 << 8) /* submit_from_crypt_cpus */
   58 #define DM_VERITY_ON_CORRUPTION_SUPPORTED (1 << 9) /* ignore/restart_on_corruption, ignore_zero_block */
   59 #define DM_VERITY_FEC_SUPPORTED (1 << 10) /* Forward Error Correction (FEC) */
   60 #define DM_KERNEL_KEYRING_SUPPORTED (1 << 11) /* dm-crypt allows loading kernel keyring keys */
   61 #define DM_INTEGRITY_SUPPORTED (1 << 12) /* dm-integrity target supported */
   62 #define DM_SECTOR_SIZE_SUPPORTED (1 << 13) /* support for sector size setting in dm-crypt/dm-integrity */
   63 #define DM_CAPI_STRING_SUPPORTED (1 << 14) /* support for cryptoapi format cipher definition */
   64 #define DM_DEFERRED_SUPPORTED (1 << 15) /* deferred removal of device */
   65 #define DM_INTEGRITY_RECALC_SUPPORTED (1 << 16) /* dm-integrity automatic recalculation supported */
   66 #define DM_INTEGRITY_BITMAP_SUPPORTED (1 << 17) /* dm-integrity bitmap mode supported */
   67 #define DM_GET_TARGET_VERSION_SUPPORTED (1 << 18) /* dm DM_GET_TARGET version ioctl supported */
   68 #define DM_INTEGRITY_FIX_PADDING_SUPPORTED (1 << 19) /* supports the parameter fix_padding that fixes a bug that caused excessive padding */
   69 #define DM_BITLK_EBOIV_SUPPORTED (1 << 20) /* EBOIV for BITLK supported */
   70 #define DM_BITLK_ELEPHANT_SUPPORTED (1 << 21) /* Elephant diffuser for BITLK supported */
   71 #define DM_VERITY_SIGNATURE_SUPPORTED (1 << 22) /* Verity option root_hash_sig_key_desc supported */
   72 #define DM_INTEGRITY_DISCARDS_SUPPORTED (1 << 23) /* dm-integrity discards/TRIM option is supported */
   73 #define DM_VERITY_PANIC_CORRUPTION_SUPPORTED (1 << 24) /* dm-verity panic on corruption  */
   74 #define DM_CRYPT_NO_WORKQUEUE_SUPPORTED (1 << 25) /* dm-crypt suppot for bypassing workqueues  */
   75 #define DM_INTEGRITY_FIX_HMAC_SUPPORTED (1 << 26) /* hmac covers also superblock */
   76 #define DM_INTEGRITY_RESET_RECALC_SUPPORTED (1 << 27) /* dm-integrity automatic recalculation supported */
   77 
   78 typedef enum { DM_CRYPT = 0, DM_VERITY, DM_INTEGRITY, DM_LINEAR, DM_ERROR, DM_ZERO, DM_UNKNOWN } dm_target_type;
   79 enum tdirection { TARGET_SET = 1, TARGET_QUERY };
   80 
   81 int dm_flags(struct crypt_device *cd, dm_target_type target, uint32_t *flags);
   82 
   83 #define DM_ACTIVE_DEVICE    (1 << 0)
   84 #define DM_ACTIVE_UUID      (1 << 1)
   85 #define DM_ACTIVE_HOLDERS   (1 << 2)
   86 
   87 #define DM_ACTIVE_CRYPT_CIPHER  (1 << 3)
   88 #define DM_ACTIVE_CRYPT_KEYSIZE (1 << 4)
   89 #define DM_ACTIVE_CRYPT_KEY (1 << 5)
   90 
   91 #define DM_ACTIVE_VERITY_ROOT_HASH  (1 << 6)
   92 #define DM_ACTIVE_VERITY_HASH_DEVICE    (1 << 7)
   93 #define DM_ACTIVE_VERITY_PARAMS     (1 << 8)
   94 
   95 #define DM_ACTIVE_INTEGRITY_PARAMS  (1 << 9)
   96 
   97 struct dm_target {
   98     dm_target_type type;
   99     enum tdirection direction;
  100     uint64_t offset;
  101     uint64_t size;
  102     struct device *data_device;
  103     union {
  104     struct {
  105         const char *cipher;
  106         const char *integrity;
  107 
  108         /* Active key for device */
  109         struct volume_key *vk;
  110 
  111         /* struct crypt_active_device */
  112         uint64_t offset;    /* offset in sectors */
  113         uint64_t iv_offset; /* IV initialisation sector */
  114         uint32_t tag_size;  /* additional on-disk tag size */
  115         uint32_t sector_size;   /* encryption sector size */
  116     } crypt;
  117     struct {
  118         struct device *hash_device;
  119         struct device *fec_device;
  120 
  121         const char *root_hash;
  122         uint32_t root_hash_size;
  123         const char *root_hash_sig_key_desc;
  124 
  125         uint64_t hash_offset;   /* hash offset in blocks (not header) */
  126         uint64_t fec_offset;    /* FEC offset in blocks (not header) */
  127         uint64_t fec_blocks;    /* FEC blocks covering data + hash + padding (foreign metadata)*/
  128         struct crypt_params_verity *vp;
  129     } verity;
  130     struct {
  131         uint64_t journal_size;
  132         uint32_t journal_watermark;
  133         uint32_t journal_commit_time;
  134         uint32_t interleave_sectors;
  135         uint32_t tag_size;
  136         uint64_t offset;    /* offset in sectors */
  137         uint32_t sector_size;   /* integrity sector size */
  138         uint32_t buffer_sectors;
  139 
  140         const char *integrity;
  141         /* Active key for device */
  142         struct volume_key *vk;
  143 
  144         const char *journal_integrity;
  145         struct volume_key *journal_integrity_key;
  146 
  147         const char *journal_crypt;
  148         struct volume_key *journal_crypt_key;
  149 
  150         struct device *meta_device;
  151 
  152         bool fix_padding;
  153         bool fix_hmac;
  154         bool legacy_recalc;
  155     } integrity;
  156     struct {
  157         uint64_t offset;
  158     } linear;
  159     struct {
  160     } zero;
  161     } u;
  162 
  163     char *params;
  164     struct dm_target *next;
  165 };
  166 
  167 struct crypt_dm_active_device {
  168     uint64_t size;      /* active device size */
  169     uint32_t flags;     /* activation flags */
  170     const char *uuid;
  171 
  172     unsigned holders:1; /* device holders detected (on query only) */
  173 
  174     struct dm_target segment;
  175 };
  176 
  177 static inline bool single_segment(const struct crypt_dm_active_device *dmd)
  178 {
  179     return dmd && !dmd->segment.next;
  180 }
  181 
  182 void dm_backend_init(struct crypt_device *cd);
  183 void dm_backend_exit(struct crypt_device *cd);
  184 
  185 int dm_targets_allocate(struct dm_target *first, unsigned count);
  186 void dm_targets_free(struct crypt_device *cd, struct crypt_dm_active_device *dmd);
  187 
  188 int dm_crypt_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg_size,
  189     struct device *data_device, struct volume_key *vk, const char *cipher,
  190     uint64_t iv_offset, uint64_t data_offset, const char *integrity,
  191     uint32_t tag_size, uint32_t sector_size);
  192 int dm_verity_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg_size,
  193     struct device *data_device, struct device *hash_device, struct device *fec_device,
  194     const char *root_hash, uint32_t root_hash_size, const char* root_hash_sig_key_desc,
  195     uint64_t hash_offset_block, uint64_t fec_blocks, struct crypt_params_verity *vp);
  196 int dm_integrity_target_set(struct crypt_device *cd,
  197     struct dm_target *tgt, uint64_t seg_offset, uint64_t seg_size,
  198     struct device *meta_device,
  199     struct device *data_device, uint64_t tag_size, uint64_t offset, uint32_t sector_size,
  200     struct volume_key *vk,
  201     struct volume_key *journal_crypt_key, struct volume_key *journal_mac_key,
  202     const struct crypt_params_integrity *ip);
  203 int dm_linear_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg_size,
  204     struct device *data_device, uint64_t data_offset);
  205 int dm_zero_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg_size);
  206 
  207 int dm_remove_device(struct crypt_device *cd, const char *name, uint32_t flags);
  208 int dm_status_device(struct crypt_device *cd, const char *name);
  209 int dm_status_suspended(struct crypt_device *cd, const char *name);
  210 int dm_status_verity_ok(struct crypt_device *cd, const char *name);
  211 int dm_status_integrity_failures(struct crypt_device *cd, const char *name, uint64_t *count);
  212 int dm_query_device(struct crypt_device *cd, const char *name,
  213             uint32_t get_flags, struct crypt_dm_active_device *dmd);
  214 int dm_device_deps(struct crypt_device *cd, const char *name, const char *prefix,
  215            char **names, size_t names_length);
  216 int dm_create_device(struct crypt_device *cd, const char *name,
  217              const char *type, struct crypt_dm_active_device *dmd);
  218 int dm_reload_device(struct crypt_device *cd, const char *name,
  219              struct crypt_dm_active_device *dmd, uint32_t dmflags, unsigned resume);
  220 int dm_suspend_device(struct crypt_device *cd, const char *name, uint32_t dmflags);
  221 int dm_resume_device(struct crypt_device *cd, const char *name, uint32_t dmflags);
  222 int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
  223                 const struct volume_key *vk);
  224 int dm_error_device(struct crypt_device *cd, const char *name);
  225 int dm_clear_device(struct crypt_device *cd, const char *name);
  226 int dm_cancel_deferred_removal(const char *name);
  227 
  228 const char *dm_get_dir(void);
  229 
  230 int lookup_dm_dev_by_uuid(struct crypt_device *cd, const char *uuid, const char *type);
  231 
  232 /* These are DM helpers used only by utils_devpath file */
  233 int dm_is_dm_device(int major);
  234 int dm_is_dm_kernel_name(const char *name);
  235 char *dm_device_path(const char *prefix, int major, int minor);
  236 char *dm_device_name(const char *path);
  237 
  238 #endif /* _UTILS_DM_H */