ANDROID: block: Prevent crypto fallback for wrapped keys

blk-crypto-fallback does not support wrapped keys, hence
prevent falling back when program_key fails. Add 'is_hw_wrapped'
flag to blk-crypto-key to mention if the key is wrapped
when the key is initialized.

Bug: 147209885

Test: Validate FBE, simulate a failure in the underlying blk
      device and ensure the call fails without falling back
      to blk-crypto-fallback.

Change-Id: I8bc301ca1ac9e55ba6ab622e8325486916b45c56
Signed-off-by: Barani Muthukumaran <bmuthuku@codeaurora.org>
This commit is contained in:
Barani Muthukumaran 2020-02-06 18:01:20 -08:00 committed by Todd Kjos
parent 50d5ac3d7c
commit 3ab1972984
10 changed files with 89 additions and 63 deletions

View File

@ -39913,6 +39913,11 @@
<class-decl name='gpio_desc' size-in-bits='256' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-3087'/>
<class-decl name='regulator' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-4403'/>
<class-decl name='reset_control' size-in-bits='384' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-4404'/>
<union-decl name='phy_configure_opts' size-in-bits='896' visibility='default' filepath='include/linux/phy/phy.h' line='50' column='1' id='type-id-4405'>
<data-member access='private'>
<var-decl name='mipi_dphy' type-id='type-id-4406' visibility='default' filepath='include/linux/phy/phy.h' line='51' column='1'/>
</data-member>
</union-decl>
<enum-decl name='gpiod_flags' filepath='include/linux/gpio/consumer.h' line='48' column='1' id='type-id-2070'>
<underlying-type type-id='type-id-113'/>
<enumerator name='GPIOD_ASIS' value='0'/>
@ -39922,7 +39927,7 @@
<enumerator name='GPIOD_OUT_LOW_OPEN_DRAIN' value='11'/>
<enumerator name='GPIOD_OUT_HIGH_OPEN_DRAIN' value='15'/>
</enum-decl>
<class-decl name='phy' size-in-bits='6720' is-struct='yes' visibility='default' filepath='include/linux/phy/phy.h' line='130' column='1' id='type-id-4405'>
<class-decl name='phy' size-in-bits='6720' is-struct='yes' visibility='default' filepath='include/linux/phy/phy.h' line='130' column='1' id='type-id-4407'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='dev' type-id='type-id-719' visibility='default' filepath='include/linux/phy/phy.h' line='131' column='1'/>
</data-member>
@ -39930,7 +39935,7 @@
<var-decl name='id' type-id='type-id-92' visibility='default' filepath='include/linux/phy/phy.h' line='132' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='6208'>
<var-decl name='ops' type-id='type-id-4406' visibility='default' filepath='include/linux/phy/phy.h' line='133' column='1'/>
<var-decl name='ops' type-id='type-id-4408' visibility='default' filepath='include/linux/phy/phy.h' line='133' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='6272'>
<var-decl name='mutex' type-id='type-id-186' visibility='default' filepath='include/linux/phy/phy.h' line='134' column='1'/>
@ -39942,48 +39947,48 @@
<var-decl name='power_count' type-id='type-id-92' visibility='default' filepath='include/linux/phy/phy.h' line='136' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='6592'>
<var-decl name='attrs' type-id='type-id-4407' visibility='default' filepath='include/linux/phy/phy.h' line='137' column='1'/>
<var-decl name='attrs' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='137' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='6656'>
<var-decl name='pwr' type-id='type-id-3454' visibility='default' filepath='include/linux/phy/phy.h' line='138' column='1'/>
</data-member>
</class-decl>
<class-decl name='phy_ops' size-in-bits='704' is-struct='yes' visibility='default' filepath='include/linux/phy/phy.h' line='66' column='1' id='type-id-4408'>
<class-decl name='phy_ops' size-in-bits='704' is-struct='yes' visibility='default' filepath='include/linux/phy/phy.h' line='66' column='1' id='type-id-4410'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='init' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='67' column='1'/>
<var-decl name='init' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='67' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='64'>
<var-decl name='exit' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='68' column='1'/>
<var-decl name='exit' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='68' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='128'>
<var-decl name='power_on' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='69' column='1'/>
<var-decl name='power_on' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='69' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='192'>
<var-decl name='power_off' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='70' column='1'/>
<var-decl name='power_off' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='70' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='256'>
<var-decl name='set_mode' type-id='type-id-4410' visibility='default' filepath='include/linux/phy/phy.h' line='71' column='1'/>
<var-decl name='set_mode' type-id='type-id-4412' visibility='default' filepath='include/linux/phy/phy.h' line='71' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='320'>
<var-decl name='configure' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='83' column='1'/>
<var-decl name='configure' type-id='type-id-4413' visibility='default' filepath='include/linux/phy/phy.h' line='83' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='384'>
<var-decl name='validate' type-id='type-id-4412' visibility='default' filepath='include/linux/phy/phy.h' line='101' column='1'/>
<var-decl name='validate' type-id='type-id-4414' visibility='default' filepath='include/linux/phy/phy.h' line='101' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='448'>
<var-decl name='reset' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='103' column='1'/>
<var-decl name='reset' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='103' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='512'>
<var-decl name='calibrate' type-id='type-id-4409' visibility='default' filepath='include/linux/phy/phy.h' line='104' column='1'/>
<var-decl name='calibrate' type-id='type-id-4411' visibility='default' filepath='include/linux/phy/phy.h' line='104' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='576'>
<var-decl name='release' type-id='type-id-4413' visibility='default' filepath='include/linux/phy/phy.h' line='105' column='1'/>
<var-decl name='release' type-id='type-id-4415' visibility='default' filepath='include/linux/phy/phy.h' line='105' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='640'>
<var-decl name='owner' type-id='type-id-2440' visibility='default' filepath='include/linux/phy/phy.h' line='106' column='1'/>
</data-member>
</class-decl>
<enum-decl name='phy_mode' filepath='include/linux/phy/phy.h' line='23' column='1' id='type-id-4414'>
<enum-decl name='phy_mode' filepath='include/linux/phy/phy.h' line='23' column='1' id='type-id-4416'>
<underlying-type type-id='type-id-113'/>
<enumerator name='PHY_MODE_INVALID' value='0'/>
<enumerator name='PHY_MODE_USB_HOST' value='1'/>
@ -40004,7 +40009,7 @@
<enumerator name='PHY_MODE_MIPI_DPHY' value='16'/>
<enumerator name='PHY_MODE_SATA' value='17'/>
</enum-decl>
<class-decl name='phy_configure_opts_mipi_dphy' size-in-bits='896' is-struct='yes' visibility='default' filepath='include/linux/phy/phy-mipi-dphy.h' line='15' column='1' id='type-id-4415'>
<class-decl name='phy_configure_opts_mipi_dphy' size-in-bits='896' is-struct='yes' visibility='default' filepath='include/linux/phy/phy-mipi-dphy.h' line='15' column='1' id='type-id-4406'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='clk_miss' type-id='type-id-135' visibility='default' filepath='include/linux/phy/phy-mipi-dphy.h' line='24' column='1'/>
</data-member>
@ -40081,17 +40086,12 @@
<var-decl name='lanes' type-id='type-id-115' visibility='default' filepath='include/linux/phy/phy-mipi-dphy.h' line='275' column='1'/>
</data-member>
</class-decl>
<union-decl name='phy_configure_opts' size-in-bits='896' visibility='default' filepath='include/linux/phy/phy.h' line='50' column='1' id='type-id-4416'>
<data-member access='private'>
<var-decl name='mipi_dphy' type-id='type-id-4415' visibility='default' filepath='include/linux/phy/phy.h' line='51' column='1'/>
</data-member>
</union-decl>
<class-decl name='phy_attrs' size-in-bits='64' is-struct='yes' visibility='default' filepath='include/linux/phy/phy.h' line='114' column='1' id='type-id-4407'>
<class-decl name='phy_attrs' size-in-bits='64' is-struct='yes' visibility='default' filepath='include/linux/phy/phy.h' line='114' column='1' id='type-id-4409'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='bus_width' type-id='type-id-134' visibility='default' filepath='include/linux/phy/phy.h' line='115' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='32'>
<var-decl name='mode' type-id='type-id-4414' visibility='default' filepath='include/linux/phy/phy.h' line='116' column='1'/>
<var-decl name='mode' type-id='type-id-4416' visibility='default' filepath='include/linux/phy/phy.h' line='116' column='1'/>
</data-member>
</class-decl>
<class-decl name='regulator_bulk_data' size-in-bits='192' is-struct='yes' visibility='default' filepath='include/linux/regulator/consumer.h' line='167' column='1' id='type-id-4417'>
@ -40116,19 +40116,19 @@
<pointer-type-def type-id='type-id-4418' size-in-bits='64' id='type-id-3158'/>
<qualified-type-def type-id='type-id-4418' const='yes' id='type-id-4419'/>
<pointer-type-def type-id='type-id-4419' size-in-bits='64' id='type-id-4420'/>
<qualified-type-def type-id='type-id-4408' const='yes' id='type-id-4421'/>
<pointer-type-def type-id='type-id-4421' size-in-bits='64' id='type-id-4406'/>
<qualified-type-def type-id='type-id-4410' const='yes' id='type-id-4421'/>
<pointer-type-def type-id='type-id-4421' size-in-bits='64' id='type-id-4408'/>
<pointer-type-def type-id='type-id-3087' size-in-bits='64' id='type-id-1773'/>
<pointer-type-def type-id='type-id-4422' size-in-bits='64' id='type-id-4409'/>
<pointer-type-def type-id='type-id-4423' size-in-bits='64' id='type-id-4410'/>
<pointer-type-def type-id='type-id-4424' size-in-bits='64' id='type-id-4412'/>
<pointer-type-def type-id='type-id-4425' size-in-bits='64' id='type-id-4411'/>
<pointer-type-def type-id='type-id-4405' size-in-bits='64' id='type-id-4426'/>
<pointer-type-def type-id='type-id-4416' size-in-bits='64' id='type-id-4427'/>
<pointer-type-def type-id='type-id-4422' size-in-bits='64' id='type-id-4411'/>
<pointer-type-def type-id='type-id-4423' size-in-bits='64' id='type-id-4412'/>
<pointer-type-def type-id='type-id-4424' size-in-bits='64' id='type-id-4414'/>
<pointer-type-def type-id='type-id-4425' size-in-bits='64' id='type-id-4413'/>
<pointer-type-def type-id='type-id-4407' size-in-bits='64' id='type-id-4426'/>
<pointer-type-def type-id='type-id-4405' size-in-bits='64' id='type-id-4427'/>
<pointer-type-def type-id='type-id-4403' size-in-bits='64' id='type-id-3454'/>
<pointer-type-def type-id='type-id-4417' size-in-bits='64' id='type-id-4428'/>
<pointer-type-def type-id='type-id-4404' size-in-bits='64' id='type-id-3594'/>
<pointer-type-def type-id='type-id-4429' size-in-bits='64' id='type-id-4413'/>
<pointer-type-def type-id='type-id-4429' size-in-bits='64' id='type-id-4415'/>
<function-decl name='pm_runtime_enable' mangled-name='pm_runtime_enable' filepath='include/linux/pm_runtime.h' line='45' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='pm_runtime_enable'>
<parameter type-id='type-id-729'/>
<return type-id='type-id-686'/>
@ -40250,13 +40250,13 @@
</function-type>
<function-type size-in-bits='64' id='type-id-4423'>
<parameter type-id='type-id-4426'/>
<parameter type-id='type-id-4414'/>
<parameter type-id='type-id-4416'/>
<parameter type-id='type-id-92'/>
<return type-id='type-id-92'/>
</function-type>
<function-type size-in-bits='64' id='type-id-4424'>
<parameter type-id='type-id-4426'/>
<parameter type-id='type-id-4414'/>
<parameter type-id='type-id-4416'/>
<parameter type-id='type-id-92'/>
<parameter type-id='type-id-4427'/>
<return type-id='type-id-92'/>
@ -40567,7 +40567,7 @@
</function-decl>
<function-decl name='phy_set_mode_ext' mangled-name='phy_set_mode_ext' filepath='drivers/phy/phy-core.c' line='359' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='phy_set_mode_ext'>
<parameter type-id='type-id-4426' name='phy' filepath='drivers/phy/phy-core.c' line='359' column='1'/>
<parameter type-id='type-id-4414' name='mode' filepath='drivers/phy/phy-core.c' line='359' column='1'/>
<parameter type-id='type-id-4416' name='mode' filepath='drivers/phy/phy-core.c' line='359' column='1'/>
<parameter type-id='type-id-92' name='submode' filepath='drivers/phy/phy-core.c' line='359' column='1'/>
<return type-id='type-id-92'/>
</function-decl>
@ -40584,7 +40584,7 @@
<function-decl name='devm_phy_create' mangled-name='devm_phy_create' filepath='drivers/phy/phy-core.c' line='910' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='devm_phy_create'>
<parameter type-id='type-id-729' name='dev' filepath='drivers/phy/phy-core.c' line='910' column='1'/>
<parameter type-id='type-id-1703' name='node' filepath='drivers/phy/phy-core.c' line='910' column='1'/>
<parameter type-id='type-id-4406' name='ops' filepath='drivers/phy/phy-core.c' line='911' column='1'/>
<parameter type-id='type-id-4408' name='ops' filepath='drivers/phy/phy-core.c' line='911' column='1'/>
<return type-id='type-id-4426'/>
</function-decl>
<function-decl name='__devm_of_phy_provider_register' mangled-name='__devm_of_phy_provider_register' filepath='drivers/phy/phy-core.c' line='1041' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='__devm_of_phy_provider_register'>
@ -56178,7 +56178,7 @@
<class-decl name='fsverity_operations' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6066'/>
<class-decl name='hd_geometry' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6067'/>
<class-decl name='iommu_fwspec' size-in-bits='320' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6068'/>
<class-decl name='iommu_group' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6069'/>
<class-decl name='iommu_group' size-in-bits='1728' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6069'/>
<class-decl name='iommu_ops' size-in-bits='2304' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6070'/>
<class-decl name='iommu_param' size-in-bits='320' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6071'/>
<class-decl name='irq_domain' is-struct='yes' visibility='default' is-declaration-only='yes' id='type-id-6072'/>
@ -61905,38 +61905,41 @@
<var-decl name='value' type-id='type-id-271' visibility='default' filepath='include/linux/blk_types.h' line='114' column='1'/>
</data-member>
</class-decl>
<class-decl name='bio_crypt_ctx' size-in-bits='448' is-struct='yes' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='64' column='1' id='type-id-6623'>
<class-decl name='bio_crypt_ctx' size-in-bits='448' is-struct='yes' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='67' column='1' id='type-id-6623'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='bc_key' type-id='type-id-4973' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='65' column='1'/>
<var-decl name='bc_key' type-id='type-id-4973' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='68' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='64'>
<var-decl name='bc_keyslot' type-id='type-id-92' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='66' column='1'/>
<var-decl name='bc_keyslot' type-id='type-id-92' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='69' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='128'>
<var-decl name='bc_dun' type-id='type-id-6145' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='69' column='1'/>
<var-decl name='bc_dun' type-id='type-id-6145' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='72' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='384'>
<var-decl name='bc_ksm' type-id='type-id-4821' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='75' column='1'/>
<var-decl name='bc_ksm' type-id='type-id-4821' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='78' column='1'/>
</data-member>
</class-decl>
<class-decl name='blk_crypto_key' size-in-bits='1184' is-struct='yes' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='39' column='1' id='type-id-6624'>
<class-decl name='blk_crypto_key' size-in-bits='1216' is-struct='yes' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='41' column='1' id='type-id-6624'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='crypto_mode' type-id='type-id-6625' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='40' column='1'/>
<var-decl name='crypto_mode' type-id='type-id-6625' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='42' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='32'>
<var-decl name='data_unit_size' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='41' column='1'/>
<var-decl name='data_unit_size' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='43' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='64'>
<var-decl name='data_unit_size_bits' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='42' column='1'/>
<var-decl name='data_unit_size_bits' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='44' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='96'>
<var-decl name='size' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='43' column='1'/>
<var-decl name='size' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='45' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='128'>
<var-decl name='hash' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='44' column='1'/>
<var-decl name='hash' type-id='type-id-135' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='46' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='160'>
<var-decl name='raw' type-id='type-id-6148' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='45' column='1'/>
<var-decl name='is_hw_wrapped' type-id='type-id-188' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='47' column='1'/>
</data-member>
<data-member access='public' layout-offset-in-bits='168'>
<var-decl name='raw' type-id='type-id-6148' visibility='default' filepath='include/linux/bio-crypt-ctx.h' line='48' column='1'/>
</data-member>
</class-decl>
<enum-decl name='blk_crypto_mode_num' filepath='include/linux/bio-crypt-ctx.h' line='8' column='1' id='type-id-6625'>

