mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederick Lawler <fred@cloudflare.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: herbert@gondor.apana.org.au, davem@davemloft.net, hch@lst.de,
	smueller@chronox.de, linux-kernel@vger.kernel.org,
	linux-crypto@vger.kernel.org, kernel-team@cloudflare.com,
	Ondrej Mosnacek <omosnace@redhat.com>
Subject: Re: [RFC PATCH 1/1] crypto: af_alg - Support symmetric encryption via keyring keys
Date: Wed, 12 Oct 2022 09:49:56 -0500	[thread overview]
Message-ID: <cc5c3efe-7dc3-65d6-d7d9-761bfc2c9711@cloudflare.com> (raw)
In-Reply-To: <Y0X3L/jhinCqJXxj@sol.localdomain>

Hi Eric,

On 10/11/22 6:07 PM, Eric Biggers wrote:
> Hi Frederick,
> 
> On Tue, Oct 04, 2022 at 04:29:27PM -0500, Frederick Lawler wrote:
>> We want to leverage keyring to store sensitive keys, and then use those
>> keys for symmetric encryption via the crypto API. Among the key types we
>> wish to support are: user, logon, encrypted, and trusted.
>>
>> User key types are already able to have their data copied to user space,
>> but logon does not support this. Further, trusted and encrypted keys will
>> return their encrypted data back to user space on read, which make them not
>> ideal for symmetric encryption.
>>
>> To support symmetric encryption for these key types, add a new
>> ALG_SET_KEY_BY_KEY_SERIAL setsockopt() option to the crypto API. This
>> allows users to pass a key_serial_t to the crypto API to perform
>> symmetric encryption. The behavior is the same as ALG_SET_KEY, but
>> the crypto key data is copied in kernel space from a keyring key,
>> which allows for the support of logon, encrypted, and trusted key types.
>>
>> Keyring keys must have the KEY_(POS|USR|GRP|OTH)_SEARCH permission set
>> to leverage this feature. This follows the asymmetric_key type where key
>> lookup calls eventually lead to keyring_search_rcu() without the
>> KEYRING_SEARCH_NO_CHECK_PERM flag set.
>>
>> Signed-off-by: Frederick Lawler <fred@cloudflare.com>
> 
> There was a similar patch several years ago by Ondrej Mosnacek:
> https://lore.kernel.org/linux-crypto/20190521100034.9651-1-omosnace@redhat.com/T/#u
> 
> Have you addressed all the feedback that was raised on that one?

Thanks for sharing that.

I believe I've addressed most of the feedback. Starting with we agree 
preferring key_serial_t. I changed to to use IS_REACHABLE(), and set 
ALG_SET_KEY_BY_KEY_SERIAL to 10 leaving a comment about libkcapi 
reserving values 7-9.

I've made other additional changes since the RFC, so we should consider 
this code outdated. I'll submit a v1 that is a bit cleaner after the 
merge window.

Your comment about broken crypto algorithms exposing sensitive data is 
interesting. We've had similar thoughts about adding additional 
permission, but ultimately decided to stick to the pattern asymmetric 
key types use.

lookup_user_key() ultimately makes a call into a security hook 
security_key_permission() given a key_ref_t, so users can further 
restrict access based on keys that way if enabled. We've also had 
similar discussions regarding X.509 certificates, and I'm not opposed to 
Ondrej's suggestion of disabling this feature by default with Kconfig. 
I'll look into this a bit more, and we're open to suggestions here.

> 
> Two random nits below:
> 
>> +	*dest_len = key->datalen;
>> +	*dest = kmalloc(*dest_len, GFP_KERNEL);
>> +	if (!*dest)
>> +		return -ENOMEM;
>> +
>> +	memcpy(*dest, ukp->data, *dest_len);
> 
> This should use kmemdup(). >
>> +	} else if (IS_ENABLED(CONFIG_ENCRYPTED_KEYS) &&
>> +			   !strcmp(key->type->name, "encrypted")) {
>> +		read_key = &read_key_type_encrypted;
>> +	} else if (IS_ENABLED(CONFIG_TRUSTED_KEYS) &&
>> +			   !strcmp(key->type->name, "trusted")) {
>> +		read_key = &read_key_type_trusted;
> 
> These need to use IS_REACHABLE(), not IS_ENABLED().
> 
> - Eric


  reply	other threads:[~2022-10-12 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 21:29 Frederick Lawler
2022-10-11 23:07 ` Eric Biggers
2022-10-12 14:49   ` Frederick Lawler [this message]
2022-10-12 15:21     ` Stephan Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc5c3efe-7dc3-65d6-d7d9-761bfc2c9711@cloudflare.com \
    --to=fred@cloudflare.com \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=hch@lst.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=kernel-team@cloudflare.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=smueller@chronox.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®