Skip to content

Commit 7dfa0ca

Browse files
committed
KEYS: Allow expiry time to be set when preparsing a key
Allow a key type's preparsing routine to set the expiry time for a key. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Steve Dickson <steved@redhat.com> Acked-by: Jeff Layton <jlayton@primarydata.com> Reviewed-by: Sage Weil <sage@redhat.com>
1 parent fc7c70e commit 7dfa0ca

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎Documentation/security/keys.txt‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,20 +1150,24 @@ The structure has a number of fields, some of which are mandatory:
11501150
const void *data;
11511151
size_t datalen;
11521152
size_t quotalen;
1153+
time_t expiry;
11531154
};
11541155

11551156
Before calling the method, the caller will fill in data and datalen with
11561157
the payload blob parameters; quotalen will be filled in with the default
1157-
quota size from the key type and the rest will be cleared.
1158+
quota size from the key type; expiry will be set to TIME_T_MAX and the
1159+
rest will be cleared.
11581160

11591161
If a description can be proposed from the payload contents, that should be
11601162
attached as a string to the description field. This will be used for the
11611163
key description if the caller of add_key() passes NULL or "".
11621164

11631165
The method can attach anything it likes to type_data[] and payload. These
1164-
are merely passed along to the instantiate() or update() operations.
1166+
are merely passed along to the instantiate() or update() operations. If
1167+
set, the expiry time will be applied to the key if it is instantiated from
1168+
this data.
11651169

1166-
The method should return 0 if success ful or a negative error code
1170+
The method should return 0 if successful or a negative error code
11671171
otherwise.
11681172

11691173

‎include/linux/key-type.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct key_preparsed_payload {
4545
const void *data; /* Raw data */
4646
size_t datalen; /* Raw datalen */
4747
size_t quotalen; /* Quota length for proposed payload */
48+
time_t expiry; /* Expiry time of key */
4849
bool trusted; /* True if key is trusted */
4950
};
5051

‎security/keys/key.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ static int __key_instantiate_and_link(struct key *key,
437437
/* disable the authorisation key */
438438
if (authkey)
439439
key_revoke(authkey);
440+
441+
if (prep->expiry != TIME_T_MAX) {
442+
key->expiry = prep->expiry;
443+
key_schedule_gc(prep->expiry + key_gc_delay);
444+
}
440445
}
441446
}
442447

@@ -479,6 +484,7 @@ int key_instantiate_and_link(struct key *key,
479484
prep.data = data;
480485
prep.datalen = datalen;
481486
prep.quotalen = key->type->def_datalen;
487+
prep.expiry = TIME_T_MAX;
482488
if (key->type->preparse) {
483489
ret = key->type->preparse(&prep);
484490
if (ret < 0)
@@ -811,6 +817,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
811817
prep.datalen = plen;
812818
prep.quotalen = index_key.type->def_datalen;
813819
prep.trusted = flags & KEY_ALLOC_TRUSTED;
820+
prep.expiry = TIME_T_MAX;
814821
if (index_key.type->preparse) {
815822
ret = index_key.type->preparse(&prep);
816823
if (ret < 0) {
@@ -941,6 +948,7 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen)
941948
prep.data = payload;
942949
prep.datalen = plen;
943950
prep.quotalen = key->type->def_datalen;
951+
prep.expiry = TIME_T_MAX;
944952
if (key->type->preparse) {
945953
ret = key->type->preparse(&prep);
946954
if (ret < 0)

0 commit comments

Comments
 (0)