View File

@ -572,6 +572,12 @@ int blk_crypto_fallback_submit_bio(struct bio **bio_ptr)
struct bio_crypt_ctx *bc = bio->bi_crypt_context;
struct bio_fallback_crypt_ctx *f_ctx;
if (bc->bc_key->is_hw_wrapped) {
pr_warn_once("HW wrapped key cannot be used with fallback.\n");
bio->bi_status = BLK_STS_NOTSUPP;
return -EOPNOTSUPP;
}
if (!tfms_inited[bc->bc_key->crypto_mode]) {
bio->bi_status = BLK_STS_IOERR;
return -EIO;

View File

@ -175,7 +175,9 @@ bool blk_crypto_endio(struct bio *bio)
* @raw_key_size: Size of raw key. Must be at least the required size for the
* chosen @crypto_mode; see blk_crypto_modes[]. (It's allowed
* to be longer than the mode's actual key size, in order to
* support inline encryption hardware that accepts wrapped keys.)
* support inline encryption hardware that accepts wrapped keys.
* @is_hw_wrapped has to be set for such keys)
* @is_hw_wrapped: Denotes @raw_key is wrapped.
* @crypto_mode: identifier for the encryption algorithm to use
* @data_unit_size: the data unit size to use for en/decryption
*
@ -184,6 +186,7 @@ bool blk_crypto_endio(struct bio *bio)
*/
int blk_crypto_init_key(struct blk_crypto_key *blk_key,
const u8 *raw_key, unsigned int raw_key_size,
bool is_hw_wrapped,
enum blk_crypto_mode_num crypto_mode,
unsigned int data_unit_size)
{
@ -198,9 +201,14 @@ int blk_crypto_init_key(struct blk_crypto_key *blk_key,
BUILD_BUG_ON(BLK_CRYPTO_MAX_WRAPPED_KEY_SIZE < BLK_CRYPTO_MAX_KEY_SIZE);
mode = &blk_crypto_modes[crypto_mode];
if (raw_key_size < mode->keysize ||
raw_key_size > BLK_CRYPTO_MAX_WRAPPED_KEY_SIZE)
return -EINVAL;
if (is_hw_wrapped) {
if (raw_key_size < mode->keysize ||
raw_key_size > BLK_CRYPTO_MAX_WRAPPED_KEY_SIZE)
return -EINVAL;
} else {
if (raw_key_size != mode->keysize)
return -EINVAL;
}
if (!is_power_of_2(data_unit_size))
return -EINVAL;
@ -209,6 +217,7 @@ int blk_crypto_init_key(struct blk_crypto_key *blk_key,
blk_key->data_unit_size = data_unit_size;
blk_key->data_unit_size_bits = ilog2(data_unit_size);
blk_key->size = raw_key_size;
blk_key->is_hw_wrapped = is_hw_wrapped;
memcpy(blk_key->raw, raw_key, raw_key_size);
/*

View File

@ -224,7 +224,7 @@ static int default_key_ctr(struct dm_target *ti, unsigned int argc, char **argv)
}
err = blk_crypto_init_key(&dkc->key, raw_key, cipher->key_size,
cipher->mode_num, dkc->sector_size);
false, cipher->mode_num, dkc->sector_size);
if (err) {
ti->error = "Error initializing blk-crypto key";
goto bad;

View File

@ -318,6 +318,7 @@ extern int fscrypt_prepare_inline_crypt_key(
struct fscrypt_prepared_key *prep_key,
const u8 *raw_key,
unsigned int raw_key_size,
bool is_hw_wrapped,
const struct fscrypt_info *ci);
extern void fscrypt_destroy_inline_crypt_key(
@ -362,6 +363,7 @@ static inline bool fscrypt_using_inline_encryption(
static inline int
fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key, unsigned int raw_key_size,
bool is_hw_wrapped,
const struct fscrypt_info *ci)
{
WARN_ON(1);
@ -556,6 +558,7 @@ extern struct fscrypt_mode fscrypt_modes[];
extern int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key, unsigned int raw_key_size,
bool is_hw_wrapped,
const struct fscrypt_info *ci);
extern void fscrypt_destroy_prepared_key(struct fscrypt_prepared_key *prep_key);

View File

@ -50,6 +50,7 @@ void fscrypt_select_encryption_impl(struct fscrypt_info *ci)
int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key,
unsigned int raw_key_size,
bool is_hw_wrapped,
const struct fscrypt_info *ci)
{
const struct inode *inode = ci->ci_inode;
@ -80,7 +81,7 @@ int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key,
BLK_CRYPTO_MAX_WRAPPED_KEY_SIZE);
err = blk_crypto_init_key(&blk_key->base, raw_key, raw_key_size,
crypto_mode, sb->s_blocksize);
is_hw_wrapped, crypto_mode, sb->s_blocksize);
if (err) {
fscrypt_err(inode, "error %d initializing blk-crypto key", err);
goto fail;

View File

@ -117,15 +117,15 @@ fscrypt_allocate_skcipher(struct fscrypt_mode *mode, const u8 *raw_key,
*/
int fscrypt_prepare_key(struct fscrypt_prepared_key *prep_key,
const u8 *raw_key, unsigned int raw_key_size,
const struct fscrypt_info *ci)
bool is_hw_wrapped, const struct fscrypt_info *ci)
{
struct crypto_skcipher *tfm;
if (fscrypt_using_inline_encryption(ci))
return fscrypt_prepare_inline_crypt_key(prep_key,
raw_key, raw_key_size, ci);
raw_key, raw_key_size, is_hw_wrapped, ci);
if (WARN_ON(raw_key_size != ci->ci_mode->keysize))
if (WARN_ON(is_hw_wrapped || raw_key_size != ci->ci_mode->keysize))
return -EINVAL;
tfm = fscrypt_allocate_skcipher(ci->ci_mode, raw_key, ci->ci_inode);
@ -150,8 +150,8 @@ void fscrypt_destroy_prepared_key(struct fscrypt_prepared_key *prep_key)
int fscrypt_set_per_file_enc_key(struct fscrypt_info *ci, const u8 *raw_key)
{
ci->ci_owns_key = true;
return fscrypt_prepare_key(&ci->ci_key, raw_key,
ci->ci_mode->keysize, ci);
return fscrypt_prepare_key(&ci->ci_key, raw_key, ci->ci_mode->keysize,
false /*is_hw_wrapped*/, ci);
}
static int setup_per_mode_enc_key(struct fscrypt_info *ci,
@ -202,7 +202,7 @@ static int setup_per_mode_enc_key(struct fscrypt_info *ci,
}
}
err = fscrypt_prepare_key(prep_key, mk->mk_secret.raw,
mk->mk_secret.size, ci);
mk->mk_secret.size, true, ci);
if (err)
goto out_unlock;
} else {
@ -221,7 +221,7 @@ static int setup_per_mode_enc_key(struct fscrypt_info *ci,
if (err)
goto out_unlock;
err = fscrypt_prepare_key(prep_key, mode_key, mode->keysize,
ci);
false /*is_hw_wrapped*/, ci);
memzero_explicit(mode_key, mode->keysize);
if (err)
goto out_unlock;

View File

@ -234,7 +234,7 @@ fscrypt_get_direct_key(const struct fscrypt_info *ci, const u8 *raw_key)
refcount_set(&dk->dk_refcount, 1);
dk->dk_mode = ci->ci_mode;
err = fscrypt_prepare_key(&dk->dk_key, raw_key, ci->ci_mode->keysize,
ci);
false /*is_hw_wrapped*/, ci);
if (err)
goto err_free_dk;
memcpy(dk->dk_descriptor, ci->ci_policy.v1.master_key_descriptor,

View File

@ -31,6 +31,8 @@ enum blk_crypto_mode_num {
* @data_unit_size_bits: log2 of data_unit_size
* @size: size of this key in bytes (determined by @crypto_mode)
* @hash: hash of this key, for keyslot manager use only
* @is_hw_wrapped: @raw points to a wrapped key to be used by an inline
* encryption hardware that accepts wrapped keys.
* @raw: the raw bytes of this key. Only the first @size bytes are used.
*
* A blk_crypto_key is immutable once created, and many bios can reference it at
@ -42,6 +44,7 @@ struct blk_crypto_key {
unsigned int data_unit_size_bits;
unsigned int size;
unsigned int hash;
bool is_hw_wrapped;
u8 raw[BLK_CRYPTO_MAX_WRAPPED_KEY_SIZE];
};

View File

@ -16,6 +16,7 @@ bool blk_crypto_endio(struct bio *bio);
int blk_crypto_init_key(struct blk_crypto_key *blk_key,
const u8 *raw_key, unsigned int raw_key_size,
bool is_hw_wrapped,
enum blk_crypto_mode_num crypto_mode,
unsigned int data_unit_size);