Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 235096
b: refs/heads/master
c: b9fffa3
h: refs/heads/master
v: v3
  • Loading branch information
David Howells authored and James Morris committed Mar 8, 2011
1 parent bd076a8 commit 23887f9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 633e804e89464d3875e59de1959a53f9041d3094
refs/heads/master: b9fffa3877a3ebbe0a5ad5a247358e2f7df15b24
7 changes: 7 additions & 0 deletions trunk/Documentation/keys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,13 @@ The structure has a number of fields, some of which are mandatory:
viable.


(*) int (*vet_description)(const char *description);

This optional method is called to vet a key description. If the key type
doesn't approve of the key description, it may return an error, otherwise
it should return 0.


(*) int (*instantiate)(struct key *key, const void *data, size_t datalen);

This method is called to attach a payload to a key during construction.
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/key-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct key_type {
*/
size_t def_datalen;

/* vet a description */
int (*vet_description)(const char *description);

/* instantiate a key of this type
* - this method should call key_payload_reserve() to determine if the
* user's quota will hold the payload
Expand Down
19 changes: 19 additions & 0 deletions trunk/net/rxrpc/ar-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <keys/user-type.h>
#include "ar-internal.h"

static int rxrpc_vet_description_s(const char *);
static int rxrpc_instantiate(struct key *, const void *, size_t);
static int rxrpc_instantiate_s(struct key *, const void *, size_t);
static void rxrpc_destroy(struct key *);
Expand Down Expand Up @@ -52,12 +53,30 @@ EXPORT_SYMBOL(key_type_rxrpc);
*/
struct key_type key_type_rxrpc_s = {
.name = "rxrpc_s",
.vet_description = rxrpc_vet_description_s,
.instantiate = rxrpc_instantiate_s,
.match = user_match,
.destroy = rxrpc_destroy_s,
.describe = rxrpc_describe,
};

/*
* Vet the description for an RxRPC server key
*/
static int rxrpc_vet_description_s(const char *desc)
{
unsigned long num;
char *p;

num = simple_strtoul(desc, &p, 10);
if (*p != ':' || num > 65535)
return -EINVAL;
num = simple_strtoul(p + 1, &p, 10);
if (*p || num < 1 || num > 255)
return -EINVAL;
return 0;
}

/*
* parse an RxKAD type XDR format token
* - the caller guarantees we have at least 4 words
Expand Down
8 changes: 8 additions & 0 deletions trunk/security/keys/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ struct key *key_alloc(struct key_type *type, const char *desc,
if (!desc || !*desc)
goto error;

if (type->vet_description) {
ret = type->vet_description(desc);
if (ret < 0) {
key = ERR_PTR(ret);
goto error;
}
}

desclen = strlen(desc) + 1;
quotalen = desclen + type->def_datalen;

Expand Down

0 comments on commit 23887f9

Please sign in to comment.