Skip to content

Commit c03c21b

Browse files
committed
Merge tag 'keys-misc-20210126' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
Pull keyring updates from David Howells: "Here's a set of minor keyrings fixes/cleanups that I've collected from various people for the upcoming merge window. A couple of them might, in theory, be visible to userspace: - Make blacklist_vet_description() reject uppercase letters as they don't match the all-lowercase hex string generated for a blacklist search. This may want reconsideration in the future, but, currently, you can't add to the blacklist keyring from userspace and the only source of blacklist keys generates lowercase descriptions. - Fix blacklist_init() to use a new KEY_ALLOC_* flag to indicate that it wants KEY_FLAG_KEEP to be set rather than passing KEY_FLAG_KEEP into keyring_alloc() as KEY_FLAG_KEEP isn't a valid alloc flag. This isn't currently a problem as the blacklist keyring isn't currently writable by userspace. The rest of the patches are cleanups and I don't think they should have any visible effect" * tag 'keys-misc-20210126' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: watch_queue: rectify kernel-doc for init_watch() certs: Replace K{U,G}IDT_INIT() with GLOBAL_ROOT_{U,G}ID certs: Fix blacklist flag type confusion PKCS#7: Fix missing include certs: Fix blacklisted hexadecimal hash string check certs/blacklist: fix kernel doc interface issue crypto: public_key: Remove redundant header file from public_key.h keys: remove trailing semicolon in macro definition crypto: pkcs7: Use match_string() helper to simplify the code PKCS#7: drop function from kernel-doc pkcs7_validate_trust_one encrypted-keys: Replace HTTP links with HTTPS ones crypto: asymmetric_keys: fix some comments in pkcs7_parser.h KEYS: remove redundant memset security: keys: delete repeated words in comments KEYS: asymmetric: Fix kerneldoc security/keys: use kvfree_sensitive() watch_queue: Drop references to /dev/watch_queue keys: Remove outdated __user annotations security: keys: Fix fall-through warnings for Clang
2 parents 414eece + 8f0bfc2 commit c03c21b

File tree

22 files changed

+48
-48
lines changed

22 files changed

+48
-48
lines changed

Documentation/security/keys/core.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,8 @@ The keyctl syscall functions are:
10401040

10411041
"key" is the ID of the key to be watched.
10421042

1043-
"queue_fd" is a file descriptor referring to an open "/dev/watch_queue"
1044-
which manages the buffer into which notifications will be delivered.
1043+
"queue_fd" is a file descriptor referring to an open pipe which
1044+
manages the buffer into which notifications will be delivered.
10451045

10461046
"filter" is either NULL to remove a watch or a filter specification to
10471047
indicate what events are required from the key.

certs/blacklist.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/ctype.h>
1515
#include <linux/err.h>
1616
#include <linux/seq_file.h>
17+
#include <linux/uidgid.h>
1718
#include <keys/system_keyring.h>
1819
#include "blacklist.h"
1920

