Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] Keys: Export user-defined keyring operations

Export user-defined key operations so that those who wish to define their
own key type based on the user-defined key operations may do so (as has
been requested).

The header file created has been placed into include/keys/user-type.h, thus
creating a directory where other key types may also be placed. Any
objections to doing this?

Signed-Off-By: David Howells <dhowells@redhat.com>
Signed-Off-By: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

David Howells and committed by
Linus Torvalds
2aa349f6 1426d7a8

+71 -25
+47
include/keys/user-type.h
··· 1 + /* user-type.h: User-defined key type 2 + * 3 + * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. 4 + * Written by David Howells (dhowells@redhat.com) 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License 8 + * as published by the Free Software Foundation; either version 9 + * 2 of the License, or (at your option) any later version. 10 + */ 11 + 12 + #ifndef _KEYS_USER_TYPE_H 13 + #define _KEYS_USER_TYPE_H 14 + 15 + #include <linux/key.h> 16 + #include <linux/rcupdate.h> 17 + 18 + /*****************************************************************************/ 19 + /* 20 + * the payload for a key of type "user" 21 + * - once filled in and attached to a key: 22 + * - the payload struct is invariant may not be changed, only replaced 23 + * - the payload must be read with RCU procedures or with the key semaphore 24 + * held 25 + * - the payload may only be replaced with the key semaphore write-locked 26 + * - the key's data length is the size of the actual data, not including the 27 + * payload wrapper 28 + */ 29 + struct user_key_payload { 30 + struct rcu_head rcu; /* RCU destructor */ 31 + unsigned short datalen; /* length of this data */ 32 + char data[0]; /* actual data */ 33 + }; 34 + 35 + extern struct key_type key_type_user; 36 + 37 + extern int user_instantiate(struct key *key, const void *data, size_t datalen); 38 + extern int user_duplicate(struct key *key, const struct key *source); 39 + extern int user_update(struct key *key, const void *data, size_t datalen); 40 + extern int user_match(const struct key *key, const void *criterion); 41 + extern void user_destroy(struct key *key); 42 + extern void user_describe(const struct key *user, struct seq_file *m); 43 + extern long user_read(const struct key *key, 44 + char __user *buffer, size_t buflen); 45 + 46 + 47 + #endif /* _KEYS_USER_TYPE_H */
+24 -25
security/keys/user_defined.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/seq_file.h> 17 17 #include <linux/err.h> 18 + #include <keys/user-type.h> 18 19 #include <asm/uaccess.h> 19 20 #include "internal.h" 20 - 21 - static int user_instantiate(struct key *key, const void *data, size_t datalen); 22 - static int user_duplicate(struct key *key, const struct key *source); 23 - static int user_update(struct key *key, const void *data, size_t datalen); 24 - static int user_match(const struct key *key, const void *criterion); 25 - static void user_destroy(struct key *key); 26 - static void user_describe(const struct key *user, struct seq_file *m); 27 - static long user_read(const struct key *key, 28 - char __user *buffer, size_t buflen); 29 21 30 22 /* 31 23 * user defined keys take an arbitrary string as the description and an ··· 34 42 .read = user_read, 35 43 }; 36 44 37 - struct user_key_payload { 38 - struct rcu_head rcu; /* RCU destructor */ 39 - unsigned short datalen; /* length of this data */ 40 - char data[0]; /* actual data */ 41 - }; 42 - 43 45 EXPORT_SYMBOL_GPL(key_type_user); 44 46 45 47 /*****************************************************************************/ 46 48 /* 47 49 * instantiate a user defined key 48 50 */ 49 - static int user_instantiate(struct key *key, const void *data, size_t datalen) 51 + int user_instantiate(struct key *key, const void *data, size_t datalen) 50 52 { 51 53 struct user_key_payload *upayload; 52 54 int ret; ··· 64 78 rcu_assign_pointer(key->payload.data, upayload); 65 79 ret = 0; 66 80 67 - error: 81 + error: 68 82 return ret; 69 83 70 84 } /* end user_instantiate() */ 85 + 86 + EXPORT_SYMBOL_GPL(user_instantiate); 71 87 72 88 /*****************************************************************************/ 73 89 /* ··· 77 89 * - both keys' semaphores are locked against further modification 78 90 * - the new key cannot yet be accessed 79 91 */ 80 - static int user_duplicate(struct key *key, const struct key *source) 92 + int user_duplicate(struct key *key, const struct key *source) 81 93 { 82 94 struct user_key_payload *upayload, *spayload; 83 95 int ret; ··· 100 112 101 113 } /* end user_duplicate() */ 102 114 115 + EXPORT_SYMBOL_GPL(user_duplicate); 116 + 103 117 /*****************************************************************************/ 104 118 /* 105 119 * dispose of the old data from an updated user defined key ··· 121 131 * update a user defined key 122 132 * - the key's semaphore is write-locked 123 133 */ 124 - static int user_update(struct key *key, const void *data, size_t datalen) 134 + int user_update(struct key *key, const void *data, size_t datalen) 125 135 { 126 136 struct user_key_payload *upayload, *zap; 127 137 int ret; ··· 153 163 154 164 call_rcu(&zap->rcu, user_update_rcu_disposal); 155 165 156 - error: 166 + error: 157 167 return ret; 158 168 159 169 } /* end user_update() */ 170 + 171 + EXPORT_SYMBOL_GPL(user_update); 160 172 161 173 /*****************************************************************************/ 162 174 /* 163 175 * match users on their name 164 176 */ 165 - static int user_match(const struct key *key, const void *description) 177 + int user_match(const struct key *key, const void *description) 166 178 { 167 179 return strcmp(key->description, description) == 0; 168 180 169 181 } /* end user_match() */ 170 182 183 + EXPORT_SYMBOL_GPL(user_match); 184 + 171 185 /*****************************************************************************/ 172 186 /* 173 187 * dispose of the data dangling from the corpse of a user 174 188 */ 175 - static void user_destroy(struct key *key) 189 + void user_destroy(struct key *key) 176 190 { 177 191 struct user_key_payload *upayload = key->payload.data; 178 192 ··· 184 190 185 191 } /* end user_destroy() */ 186 192 193 + EXPORT_SYMBOL_GPL(user_destroy); 194 + 187 195 /*****************************************************************************/ 188 196 /* 189 197 * describe the user key 190 198 */ 191 - static void user_describe(const struct key *key, struct seq_file *m) 199 + void user_describe(const struct key *key, struct seq_file *m) 192 200 { 193 201 seq_puts(m, key->description); 194 202 ··· 198 202 199 203 } /* end user_describe() */ 200 204 205 + EXPORT_SYMBOL_GPL(user_describe); 206 + 201 207 /*****************************************************************************/ 202 208 /* 203 209 * read the key data 204 210 * - the key's semaphore is read-locked 205 211 */ 206 - static long user_read(const struct key *key, 207 - char __user *buffer, size_t buflen) 212 + long user_read(const struct key *key, char __user *buffer, size_t buflen) 208 213 { 209 214 struct user_key_payload *upayload; 210 215 long ret; ··· 225 228 return ret; 226 229 227 230 } /* end user_read() */ 231 + 232 + EXPORT_SYMBOL_GPL(user_read);