Skip to content

Commit

Permalink
KEYS: Remove KEY_FLAG_TRUSTED and KEY_ALLOC_TRUSTED
Browse files Browse the repository at this point in the history
Remove KEY_FLAG_TRUSTED and KEY_ALLOC_TRUSTED as they're no longer
meaningful.  Also we can drop the trusted flag from the preparse structure.

Given this, we no longer need to pass the key flags through to
restrict_link().

Further, we can now get rid of keyring_restrict_trusted_only() also.

Signed-off-by: David Howells <[email protected]>
  • Loading branch information
dhowells committed Apr 11, 2016
1 parent a511e1a commit 77f68ba
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 59 deletions.
2 changes: 0 additions & 2 deletions certs/system_keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extern __initconst const unsigned long system_certificate_list_size;
*/
int restrict_link_by_builtin_trusted(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload)
{
return restrict_link_by_signature(system_trusted_keyring,
Expand Down Expand Up @@ -97,7 +96,6 @@ static __init int load_system_certificate_list(void)
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
KEY_USR_VIEW | KEY_USR_READ),
KEY_ALLOC_NOT_IN_QUOTA |
KEY_ALLOC_TRUSTED |
KEY_ALLOC_BUILT_IN |
KEY_ALLOC_BYPASS_RESTRICTION);
if (IS_ERR(key)) {
Expand Down
1 change: 0 additions & 1 deletion include/keys/system_keyring.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

extern int restrict_link_by_builtin_trusted(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload);

#else
Expand Down
1 change: 0 additions & 1 deletion include/linux/key-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ struct key_preparsed_payload {
size_t datalen; /* Raw datalen */
size_t quotalen; /* Quota length for proposed payload */
time_t expiry; /* Expiry time of key */
bool trusted; /* True if key is trusted */
};

typedef int (*request_key_actor_t)(struct key_construction *key,
Expand Down
21 changes: 5 additions & 16 deletions include/linux/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ struct key {
#define KEY_FLAG_NEGATIVE 5 /* set if key is negative */
#define KEY_FLAG_ROOT_CAN_CLEAR 6 /* set if key can be cleared by root without permission */
#define KEY_FLAG_INVALIDATED 7 /* set if key has been invalidated */
#define KEY_FLAG_TRUSTED 8 /* set if key is trusted */
#define KEY_FLAG_BUILTIN 9 /* set if key is built in to the kernel */
#define KEY_FLAG_ROOT_CAN_INVAL 10 /* set if key can be invalidated by root without permission */
#define KEY_FLAG_KEEP 11 /* set if key should not be removed */
#define KEY_FLAG_BUILTIN 8 /* set if key is built in to the kernel */
#define KEY_FLAG_ROOT_CAN_INVAL 9 /* set if key can be invalidated by root without permission */
#define KEY_FLAG_KEEP 10 /* set if key should not be removed */

/* the key type and key description string
* - the desc is used to match a key against search criteria
Expand Down Expand Up @@ -217,7 +216,6 @@ struct key {
*/
int (*restrict_link)(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload);
};

Expand All @@ -229,16 +227,14 @@ extern struct key *key_alloc(struct key_type *type,
unsigned long flags,
int (*restrict_link)(struct key *,
const struct key_type *,
unsigned long,
const union key_payload *));


#define KEY_ALLOC_IN_QUOTA 0x0000 /* add to quota, reject if would overrun */
#define KEY_ALLOC_QUOTA_OVERRUN 0x0001 /* add to quota, permit even if overrun */
#define KEY_ALLOC_NOT_IN_QUOTA 0x0002 /* not in quota */
#define KEY_ALLOC_TRUSTED 0x0004 /* Key should be flagged as trusted */
#define KEY_ALLOC_BUILT_IN 0x0008 /* Key is built into kernel */
#define KEY_ALLOC_BYPASS_RESTRICTION 0x0010 /* Override the check on restricted keyrings */
#define KEY_ALLOC_BUILT_IN 0x0004 /* Key is built into kernel */
#define KEY_ALLOC_BYPASS_RESTRICTION 0x0008 /* Override the check on restricted keyrings */

extern void key_revoke(struct key *key);
extern void key_invalidate(struct key *key);
Expand Down Expand Up @@ -309,18 +305,11 @@ extern struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid
unsigned long flags,
int (*restrict_link)(struct key *,
const struct key_type *,
unsigned long,
const union key_payload *),
struct key *dest);

extern int keyring_restrict_trusted_only(struct key *keyring,
const struct key_type *type,
unsigned long,
const union key_payload *payload);

extern int restrict_link_reject(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload);

extern int keyring_clear(struct key *keyring);
Expand Down
3 changes: 1 addition & 2 deletions security/integrity/digsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ static bool init_keyring __initdata;
*/
static int restrict_link_by_ima_mok(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload)
{
int ret;

ret = restrict_link_by_builtin_trusted(keyring, type, flags, payload);
ret = restrict_link_by_builtin_trusted(keyring, type, payload);
if (ret != -ENOKEY)
return ret;

Expand Down
11 changes: 2 additions & 9 deletions security/keys/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ struct key *key_alloc(struct key_type *type, const char *desc,
key_perm_t perm, unsigned long flags,
int (*restrict_link)(struct key *,
const struct key_type *,
unsigned long,
const union key_payload *))
{
struct key_user *user = NULL;
Expand Down Expand Up @@ -300,8 +299,6 @@ struct key *key_alloc(struct key_type *type, const char *desc,

if (!(flags & KEY_ALLOC_NOT_IN_QUOTA))
key->flags |= 1 << KEY_FLAG_IN_QUOTA;
if (flags & KEY_ALLOC_TRUSTED)
key->flags |= 1 << KEY_FLAG_TRUSTED;
if (flags & KEY_ALLOC_BUILT_IN)
key->flags |= 1 << KEY_FLAG_BUILTIN;

Expand Down Expand Up @@ -504,7 +501,7 @@ int key_instantiate_and_link(struct key *key,
if (keyring) {
if (keyring->restrict_link) {
ret = keyring->restrict_link(keyring, key->type,
key->flags, &prep.payload);
&prep.payload);
if (ret < 0)
goto error;
}
Expand Down Expand Up @@ -811,7 +808,6 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
int ret;
int (*restrict_link)(struct key *,
const struct key_type *,
unsigned long,
const union key_payload *) = NULL;

/* look up the key type to see if it's one of the registered kernel
Expand Down Expand Up @@ -843,7 +839,6 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
prep.data = payload;
prep.datalen = plen;
prep.quotalen = index_key.type->def_datalen;
prep.trusted = flags & KEY_ALLOC_TRUSTED;
prep.expiry = TIME_T_MAX;
if (index_key.type->preparse) {
ret = index_key.type->preparse(&prep);
Expand All @@ -860,9 +855,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
index_key.desc_len = strlen(index_key.description);

if (restrict_link) {
unsigned long kflags = prep.trusted ? KEY_FLAG_TRUSTED : 0;
ret = restrict_link(keyring,
index_key.type, kflags, &prep.payload);
ret = restrict_link(keyring, index_key.type, &prep.payload);
if (ret < 0) {
key_ref = ERR_PTR(ret);
goto error_free_prep;
Expand Down
29 changes: 1 addition & 28 deletions security/keys/keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid,
unsigned long flags,
int (*restrict_link)(struct key *,
const struct key_type *,
unsigned long,
const union key_payload *),
struct key *dest)
{
Expand All @@ -515,34 +514,10 @@ struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid,
}
EXPORT_SYMBOL(keyring_alloc);

/**
* keyring_restrict_trusted_only - Restrict additions to a keyring to trusted keys only
* @keyring: The keyring being added to.
* @type: The type of key being added.
* @flags: The key flags.
* @payload: The payload of the key intended to be added.
*
* Reject the addition of any links to a keyring that point to keys that aren't
* marked as being trusted. It can be overridden by passing
* KEY_ALLOC_BYPASS_RESTRICTION to key_instantiate_and_link() when adding a key
* to a keyring.
*
* This is meant to be passed as the restrict_link parameter to
* keyring_alloc().
*/
int keyring_restrict_trusted_only(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload)
{
return flags & KEY_FLAG_TRUSTED ? 0 : -EPERM;
}

/**
* restrict_link_reject - Give -EPERM to restrict link
* @keyring: The keyring being added to.
* @type: The type of key being added.
* @flags: The key flags.
* @payload: The payload of the key intended to be added.
*
* Reject the addition of any links to a keyring. It can be overridden by
Expand All @@ -554,7 +529,6 @@ int keyring_restrict_trusted_only(struct key *keyring,
*/
int restrict_link_reject(struct key *keyring,
const struct key_type *type,
unsigned long flags,
const union key_payload *payload)
{
return -EPERM;
Expand Down Expand Up @@ -1248,8 +1222,7 @@ static int __key_link_check_restriction(struct key *keyring, struct key *key)
{
if (!keyring->restrict_link)
return 0;
return keyring->restrict_link(keyring,
key->type, key->flags, &key->payload);
return keyring->restrict_link(keyring, key->type, &key->payload);
}

/**
Expand Down

0 comments on commit 77f68ba

Please sign in to comment.