Skip to content

Commit 5dec682

Browse files
committed
Merge tag 'keys-devel-20131210' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
Pull misc keyrings fixes from David Howells: "These break down into five sets: - A patch to error handling in the big_key type for huge payloads. If the payload is larger than the "low limit" and the backing store allocation fails, then big_key_instantiate() doesn't clear the payload pointers in the key, assuming them to have been previously cleared - but only one of them is. Unfortunately, the garbage collector still calls big_key_destroy() when sees one of the pointers with a weird value in it (and not NULL) which it then tries to clean up. - Three patches to fix the keyring type: * A patch to fix the hash function to correctly divide keyrings off from keys in the topology of the tree inside the associative array. This is only a problem if searching through nested keyrings - and only if the hash function incorrectly puts the a keyring outside of the 0 branch of the root node. * A patch to fix keyrings' use of the associative array. The __key_link_begin() function initially passes a NULL key pointer to assoc_array_insert() on the basis that it's holding a place in the tree whilst it does more allocation and stuff. This is only a problem when a node contains 16 keys that match at that level and we want to add an also matching 17th. This should easily be manufactured with a keyring full of keyrings (without chucking any other sort of key into the mix) - except for (a) above which makes it on average adding the 65th keyring. * A patch to fix searching down through nested keyrings, where any keyring in the set has more than 16 keyrings and none of the first keyrings we look through has a match (before the tree iteration needs to step to a more distal node). Test in keyutils test suite: http://git.kernel.org/cgit/linux/kernel/git/dhowells/keyutils.git/commit/?id=8b4ae963ed92523aea18dfbb8cab3f4979e13bd1 - A patch to fix the big_key type's use of a shmem file as its backing store causing audit messages and LSM check failures. This is done by setting S_PRIVATE on the file to avoid LSM checks on the file (access to the shmem file goes through the keyctl() interface and so is gated by the LSM that way). This isn't normally a problem if a key is used by the context that generated it - and it's currently only used by libkrb5. Test in keyutils test suite: http://git.kernel.org/cgit/linux/kernel/git/dhowells/keyutils.git/commit/?id=d9a53cbab42c293962f2f78f7190253fc73bd32e - A patch to add a generated file to .gitignore. - A patch to fix the alignment of the system certificate data such that it it works on s390. As I understand it, on the S390 arch, symbols must be 2-byte aligned because loading the address discards the least-significant bit" * tag 'keys-devel-20131210' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: KEYS: correct alignment of system_certificate_list content in assembly file Ignore generated file kernel/x509_certificate_list security: shmem: implement kernel private shmem inodes KEYS: Fix searching of nested keyrings KEYS: Fix multiple key add into associative array KEYS: Fix the keyring hash function KEYS: Pre-clear struct key on allocation
2 parents 48a2f0b + 6222698 commit 5dec682

11 files changed

Lines changed: 64 additions & 36 deletions

File tree

‎Documentation/assoc_array.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ This points to a number of methods, all of which need to be provided:
164164

165165
(4) Diff the index keys of two objects.
166166

167-
int (*diff_objects)(const void *a, const void *b);
167+
int (*diff_objects)(const void *object, const void *index_key);
168168

169-
Return the bit position at which the index keys of two objects differ or
170-
-1 if they are the same.
169+
Return the bit position at which the index key of the specified object
170+
differs from the given index key or -1 if they are the same.
171171

172172

173173
(5) Free an object.

