Skip to content

Commit 77f68ba

Browse files
committed
KEYS: Remove KEY_FLAG_TRUSTED and KEY_ALLOC_TRUSTED
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]>
1 parent a511e1a commit 77f68ba

File tree

7 files changed

+9
-59
lines changed

7 files changed

+9
-59
lines changed

certs/system_keyring.c

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extern __initconst const unsigned long system_certificate_list_size;
3131
*/
3232
int restrict_link_by_builtin_trusted(struct key *keyring,
3333
const struct key_type *type,
34-
unsigned long flags,
3534
const union key_payload *payload)
3635
{
3736
return restrict_link_by_signature(system_trusted_keyring,
@@ -97,7 +96,6 @@ static __init int load_system_certificate_list(void)
9796
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
9897
KEY_USR_VIEW | KEY_USR_READ),
9998
KEY_ALLOC_NOT_IN_QUOTA |
100-
KEY_ALLOC_TRUSTED |
10199
KEY_ALLOC_BUILT_IN |
102100
KEY_ALLOC_BYPASS_RESTRICTION);
103101
if (IS_ERR(key)) {

include/keys/system_keyring.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
extern int restrict_link_by_builtin_trusted(struct key *keyring,
2020
const struct key_type *type,
21-
unsigned long flags,
2221
const union key_payload *payload);
2322

2423
#else

include/linux/key-type.h

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct key_preparsed_payload {
4545
size_t datalen; /* Raw datalen */
4646
size_t quotalen; /* Quota length for proposed payload */
4747
time_t expiry; /* Expiry time of key */
48-
bool trusted; /* True if key is trusted */
4948
};
5049

5150
typedef int (*request_key_actor_t)(struct key_construction *key,

include/linux/key.h

+5-16
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ struct key {
173173
#define KEY_FLAG_NEGATIVE 5 /* set if key is negative */
174174
#define KEY_FLAG_ROOT_CAN_CLEAR 6 /* set if key can be cleared by root without permission */
175175
#define KEY_FLAG_INVALIDATED 7 /* set if key has been invalidated */
176-
#define KEY_FLAG_TRUSTED 8 /* set if key is trusted */
177-
#define KEY_FLAG_BUILTIN 9 /* set if key is built in to the kernel */
178-
#define KEY_FLAG_ROOT_CAN_INVAL 10 /* set if key can be invalidated by root without permission */
179-
#define KEY_FLAG_KEEP 11 /* set if key should not be removed */
176+
#define KEY_FLAG_BUILTIN 8 /* set if key is built in to the kernel */
177+
#define KEY_FLAG_ROOT_CAN_INVAL 9 /* set if key can be invalidated by root without permission */
178+
#define KEY_FLAG_KEEP 10 /* set if key should not be removed */
180179

181180
/* the key type and key description string
182181
* - the desc is used to match a key against search criteria
@@ -217,7 +216,6 @@ struct key {
217216
*/
218217
int (*restrict_link)(struct key *keyring,
219218
const struct key_type *type,
220-
unsigned long flags,
221219
const union key_payload *payload);
222220
};
223221

@@ -229,16 +227,14 @@ extern struct key *key_alloc(struct key_type *type,
229227
unsigned long flags,
230228
int (*restrict_link)(struct key *,
231229
const struct key_type *,
232-
unsigned long,
233230
const union key_payload *));
234231

235232

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

243239
extern void key_revoke(struct key *key);
244240
extern void key_invalidate(struct key *key);
@@ -309,18 +305,11 @@ extern struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid
309305
unsigned long flags,
310306
int (*restrict_link)(struct key *,
311307
const struct key_type *,
312-
unsigned long,
313308
const union key_payload *),
314309
struct key *dest);
315310

316-
extern int keyring_restrict_trusted_only(struct key *keyring,
317-
const struct key_type *type,
318-
unsigned long,
319-
const union key_payload *payload);
320-
321311
extern int restrict_link_reject(struct key *keyring,
322312
const struct key_type *type,
323-
unsigned long flags,
324313
const union key_payload *payload);
325314

326315
extern int keyring_clear(struct key *keyring);

security/integrity/digsig.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ static bool init_keyring __initdata;
5151
*/
5252
static int restrict_link_by_ima_mok(struct key *keyring,
5353
const struct key_type *type,
54-
unsigned long flags,
5554
const union key_payload *payload)
5655
{
5756
int ret;
5857

59-
ret = restrict_link_by_builtin_trusted(keyring, type, flags, payload);
58+
ret = restrict_link_by_builtin_trusted(keyring, type, payload);
6059
if (ret != -ENOKEY)
6160
return ret;
6261

security/keys/key.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ struct key *key_alloc(struct key_type *type, const char *desc,
227227
key_perm_t perm, unsigned long flags,
228228
int (*restrict_link)(struct key *,
229229
const struct key_type *,
230-
unsigned long,
231230
const union key_payload *))
232231
{
233232
struct key_user *user = NULL;
@@ -300,8 +299,6 @@ struct key *key_alloc(struct key_type *type, const char *desc,
300299

301300
if (!(flags & KEY_ALLOC_NOT_IN_QUOTA))
302301
key->flags |= 1 << KEY_FLAG_IN_QUOTA;
303-
if (flags & KEY_ALLOC_TRUSTED)
304-
key->flags |= 1 << KEY_FLAG_TRUSTED;
305302
if (flags & KEY_ALLOC_BUILT_IN)
306303
key->flags |= 1 << KEY_FLAG_BUILTIN;
307304

@@ -504,7 +501,7 @@ int key_instantiate_and_link(struct key *key,
504501
if (keyring) {
505502
if (keyring->restrict_link) {
506503
ret = keyring->restrict_link(keyring, key->type,
507-
key->flags, &prep.payload);
504+
&prep.payload);
508505
if (ret < 0)
509506
goto error;
510507
}
@@ -811,7 +808,6 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
811808
int ret;
812809
int (*restrict_link)(struct key *,
813810
const struct key_type *,
814-
unsigned long,
815811
const union key_payload *) = NULL;
816812

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

862857
if (restrict_link) {
863-
unsigned long kflags = prep.trusted ? KEY_FLAG_TRUSTED : 0;
864-
ret = restrict_link(keyring,
865-
index_key.type, kflags, &prep.payload);
858+
ret = restrict_link(keyring, index_key.type, &prep.payload);
866859
if (ret < 0) {
867860
key_ref = ERR_PTR(ret);
868861
goto error_free_prep;

security/keys/keyring.c

+1-28
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid,
494494
unsigned long flags,
495495
int (*restrict_link)(struct key *,
496496
const struct key_type *,
497-
unsigned long,
498497
const union key_payload *),
499498
struct key *dest)
500499
{
@@ -515,34 +514,10 @@ struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid,
515514
}
516515
EXPORT_SYMBOL(keyring_alloc);
517516

518-
/**
519-
* keyring_restrict_trusted_only - Restrict additions to a keyring to trusted keys only
520-
* @keyring: The keyring being added to.
521-
* @type: The type of key being added.
522-
* @flags: The key flags.
523-
* @payload: The payload of the key intended to be added.
524-
*
525-
* Reject the addition of any links to a keyring that point to keys that aren't
526-
* marked as being trusted. It can be overridden by passing
527-
* KEY_ALLOC_BYPASS_RESTRICTION to key_instantiate_and_link() when adding a key
528-
* to a keyring.
529-
*
530-
* This is meant to be passed as the restrict_link parameter to
531-
* keyring_alloc().
532-
*/
533-
int keyring_restrict_trusted_only(struct key *keyring,
534-
const struct key_type *type,
535-
unsigned long flags,
536-
const union key_payload *payload)
537-
{
538-
return flags & KEY_FLAG_TRUSTED ? 0 : -EPERM;
539-
}
540-
541517
/**
542518
* restrict_link_reject - Give -EPERM to restrict link
543519
* @keyring: The keyring being added to.
544520
* @type: The type of key being added.
545-
* @flags: The key flags.
546521
* @payload: The payload of the key intended to be added.
547522
*
548523
* Reject the addition of any links to a keyring. It can be overridden by
@@ -554,7 +529,6 @@ int keyring_restrict_trusted_only(struct key *keyring,
554529
*/
555530
int restrict_link_reject(struct key *keyring,
556531
const struct key_type *type,
557-
unsigned long flags,
558532
const union key_payload *payload)
559533
{
560534
return -EPERM;
@@ -1248,8 +1222,7 @@ static int __key_link_check_restriction(struct key *keyring, struct key *key)
12481222
{
12491223
if (!keyring->restrict_link)
12501224
return 0;
1251-
return keyring->restrict_link(keyring,
1252-
key->type, key->flags, &key->payload);
1225+
return keyring->restrict_link(keyring, key->type, &key->payload);
12531226
}
12541227

12551228
/**

0 commit comments

Comments
 (0)