dm-crypt: support using encrypted keys
PATCH 1/1 dm-crypt: support using encrypted keys
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
--- drivers/md/dm-crypt.c | 66 ++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-)
drivers/md/dm-crypt.c +50 -16
@@ -34,7 +34,9 @@#include <crypto/aead.h> #include <crypto/authenc.h> #include <linux/rtnetlink.h> /* for struct rtattr and RTA macros only */ +#include <linux/key-type.h> #include <keys/user-type.h> +#include <keys/encrypted-type.h> #include <linux/device-mapper.h>
@@ -2215,12 +2217,44 @@ static bool contains_whitespace(const char *str)return false; } +static int set_key_user (struct crypt_config *cc,struct key *key) +{ +const struct user_key_payload *ukp; + + ukp =user_key_payload_locked (key); +if (!ukp) +return -EKEYREVOKED ; + +if (cc->key_size != ukp->datalen) +return -EINVAL ; + +memcpy (cc->key, ukp->data, cc->key_size); + +return 0 ; +} + +static int set_key_encrypted (struct crypt_config *cc,struct key *key) +{ +struct encrypted_key_payload *ekp = key->payload.data[0 ]; + +if (!ekp) +return -EKEYREVOKED ; + +if (cc->key_size != ekp->decrypted_datalen) +return -EINVAL ; + +memcpy (cc->key, ekp->decrypted_data, cc->key_size); + +return 0 ; +} +static int crypt_set_keyring_key (struct crypt_config *cc,const char *key_string) {char *new_key_string, *key_desc;int ret; +struct key_type *type;struct key *key; -const struct user_key_payload *ukp; +int (*set_key)(struct crypt_config *cc,struct key *key);/* * Reject key_string with whitespace. dm core currently lacks code for
@@ -2236,15 +2270,24 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_stringif (!key_desc || key_desc == key_string || !strlen (key_desc +1 ))return -EINVAL ; -if (strncmp (key_string,"logon:" , key_desc - key_string +1 ) && -strncmp (key_string,"user:" , key_desc - key_string +1 )) +if (!strncmp (key_string,"logon:" , key_desc - key_string +1 )) { + type = &key_type_logon; + set_key = &set_key_user; + }else if (!strncmp (key_string,"user:" , key_desc - key_string +1 )) { + type = &key_type_user; + set_key = &set_key_user; + }else if (!strncmp (key_string,"encrypted:" , key_desc - key_string +1 )) { + type = &key_type_encrypted; + set_key = set_key_encrypted; + }else {return -EINVAL ; + } new_key_string =kstrdup (key_string,GFP_KERNEL );if (!new_key_string)return -ENOMEM ; - key =request_key (key_string[0 ] =='l' ? &key_type_logon : &key_type_user, + key =request_key (type, key_desc +1 ,NULL );if (IS_ERR (key)) {kzfree (new_key_string);
@@ -2253,23 +2296,14 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_stringdown_read (&key->sem); - ukp =user_key_payload_locked (key); -if (!ukp) { -up_read (&key->sem); -key_put (key); -kzfree (new_key_string); -return -EKEYREVOKED ; - } - -if (cc->key_size != ukp->datalen) { + ret =set_key (cc, key); +if (ret <0 ) {up_read (&key->sem);key_put (key);kzfree (new_key_string); -return -EINVAL ; +return ret; } -memcpy (cc->key, ukp->data, cc->key_size); -up_read (&key->sem);key_put (key);
Signature · 1 line
2.25.1
Quoted 6 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>
I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
Mike
drivers/md/dm-crypt.c +3 -4
@@ -2272,10 +2272,10 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_stringif (!strncmp (key_string,"logon:" , key_desc - key_string +1 )) { type = &key_type_logon; - set_key = &set_key_user; + set_key = set_key_user; }else if (!strncmp (key_string,"user:" , key_desc - key_string +1 )) { type = &key_type_user; - set_key = &set_key_user; + set_key = set_key_user; }else if (!strncmp (key_string,"encrypted:" , key_desc - key_string +1 )) { type = &key_type_encrypted; set_key = set_key_encrypted;
@@ -2287,8 +2287,7 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_stringif (!new_key_string)return -ENOMEM ; - key =request_key (type, - key_desc +1 ,NULL ); + key =request_key (type, key_desc +1 ,NULL );if (IS_ERR (key)) {kzfree (new_key_string);return PTR_ERR (key);
вт, 21 апр. 2020 г. в 21:27, Mike Snitzer <[email protected]>:
Quoted 6 lines
Quoted 2 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Quoted 7 lines
Quoted 4 lines
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
Thank you!
Signature · 8 lines
With best wishes Dmitry -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 10 lines · Dmitry Baryshkov
вт, 21 апр. 2020 г. в 21:27, Mike Snitzer <[email protected]>:
Quoted 9 lines
Quoted 5 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Dmitry Baryshkov <[email protected]>I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
Thank you!
Actually, I think this is needed too -- but please correct me if I'm wrong:
drivers/md/dm-crypt.c +2 -1
@@ -2235,8 +2235,9 @@ static int set_key_user(struct crypt_config *cc, struct key *key)static int set_key_encrypted (struct crypt_config *cc,struct key *key) { -struct encrypted_key_payload *ekp = key->payload.data[0 ]; +const struct encrypted_key_payload *ekp; + ekp =dereference_key_locked (key);if (!ekp)return -EKEYREVOKED ;
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
Hello,
вт, 21 апр. 2020 г. в 21:59, Mike Snitzer <[email protected]>:
Quoted 14 lines
Quoted 10 lines · Dmitry Baryshkov
вт, 21 апр. 2020 г. в 21:27, Mike Snitzer <[email protected]>:
Quoted 9 lines
Quoted 5 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Dmitry Baryshkov <[email protected]>I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
Thank you!
Actually, I think this is needed too -- but please correct me if I'm wrong:
Yes, it looks like a correct change to me.
Quoted 16 lines
drivers/md/dm-crypt.c +2
-1@@ -2235,8 +2235,9 @@ static int set_key_user(struct crypt_config *cc, struct key *key)static int set_key_encrypted (struct crypt_config *cc,struct key *key) { -struct encrypted_key_payload *ekp = key->payload.data[0 ]; +const struct encrypted_key_payload *ekp; + ekp =dereference_key_locked (key);if (!ekp)return -EKEYREVOKED ;
Signature · 8 lines
With best wishes Dmitry -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 5 lines · Mike Snitzer
Quoted 2 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Quoted 7 lines
Quoted 4 lines
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
And you just created hard dependence on encrypted key type...
If you disable this type (CONFIG_ENCRYPTED_KEYS option), it cannot load the module anymore:
ERROR: modpost: "key_type_encrypted" [drivers/md/dm-crypt.ko] undefined!
We had this idea before, and this implementation in dm-crypt just requires dynamic key type loading implemented first.
David Howells (cc) promised that moths ago, but apparently nothing was yet submitted (and the proof-of-concept patch no longer works).
Mike, I think you should revert this patch from the tree until it is solved.
Once fixed, we should also support "trusted" key type.
Also please - do no forget to increase dm-crypt minor version here...
Thanks,
Milan
Quoted 11 lines · Milan Broz
Quoted 10 lines · Mike Snitzer
Quoted 6 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>
Quoted 7 lines
Quoted 2 lines
I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
And you just created hard dependence on encrypted key type...
If you disable this type (
CONFIG_ENCRYPTED_KEYSoption), it cannot load the module anymore:
ERROR: modpost: "key_type_encrypted" [drivers/md/dm-crypt.ko] undefined!
Yes, I was made aware via linux-next last night.
Quoted 5 lines
We had this idea before, and this implementation in dm-crypt just requires dynamic key type loading implemented first.
David Howells (cc) promised that moths ago, but apparently nothing was yet submitted (and the proof-of-concept patch no longer works).
Why is it so bad for dm-crypt to depend on CONFIG_ENCRYPTED_KEYS while we wait for the innovation from David?
Quoted 5 lines
Mike, I think you should revert this patch from the tree until it is solved.
Once fixed, we should also support "trusted" key type.
Also please - do no forget to increase dm-crypt minor version here...
I fixed the patch up and staged it in linux-next to get test coverage, see:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=for-next&id=5eb07fda05fbf87d9a37939d1cd445203c55e126
Doesn't mean I intend to keep it staged; just would like to validate the patch before tabling it (if that's what is ultimately decided for now).
Mike
Quoted 24 lines · Mike Snitzer
Quoted 11 lines · Milan Broz
Quoted 10 lines · Mike Snitzer
Quoted 6 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>Quoted 7 lines
Quoted 2 lines
I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
And you just created hard dependence on encrypted key type...
If you disable this type (
CONFIG_ENCRYPTED_KEYSoption), it cannot load the module anymore:
ERROR: modpost: "key_type_encrypted" [drivers/md/dm-crypt.ko] undefined!Yes, I was made aware via linux-next last night.
Quoted 8 lines
Quoted 5 lines
We had this idea before, and this implementation in dm-crypt just requires dynamic key type loading implemented first.
David Howells (cc) promised that moths ago, but apparently nothing was yet submitted (and the proof-of-concept patch no longer works).
Why is it so bad for dm-crypt to depend on
CONFIG_ENCRYPTED_KEYSwhile we wait for the innovation from David?
People need to compile kernel with specific features disabled, even without keyring sometimes. We also support whole CONFIG_KEYS disable - and it makes sense for some small appliances.
In fact I had similar patch (support for encrypted+trusted keyes) for dm-crypt for months, with additional patch that loads key types per requests (so it can fail if the type is not available). It uses key_type_lookup function exported. IMO this is the way to go.
So the idea is good, but please keep possibility to disable it.
Additional dependencies not only cause problems above, but also can get some failures from initrd where the new module is missing (that happened several times, it is just problem that can be easily avoided).
Milan
Hello,
чт, 23 апр. 2020 г. в 09:47, Milan Broz <[email protected]>:
Quoted 19 lines · Mike Snitzer
Quoted 17 lines
Quoted 14 lines · Milan Broz
Quoted 12 lines · Mike Snitzer
Quoted 6 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
And you just created hard dependence on encrypted key type...
If you disable this type (
CONFIG_ENCRYPTED_KEYSoption), it cannot load the module anymore:
ERROR: modpost: "key_type_encrypted" [drivers/md/dm-crypt.ko] undefined!Yes, I was made aware via linux-next last night.
I'm sorry for this.
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
We had this idea before, and this implementation in dm-crypt just requires dynamic key type loading implemented first.
David Howells (cc) promised that moths ago, but apparently nothing was yet submitted (and the proof-of-concept patch no longer works).
Why is it so bad for dm-crypt to depend on
CONFIG_ENCRYPTED_KEYSwhile we wait for the innovation from David?
Quoted 6 lines
People need to compile kernel with specific features disabled, even without keyring sometimes. We also support whole
CONFIG_KEYSdisable - and it makes sense for some small appliances.In fact I had similar patch (support for encrypted+trusted keyes) for dm-crypt for months, with additional patch that loads key types per requests (so it can fail if the type is not available). It uses
key_type_lookupfunction exported. IMO this is the way to go.
I've also had a patch using key_type_lookup(). However I ended up dropping it becasue each key type still needs type-specific function to access key payload. Unless we also add an API to access payloads in a type-neutral way, it does not make sense.
Quoted 4 lines
So the idea is good, but please keep possibility to disable it.
Additional dependencies not only cause problems above, but also can get some failures from initrd where the new module is missing (that happened several times, it is just problem that can be easily avoided).
It looks like Mike has already fixed it. So thanks a lot and sorry for the issues caused by the patch.
Signature · 8 lines
With best wishes Dmitry -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 37 lines · Milan Broz
Quoted 24 lines · Mike Snitzer
Quoted 11 lines · Milan Broz
Quoted 10 lines · Mike Snitzer
Quoted 6 lines · Dmitry Baryshkov
From: Dmitry Baryshkov <[email protected]>
Allow one to use encrypted in addition to user and login key types for device encryption.
Signed-off-by Dmitry Baryshkov <[email protected]>Quoted 7 lines
Quoted 2 lines
I fixed up some issues, please see the following incremental patch, I'll get this folded in and staged for 5.8.
And you just created hard dependence on encrypted key type...
If you disable this type (
CONFIG_ENCRYPTED_KEYSoption), it cannot load the module anymore:
ERROR: modpost: "key_type_encrypted" [drivers/md/dm-crypt.ko] undefined!Yes, I was made aware via linux-next last night.
Quoted 8 lines
Quoted 5 lines
We had this idea before, and this implementation in dm-crypt just requires dynamic key type loading implemented first.
David Howells (cc) promised that moths ago, but apparently nothing was yet submitted (and the proof-of-concept patch no longer works).
Why is it so bad for dm-crypt to depend on
CONFIG_ENCRYPTED_KEYSwhile we wait for the innovation from David?People need to compile kernel with specific features disabled, even without keyring sometimes. We also support whole
CONFIG_KEYSdisable - and it makes sense for some small appliances.
Quoted 8 lines
In fact I had similar patch (support for encrypted+trusted keyes) for dm-crypt for months, with additional patch that loads key types per requests (so it can fail if the type is not available). It uses
key_type_lookupfunction exported. IMO this is the way to go.So the idea is good, but please keep possibility to disable it.
Additional dependencies not only cause problems above, but also can get some failures from initrd where the new module is missing (that happened several times, it is just problem that can be easily avoided).
Seems you didn't look at the fixed patch, here is what I ultimately staged yesterday:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.8&id=a2b35bd064baf1f4e7504c23d493a3e149172dd1
dm-crypt doesn't have a hard dependency on CONFIG_ENCRYPTED_KEYS. If it is enabled support will be available, if not enabled support isn't.
The concern about initramfs not having dep modules is a kernel tooling support issue. Not seeing any point withholding capabilities out of paranoia that a particular distribution's tooling (initramfs generation upon kernel update) isn't working as needed.
Mike
Quoted 7 lines · Mike Snitzer
Seems you didn't look at the fixed patch, here is what I ultimately staged yesterday:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.8&id=a2b35bd064baf1f4e7504c23d493a3e149172dd1dm-crypt doesn't have a hard dependency on
CONFIG_ENCRYPTED_KEYS. If it is enabled support will be available, if not enabled support isn't.
It is acceptable solution if you really want to push it now. Just you will repeat the same #ifdef exercise for the "trusted" key type.
What we did last time, is here - it combines dynamic key type loading
and #if IS_REACHABLE(CONFIG_ENCRYPTED_KEYS) (we cannot avoid it if it is completely compiled out here) It is somewhat more readable for me and eliminates few ifdefs.
Just it can be no longer applied, but the idea is here in two old patches:
https://mbroz.fedorapeople.org/tmp/
Milan