Skip to content

Commit b8d9970

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce key_post_create_or_update hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the key_post_create_or_update hook. Depending on policy, IMA measures the key content after creation or update, so that remote verifiers are aware of the operation. Other LSMs could similarly take some action after successful key creation or update. The new hook cannot return an error and cannot cause the operation to be reverted. Signed-off-by: Roberto Sassu <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Acked-by: Casey Schaufler <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 2d705d8 commit b8d9970

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key)
405405
LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred,
406406
enum key_need_perm need_perm)
407407
LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **buffer)
408+
LSM_HOOK(void, LSM_RET_VOID, key_post_create_or_update, struct key *keyring,
409+
struct key *key, const void *payload, size_t payload_len,
410+
unsigned long flags, bool create)
408411
#endif /* CONFIG_KEYS */
409412

410413
#ifdef CONFIG_AUDIT

include/linux/security.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,9 @@ void security_key_free(struct key *key);
20042004
int security_key_permission(key_ref_t key_ref, const struct cred *cred,
20052005
enum key_need_perm need_perm);
20062006
int security_key_getsecurity(struct key *key, char **_buffer);
2007+
void security_key_post_create_or_update(struct key *keyring, struct key *key,
2008+
const void *payload, size_t payload_len,
2009+
unsigned long flags, bool create);
20072010

20082011
#else
20092012

@@ -2031,6 +2034,14 @@ static inline int security_key_getsecurity(struct key *key, char **_buffer)
20312034
return 0;
20322035
}
20332036

2037+
static inline void security_key_post_create_or_update(struct key *keyring,
2038+
struct key *key,
2039+
const void *payload,
2040+
size_t payload_len,
2041+
unsigned long flags,
2042+
bool create)
2043+
{ }
2044+
20342045
#endif
20352046
#endif /* CONFIG_KEYS */
20362047

security/keys/key.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,8 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref,
930930
goto error_link_end;
931931
}
932932

933+
security_key_post_create_or_update(keyring, key, payload, plen, flags,
934+
true);
933935
ima_post_key_create_or_update(keyring, key, payload, plen,
934936
flags, true);
935937

@@ -963,10 +965,13 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref,
963965

964966
key_ref = __key_update(key_ref, &prep);
965967

966-
if (!IS_ERR(key_ref))
968+
if (!IS_ERR(key_ref)) {
969+
security_key_post_create_or_update(keyring, key, payload, plen,
970+
flags, false);
967971
ima_post_key_create_or_update(keyring, key,
968972
payload, plen,
969973
flags, false);
974+
}
970975

971976
goto error_free_prep;
972977
}

security/security.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5453,6 +5453,25 @@ int security_key_getsecurity(struct key *key, char **buffer)
54535453
*buffer = NULL;
54545454
return call_int_hook(key_getsecurity, 0, key, buffer);
54555455
}
5456+
5457+
/**
5458+
* security_key_post_create_or_update() - Notification of key create or update
5459+
* @keyring: keyring to which the key is linked to
5460+
* @key: created or updated key
5461+
* @payload: data used to instantiate or update the key
5462+
* @payload_len: length of payload
5463+
* @flags: key flags
5464+
* @create: flag indicating whether the key was created or updated
5465+
*
5466+
* Notify the caller of a key creation or update.
5467+
*/
5468+
void security_key_post_create_or_update(struct key *keyring, struct key *key,
5469+
const void *payload, size_t payload_len,
5470+
unsigned long flags, bool create)
5471+
{
5472+
call_void_hook(key_post_create_or_update, keyring, key, payload,
5473+
payload_len, flags, create);
5474+
}
54565475
#endif /* CONFIG_KEYS */
54575476

54585477
#ifdef CONFIG_AUDIT

0 commit comments

Comments
 (0)