Re: [RFC PATCH 07/20] KEYS: Add a facility to restrict new links into a keyring [ver #2]

From: David Howells
Date: Mon Feb 29 2016 - 10:49:48 EST


Mimi Zohar <zohar@xxxxxxxxxxxxxxxxxx> wrote:

> > + If restrict_link not NULL, it should point to a function will be called to
> > + vet all attempts to link keys into the keyring, though this can be
> > + overridden by passing KEY_ALLOC_BYPASS_RESTRICTION to
> > + key_create_or_update().
>
> Please fix the first part of the sentence. Maybe add an example of
> when it is appropriate to bypass the restriction - (eg. loading the
> builtin keys).

Okay:

If restrict_link not NULL, it should point to a function that will be
called each time an attempt is made to link a key into the new keyring.
This function is called to check whether a key may be added into the keying
or not. Callers of key_create_or_update() within the kernel can pass
KEY_ALLOC_BYPASS_RESTRICTION to suppress the check. An example of using
this is to manage rings of cryptographic keys that are set up when the
kernel boots where userspace is also permitted to add keys - provided they
can be verified by a key the kernel already has.

When called, the restriction function will be passed the keyring being
added to, the key flags value and the type and payload of the key being
added. Note that when a new key is being created, this is called between
payload preparsing and actual key creation. The function should return 0
to allow the link or an error to reject it.

David