Skip to content

Commit 2aa349f

Browse files
dhowellsLinus Torvalds
authored andcommitted
[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>
1 parent 1426d7a commit 2aa349f

File tree

2 files changed

+71
-25
lines changed

2 files changed

+71
-25
lines changed

include/keys/user-type.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 */

security/keys/user_defined.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@
1515
#include <linux/slab.h>
1616
#include <linux/seq_file.h>
1717
#include <linux/err.h>
18+
#include <keys/user-type.h>
1819
#include <asm/uaccess.h>
1920
#include "internal.h"
2021

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-
3022
/*
3123
* user defined keys take an arbitrary string as the description and an
3224
* arbitrary blob of data as the payload
@@ -42,19 +34,13 @@ struct key_type key_type_user = {
4234
.read = user_read,
4335
};
4436

45-
struct user_key_payload {
46-
struct rcu_head rcu; /* RCU destructor */
47-
unsigned short datalen; /* length of this data */
48-
char data[0]; /* actual data */
49-
};
50-
5137
EXPORT_SYMBOL_GPL(key_type_user);
5238

5339
/*****************************************************************************/
5440
/*
5541
* instantiate a user defined key
5642
*/
57-
static int user_instantiate(struct key *key, const void *data, size_t datalen)
43+
int user_instantiate(struct key *key, const void *data, size_t datalen)
5844
{
5945
struct user_key_payload *upayload;
6046
int ret;
@@ -78,18 +64,20 @@ static int user_instantiate(struct key *key, const void *data, size_t datalen)
7864
rcu_assign_pointer(key->payload.data, upayload);
7965
ret = 0;
8066

81-
error:
67+
error:
8268
return ret;
8369

8470
} /* end user_instantiate() */
8571

72+
EXPORT_SYMBOL_GPL(user_instantiate);
73+
8674
/*****************************************************************************/
8775
/*
8876
* duplicate a user defined key
8977
* - both keys' semaphores are locked against further modification
9078
* - the new key cannot yet be accessed
9179
*/
92-
static int user_duplicate(struct key *key, const struct key *source)
80+
int user_duplicate(struct key *key, const struct key *source)
9381
{
9482
struct user_key_payload *upayload, *spayload;
9583
int ret;
@@ -112,6 +100,8 @@ static int user_duplicate(struct key *key, const struct key *source)
112100

113101
} /* end user_duplicate() */
114102

103+
EXPORT_SYMBOL_GPL(user_duplicate);
104+
115105
/*****************************************************************************/
116106
/*
117107
* dispose of the old data from an updated user defined key
@@ -131,7 +121,7 @@ static void user_update_rcu_disposal(struct rcu_head *rcu)
131121
* update a user defined key
132122
* - the key's semaphore is write-locked
133123
*/
134-
static int user_update(struct key *key, const void *data, size_t datalen)
124+
int user_update(struct key *key, const void *data, size_t datalen)
135125
{
136126
struct user_key_payload *upayload, *zap;
137127
int ret;
@@ -163,52 +153,59 @@ static int user_update(struct key *key, const void *data, size_t datalen)
163153

164154
call_rcu(&zap->rcu, user_update_rcu_disposal);
165155

166-
error:
156+
error:
167157
return ret;
168158

169159
} /* end user_update() */
170160

161+
EXPORT_SYMBOL_GPL(user_update);
162+
171163
/*****************************************************************************/
172164
/*
173165
* match users on their name
174166
*/
175-
static int user_match(const struct key *key, const void *description)
167+
int user_match(const struct key *key, const void *description)
176168
{
177169
return strcmp(key->description, description) == 0;
178170

179171
} /* end user_match() */
180172

173+
EXPORT_SYMBOL_GPL(user_match);
174+
181175
/*****************************************************************************/
182176
/*
183177
* dispose of the data dangling from the corpse of a user
184178
*/
185-
static void user_destroy(struct key *key)
179+
void user_destroy(struct key *key)
186180
{
187181
struct user_key_payload *upayload = key->payload.data;
188182

189183
kfree(upayload);
190184

191185
} /* end user_destroy() */
192186

187+
EXPORT_SYMBOL_GPL(user_destroy);
188+
193189
/*****************************************************************************/
194190
/*
195191
* describe the user key
196192
*/
197-
static void user_describe(const struct key *key, struct seq_file *m)
193+
void user_describe(const struct key *key, struct seq_file *m)
198194
{
199195
seq_puts(m, key->description);
200196

201197
seq_printf(m, ": %u", key->datalen);
202198

203199
} /* end user_describe() */
204200

201+
EXPORT_SYMBOL_GPL(user_describe);
202+
205203
/*****************************************************************************/
206204
/*
207205
* read the key data
208206
* - the key's semaphore is read-locked
209207
*/
210-
static long user_read(const struct key *key,
211-
char __user *buffer, size_t buflen)
208+
long user_read(const struct key *key, char __user *buffer, size_t buflen)
212209
{
213210
struct user_key_payload *upayload;
214211
long ret;
@@ -228,3 +225,5 @@ static long user_read(const struct key *key,
228225
return ret;
229226

230227
} /* end user_read() */
228+
229+
EXPORT_SYMBOL_GPL(user_read);

0 commit comments

Comments
 (0)