‎include/linux/assoc_array.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ struct assoc_array_ops {
4141
/* Is this the object we're looking for? */
4242
bool (*compare_object)(const void *object, const void *index_key);
4343

44-
/* How different are two objects, to a bit position in their keys? (or
45-
* -1 if they're the same)
44+
/* How different is an object from an index key, to a bit position in
45+
* their keys? (or -1 if they're the same)
4646
*/
47-
int (*diff_objects)(const void *a, const void *b);
47+
int (*diff_objects)(const void *object, const void *index_key);
4848

4949
/* Method to free an object. */
5050
void (*free_object)(void *object);

‎include/linux/shmem_fs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ extern int shmem_init(void);
4747
extern int shmem_fill_super(struct super_block *sb, void *data, int silent);
4848
extern struct file *shmem_file_setup(const char *name,
4949
loff_t size, unsigned long flags);
50+
extern struct file *shmem_kernel_file_setup(const char *name, loff_t size,
51+
unsigned long flags);
5052
extern int shmem_zero_setup(struct vm_area_struct *);
5153
extern int shmem_lock(struct file *file, int lock, struct user_struct *user);
5254
extern void shmem_unlock_mapping(struct address_space *mapping);

‎kernel/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ config_data.h
55
config_data.gz
66
timeconst.h
77
hz.bc
8+
x509_certificate_list

‎kernel/system_certificates.S‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33

44
__INITRODATA
55

6+
.align 8
67
.globl VMLINUX_SYMBOL(system_certificate_list)
78
VMLINUX_SYMBOL(system_certificate_list):
9+
__cert_list_start:
810
.incbin "kernel/x509_certificate_list"
9-
.globl VMLINUX_SYMBOL(system_certificate_list_end)
10-
VMLINUX_SYMBOL(system_certificate_list_end):
11+
__cert_list_end:
12+
13+
.align 8
14+
.globl VMLINUX_SYMBOL(system_certificate_list_size)
15+
VMLINUX_SYMBOL(system_certificate_list_size):
16+
#ifdef CONFIG_64BIT
17+
.quad __cert_list_end - __cert_list_start
18+
#else
19+
.long __cert_list_end - __cert_list_start
20+
#endif

‎kernel/system_keyring.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct key *system_trusted_keyring;
2222
EXPORT_SYMBOL_GPL(system_trusted_keyring);
2323

2424
extern __initconst const u8 system_certificate_list[];
25-
extern __initconst const u8 system_certificate_list_end[];
25+
extern __initconst const unsigned long system_certificate_list_size;
2626

2727
/*
2828
* Load the compiled-in keys
@@ -60,8 +60,8 @@ static __init int load_system_certificate_list(void)
6060

6161
pr_notice("Loading compiled-in X.509 certificates\n");
6262

63-
end = system_certificate_list_end;
6463
p = system_certificate_list;
64+
end = p + system_certificate_list_size;
6565
while (p < end) {
6666
/* Each cert begins with an ASN.1 SEQUENCE tag and must be more
6767
* than 256 bytes in size.

‎lib/assoc_array.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,8 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,
759759
pr_devel("all leaves cluster together\n");
760760
diff = INT_MAX;
761761
for (i = 0; i < ASSOC_ARRAY_FAN_OUT; i++) {
762-
int x = ops->diff_objects(assoc_array_ptr_to_leaf(edit->leaf),
763-
assoc_array_ptr_to_leaf(node->slots[i]));
762+
int x = ops->diff_objects(assoc_array_ptr_to_leaf(node->slots[i]),
763+
index_key);
764764
if (x < diff) {
765765
BUG_ON(x < 0);
766766
diff = x;

‎mm/shmem.c‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,13 +2918,8 @@ static struct dentry_operations anon_ops = {
29182918
.d_dname = simple_dname
29192919
};
29202920

2921-
/**
2922-
* shmem_file_setup - get an unlinked file living in tmpfs
2923-
* @name: name for dentry (to be seen in /proc/<pid>/maps
2924-
* @size: size to be set for the file
2925-
* @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
2926-
*/
2927-
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
2921+
static struct file *__shmem_file_setup(const char *name, loff_t size,
2922+
unsigned long flags, unsigned int i_flags)
29282923
{
29292924
struct file *res;
29302925
struct inode *inode;
@@ -2957,6 +2952,7 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
29572952
if (!inode)
29582953
goto put_dentry;
29592954

2955+
inode->i_flags |= i_flags;
29602956
d_instantiate(path.dentry, inode);
29612957
inode->i_size = size;
29622958
clear_nlink(inode); /* It is unlinked */
@@ -2977,6 +2973,32 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
29772973
shmem_unacct_size(flags, size);
29782974
return res;
29792975
}
2976+
2977+
/**
2978+
* shmem_kernel_file_setup - get an unlinked file living in tmpfs which must be
2979+
* kernel internal. There will be NO LSM permission checks against the
2980+
* underlying inode. So users of this interface must do LSM checks at a
2981+
* higher layer. The one user is the big_key implementation. LSM checks
2982+
* are provided at the key level rather than the inode level.
2983+
* @name: name for dentry (to be seen in /proc/<pid>/maps
2984+
* @size: size to be set for the file
2985+
* @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
2986+
*/
2987+
struct file *shmem_kernel_file_setup(const char *name, loff_t size, unsigned long flags)
2988+
{
2989+
return __shmem_file_setup(name, size, flags, S_PRIVATE);
2990+
}
2991+
2992+
/**
2993+
* shmem_file_setup - get an unlinked file living in tmpfs
2994+
* @name: name for dentry (to be seen in /proc/<pid>/maps
2995+
* @size: size to be set for the file
2996+
* @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
2997+
*/
2998+
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
2999+
{
3000+
return __shmem_file_setup(name, size, flags, 0);
3001+
}
29803002
EXPORT_SYMBOL_GPL(shmem_file_setup);
29813003

29823004
/**

‎security/keys/big_key.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int big_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
7070
*
7171
* TODO: Encrypt the stored data with a temporary key.
7272
*/
73-
file = shmem_file_setup("", datalen, 0);
73+
file = shmem_kernel_file_setup("", datalen, 0);
7474
if (IS_ERR(file)) {
7575
ret = PTR_ERR(file);
7676
goto err_quota;

‎security/keys/key.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
272272
}
273273

274274
/* allocate and initialise the key and its description */
275-
key = kmem_cache_alloc(key_jar, GFP_KERNEL);
275+
key = kmem_cache_zalloc(key_jar, GFP_KERNEL);
276276
if (!key)
277277
goto no_memory_2;
278278

@@ -293,18 +293,12 @@ struct key *key_alloc(struct key_type *type, const char *desc,
293293
key->uid = uid;
294294
key->gid = gid;
295295
key->perm = perm;
296-
key->flags = 0;
297-
key->expiry = 0;
298-
key->payload.data = NULL;
299-
key->security = NULL;
300296

301297
if (!(flags & KEY_ALLOC_NOT_IN_QUOTA))
302298
key->flags |= 1 << KEY_FLAG_IN_QUOTA;
303299
if (flags & KEY_ALLOC_TRUSTED)
304300
key->flags |= 1 << KEY_FLAG_TRUSTED;
305301

306-
memset(&key->type_data, 0, sizeof(key->type_data));
307-
308302
#ifdef KEY_DEBUGGING
309303
key->magic = KEY_DEBUG_MAGIC;
310304
#endif

0 commit comments

Comments
 (0)