@@ -37,7 +38,7 @@ static int blacklist_vet_description(const char *desc)
3738
found_colon:
3839
desc++;
3940
for (; *desc; desc++) {
40-
if (!isxdigit(*desc))
41+
if (!isxdigit(*desc) || isupper(*desc))
4142
return -EINVAL;
4243
n++;
4344
}
@@ -78,7 +79,7 @@ static struct key_type key_type_blacklist = {
7879

7980
/**
8081
* mark_hash_blacklisted - Add a hash to the system blacklist
81-
* @hash - The hash as a hex string with a type prefix (eg. "tbs:23aa429783")
82+
* @hash: The hash as a hex string with a type prefix (eg. "tbs:23aa429783")
8283
*/
8384
int mark_hash_blacklisted(const char *hash)
8485
{
@@ -156,13 +157,12 @@ static int __init blacklist_init(void)
156157

157158
blacklist_keyring =
158159
keyring_alloc(".blacklist",
159-
KUIDT_INIT(0), KGIDT_INIT(0),
160-
current_cred(),
160+
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
161161
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
162162
KEY_USR_VIEW | KEY_USR_READ |
163163
KEY_USR_SEARCH,
164164
KEY_ALLOC_NOT_IN_QUOTA |
165-
KEY_FLAG_KEEP,
165+
KEY_ALLOC_SET_KEEP,
166166
NULL, NULL);
167167
if (IS_ERR(blacklist_keyring))
168168
panic("Can't allocate system blacklist keyring\n");

certs/system_keyring.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/cred.h>
1212
#include <linux/err.h>
1313
#include <linux/slab.h>
14+
#include <linux/uidgid.h>
1415
#include <linux/verification.h>
1516
#include <keys/asymmetric-type.h>
1617
#include <keys/system_keyring.h>
@@ -98,7 +99,7 @@ static __init int system_trusted_keyring_init(void)
9899

99100
builtin_trusted_keys =
100101
keyring_alloc(".builtin_trusted_keys",
101-
KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
102+
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
102103
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
103104
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH),
104105
KEY_ALLOC_NOT_IN_QUOTA,
@@ -109,7 +110,7 @@ static __init int system_trusted_keyring_init(void)
109110
#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
110111
secondary_trusted_keys =
111112
keyring_alloc(".secondary_trusted_keys",
112-
KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
113+
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
113114
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
114115
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH |
115116
KEY_USR_WRITE),

crypto/asymmetric_keys/asymmetric_type.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ EXPORT_SYMBOL_GPL(asymmetric_key_generate_id);
152152

153153
/**
154154
* asymmetric_key_id_same - Return true if two asymmetric keys IDs are the same.
155-
* @kid_1, @kid_2: The key IDs to compare
155+
* @kid1: The key ID to compare
156+
* @kid2: The key ID to compare
156157
*/
157158
bool asymmetric_key_id_same(const struct asymmetric_key_id *kid1,
158159
const struct asymmetric_key_id *kid2)
@@ -168,7 +169,8 @@ EXPORT_SYMBOL_GPL(asymmetric_key_id_same);
168169
/**
169170
* asymmetric_key_id_partial - Return true if two asymmetric keys IDs
170171
* partially match
171-
* @kid_1, @kid_2: The key IDs to compare
172+
* @kid1: The key ID to compare
173+
* @kid2: The key ID to compare
172174
*/
173175
bool asymmetric_key_id_partial(const struct asymmetric_key_id *kid1,
174176
const struct asymmetric_key_id *kid2)

crypto/asymmetric_keys/pkcs7_parser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ struct pkcs7_signed_info {
4141
*
4242
* This contains the generated digest of _either_ the Content Data or
4343
* the Authenticated Attributes [RFC2315 9.3]. If the latter, one of
44-
* the attributes contains the digest of the the Content Data within
45-
* it.
44+
* the attributes contains the digest of the Content Data within it.
4645
*
47-
* THis also contains the issuing cert serial number and issuer's name
46+
* This also contains the issuing cert serial number and issuer's name
4847
* [PKCS#7 or CMS ver 1] or issuing cert's SKID [CMS ver 3].
4948
*/
5049
struct public_key_signature *sig;

crypto/asymmetric_keys/pkcs7_trust.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <crypto/public_key.h>
1717
#include "pkcs7_parser.h"
1818

19-
/**
19+
/*
2020
* Check the trust on one PKCS#7 SignedInfo block.
2121
*/
2222
static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,

crypto/asymmetric_keys/pkcs7_verify.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
141141
*buf = sinfo->sig->digest;
142142
*len = sinfo->sig->digest_size;
143143

144-
for (i = 0; i < HASH_ALGO__LAST; i++)
145-
if (!strcmp(hash_algo_name[i], sinfo->sig->hash_algo)) {
146-
*hash_algo = i;
147-
break;
148-
}
144+
i = match_string(hash_algo_name, HASH_ALGO__LAST,
145+
sinfo->sig->hash_algo);
146+
if (i >= 0)
147+
*hash_algo = i;
149148

150149
return 0;
151150
}

include/crypto/public_key.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <linux/keyctl.h>
1414
#include <linux/oid_registry.h>
15-
#include <crypto/akcipher.h>
1615

1716
/*
1817
* Cryptographic data for the public-key subtype of the asymmetric key type.

include/keys/encrypted-type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Copyright (C) 2010 IBM Corporation
44
* Copyright (C) 2010 Politecnico di Torino, Italy
5-
* TORSEC group -- http://security.polito.it
5+
* TORSEC group -- https://security.polito.it
66
*
77
* Authors:
88
* Mimi Zohar <[email protected]>

include/linux/key.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ extern struct key *key_alloc(struct key_type *type,
289289
#define KEY_ALLOC_BUILT_IN 0x0004 /* Key is built into kernel */
290290
#define KEY_ALLOC_BYPASS_RESTRICTION 0x0008 /* Override the check on restricted keyrings */
291291
#define KEY_ALLOC_UID_KEYRING 0x0010 /* allocating a user or user session keyring */
292+
#define KEY_ALLOC_SET_KEEP 0x0020 /* Set the KEEP flag on the key/keyring */
292293

293294
extern void key_revoke(struct key *key);
294295
extern void key_invalidate(struct key *key);
@@ -360,7 +361,7 @@ static inline struct key *request_key(struct key_type *type,
360361
* completion of keys undergoing construction with a non-interruptible wait.
361362
*/
362363
#define request_key_net(type, description, net, callout_info) \
363-
request_key_tag(type, description, net->key_domain, callout_info);
364+
request_key_tag(type, description, net->key_domain, callout_info)
364365

365366
/**
366367
* request_key_net_rcu - Request a key for a net namespace under RCU conditions
@@ -372,7 +373,7 @@ static inline struct key *request_key(struct key_type *type,
372373
* network namespace are used.
373374
*/
374375
#define request_key_net_rcu(type, description, net) \
375-
request_key_rcu(type, description, net->key_domain);
376+
request_key_rcu(type, description, net->key_domain)
376377
#endif /* CONFIG_NET */
377378

378379
extern int wait_for_key_construction(struct key *key, bool intr);

include/linux/verification.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef _LINUX_VERIFICATION_H
99
#define _LINUX_VERIFICATION_H
1010

11+
#include <linux/types.h>
12+
1113
/*
1214
* Indicate that both builtin trusted keys and secondary trusted keys
1315
* should be used.

kernel/watch_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static void put_watch(struct watch *watch)
413413
}
414414

415415
/**
416-
* init_watch_queue - Initialise a watch
416+
* init_watch - Initialise a watch
417417
* @watch: The watch to initialise.
418418
* @wqueue: The queue to assign.
419419
*

samples/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ config SAMPLE_WATCHDOG
210210
depends on CC_CAN_LINK
211211

212212
config SAMPLE_WATCH_QUEUE
213-
bool "Build example /dev/watch_queue notification consumer"
213+
bool "Build example watch_queue notification API consumer"
214214
depends on CC_CAN_LINK && HEADERS_INSTALL
215215
help
216216
Build example userspace program to use the new mount_notify(),

samples/watch_queue/watch_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
/* Use /dev/watch_queue to watch for notifications.
2+
/* Use watch_queue API to watch for notifications.
33
*
44
* Copyright (C) 2020 Red Hat, Inc. All Rights Reserved.
55
* Written by David Howells ([email protected])

security/integrity/ima/ima_mok.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ __init int ima_mok_init(void)
3838
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
3939
KEY_USR_VIEW | KEY_USR_READ |
4040
KEY_USR_WRITE | KEY_USR_SEARCH,
41-
KEY_ALLOC_NOT_IN_QUOTA,
41+
KEY_ALLOC_NOT_IN_QUOTA |
42+
KEY_ALLOC_SET_KEEP,
4243
restriction, NULL);
4344

4445
if (IS_ERR(ima_blacklist_keyring))
4546
panic("Can't allocate IMA blacklist keyring.");
46-
47-
set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags);
4847
return 0;
4948
}
5049
device_initcall(ima_mok_init);

security/keys/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ config KEY_NOTIFICATIONS
119119
bool "Provide key/keyring change notifications"
120120
depends on KEYS && WATCH_QUEUE
121121
help
122-
This option provides support for getting change notifications on keys
123-
and keyrings on which the caller has View permission. This makes use
124-
of the /dev/watch_queue misc device to handle the notification
125-
buffer and provides KEYCTL_WATCH_KEY to enable/disable watches.
122+
This option provides support for getting change notifications
123+
on keys and keyrings on which the caller has View permission.
124+
This makes use of pipes to handle the notification buffer and
125+
provides KEYCTL_WATCH_KEY to enable/disable watches.

security/keys/big_key.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
121121
*path = file->f_path;
122122
path_get(path);
123123
fput(file);
124-
memzero_explicit(buf, enclen);
125-
kvfree(buf);
124+
kvfree_sensitive(buf, enclen);
126125
} else {
127126
/* Just store the data in a buffer */
128127
void *data = kmalloc(datalen, GFP_KERNEL);
@@ -140,8 +139,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
140139
err_enckey:
141140
kfree_sensitive(enckey);
142141
error:
143-
memzero_explicit(buf, enclen);
144-
kvfree(buf);
142+
kvfree_sensitive(buf, enclen);
145143
return ret;
146144
}
147145

@@ -273,8 +271,7 @@ long big_key_read(const struct key *key, char *buffer, size_t buflen)
273271
err_fput:
274272
fput(file);
275273
error:
276-
memzero_explicit(buf, enclen);
277-
kvfree(buf);
274+
kvfree_sensitive(buf, enclen);
278275
} else {
279276
ret = datalen;
280277
memcpy(buffer, key->payload.data[big_key_data], datalen);

security/keys/key.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
303303
key->flags |= 1 << KEY_FLAG_BUILTIN;
304304
if (flags & KEY_ALLOC_UID_KEYRING)
305305
key->flags |= 1 << KEY_FLAG_UID_KEYRING;
306+
if (flags & KEY_ALLOC_SET_KEEP)
307+
key->flags |= 1 << KEY_FLAG_KEEP;
306308

307309
#ifdef KEY_DEBUGGING
308310
key->magic = KEY_DEBUG_MAGIC;

security/keys/keyctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ long keyctl_keyring_clear(key_serial_t ringid)
506506
* keyring, otherwise replace the link to the matching key with a link to the
507507
* new key.
508508
*
509-
* The key must grant the caller Link permission and the the keyring must grant
509+
* The key must grant the caller Link permission and the keyring must grant
510510
* the caller Write permission. Furthermore, if an additional link is created,
511511
* the keyring's quota will be extended.
512512
*

security/keys/keyctl_pkey.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ long keyctl_pkey_query(key_serial_t id,
166166
struct kernel_pkey_query res;
167167
long ret;
168168

169-
memset(&params, 0, sizeof(params));
170-
171169
ret = keyctl_pkey_params_get(id, _info, &params);
172170
if (ret < 0)
173171
goto error;

security/keys/keyring.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ static void keyring_describe(const struct key *keyring, struct seq_file *m)
452452
struct keyring_read_iterator_context {
453453
size_t buflen;
454454
size_t count;
455-
key_serial_t __user *buffer;
455+
key_serial_t *buffer;
456456
};
457457

458458
static int keyring_read_iterator(const void *object, void *data)
@@ -479,7 +479,7 @@ static int keyring_read_iterator(const void *object, void *data)
479479
* times.
480480
*/
481481
static long keyring_read(const struct key *keyring,
482-
char __user *buffer, size_t buflen)
482+
char *buffer, size_t buflen)
483483
{
484484
struct keyring_read_iterator_context ctx;
485485
long ret;
@@ -491,7 +491,7 @@ static long keyring_read(const struct key *keyring,
491491

492492
/* Copy as many key IDs as fit into the buffer */
493493
if (buffer && buflen) {
494-
ctx.buffer = (key_serial_t __user *)buffer;
494+
ctx.buffer = (key_serial_t *)buffer;
495495
ctx.buflen = buflen;
496496
ctx.count = 0;
497497
ret = assoc_array_iterate(&keyring->keys,
@@ -881,7 +881,7 @@ static bool search_nested_keyrings(struct key *keyring,
881881
*
882882
* Keys are matched to the type provided and are then filtered by the match
883883
* function, which is given the description to use in any way it sees fit. The
884-
* match function may use any attributes of a key that it wishes to to
884+
* match function may use any attributes of a key that it wishes to
885885
* determine the match. Normally the match function from the key type would be
886886
* used.
887887
*
@@ -1204,7 +1204,7 @@ static int keyring_detect_cycle_iterator(const void *object,
12041204
}
12051205

12061206
/*
1207-
* See if a cycle will will be created by inserting acyclic tree B in acyclic
1207+
* See if a cycle will be created by inserting acyclic tree B in acyclic
12081208
* tree A at the topmost level (ie: as a direct child of A).
12091209
*
12101210
* Since we are adding B to A at the top level, checking for cycles should just

security/keys/process_keys.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ key_ref_t lookup_user_key(key_serial_t id, unsigned long lflags,
783783
if (need_perm != KEY_AUTHTOKEN_OVERRIDE &&
784784
need_perm != KEY_DEFER_PERM_CHECK)
785785
goto invalid_key;
786+
break;
786787
case 0:
787788
break;
788789
}

0 commit comments

Comments
 (0)