Skip to content

Commit ca7fb10

Browse files
committed
rxrpc: Split the server key type (rxrpc_s) into its own file
Split the server private key type (rxrpc_s) out into its own file rather than mingling it with the authentication/client key type (rxrpc) since they don't really bear any relation. Signed-off-by: David Howells <[email protected]>
1 parent ec832bd commit ca7fb10

File tree

4 files changed

+149
-127
lines changed

4 files changed

+149
-127
lines changed

net/rxrpc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rxrpc-y := \
2828
rtt.o \
2929
security.o \
3030
sendmsg.o \
31+
server_key.o \
3132
skbuff.o \
3233
utils.o
3334

net/rxrpc/ar-internal.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,8 @@ extern const struct rxrpc_security rxrpc_no_security;
906906
* key.c
907907
*/
908908
extern struct key_type key_type_rxrpc;
909-
extern struct key_type key_type_rxrpc_s;
910909

911910
int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
912-
int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
913911
int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
914912
u32);
915913

@@ -1064,6 +1062,13 @@ struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
10641062
*/
10651063
int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
10661064

1065+
/*
1066+
* server_key.c
1067+
*/
1068+
extern struct key_type key_type_rxrpc_s;
1069+
1070+
int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1071+
10671072
/*
10681073
* skbuff.c
10691074
*/

net/rxrpc/key.c

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@
2323
#include <keys/user-type.h>
2424
#include "ar-internal.h"
2525

26-
static int rxrpc_vet_description_s(const char *);
2726
static int rxrpc_preparse(struct key_preparsed_payload *);
28-
static int rxrpc_preparse_s(struct key_preparsed_payload *);
2927
static void rxrpc_free_preparse(struct key_preparsed_payload *);
30-
static void rxrpc_free_preparse_s(struct key_preparsed_payload *);
3128
static void rxrpc_destroy(struct key *);
32-
static void rxrpc_destroy_s(struct key *);
3329
static void rxrpc_describe(const struct key *, struct seq_file *);
34-
static void rxrpc_describe_s(const struct key *, struct seq_file *);
3530
static long rxrpc_read(const struct key *, char *, size_t);
3631

3732
/*
@@ -50,38 +45,6 @@ struct key_type key_type_rxrpc = {
5045
};
5146
EXPORT_SYMBOL(key_type_rxrpc);
5247

53-
/*
54-
* rxrpc server defined keys take "<serviceId>:<securityIndex>" as the
55-
* description and an 8-byte decryption key as the payload
56-
*/
57-
struct key_type key_type_rxrpc_s = {
58-
.name = "rxrpc_s",
59-
.flags = KEY_TYPE_NET_DOMAIN,
60-
.vet_description = rxrpc_vet_description_s,
61-
.preparse = rxrpc_preparse_s,
62-
.free_preparse = rxrpc_free_preparse_s,
63-
.instantiate = generic_key_instantiate,
64-
.destroy = rxrpc_destroy_s,
65-
.describe = rxrpc_describe_s,
66-
};
67-
68-
/*
69-
* Vet the description for an RxRPC server key
70-
*/
71-
static int rxrpc_vet_description_s(const char *desc)
72-
{
73-
unsigned long num;
74-
char *p;
75-
76-
num = simple_strtoul(desc, &p, 10);
77-
if (*p != ':' || num > 65535)
78-
return -EINVAL;
79-
num = simple_strtoul(p + 1, &p, 10);
80-
if (*p || num < 1 || num > 255)
81-
return -EINVAL;
82-
return 0;
83-
}
84-
8548
/*
8649
* parse an RxKAD type XDR format token
8750
* - the caller guarantees we have at least 4 words
@@ -433,45 +396,6 @@ static void rxrpc_free_preparse(struct key_preparsed_payload *prep)
433396
rxrpc_free_token_list(prep->payload.data[0]);
434397
}
435398

436-
/*
437-
* Preparse a server secret key.
438-
*
439-
* The data should be the 8-byte secret key.
440-
*/
441-
static int rxrpc_preparse_s(struct key_preparsed_payload *prep)
442-
{
443-
struct crypto_skcipher *ci;
444-
445-
_enter("%zu", prep->datalen);
446-
447-
if (prep->datalen != 8)
448-
return -EINVAL;
449-
450-
memcpy(&prep->payload.data[2], prep->data, 8);
451-
452-
ci = crypto_alloc_skcipher("pcbc(des)", 0, CRYPTO_ALG_ASYNC);
453-
if (IS_ERR(ci)) {
454-
_leave(" = %ld", PTR_ERR(ci));
455-
return PTR_ERR(ci);
456-
}
457-
458-
if (crypto_skcipher_setkey(ci, prep->data, 8) < 0)
459-
BUG();
460-
461-
prep->payload.data[0] = ci;
462-
_leave(" = 0");
463-
return 0;
464-
}
465-
466-
/*
467-
* Clean up preparse data.
468-
*/
469-
static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep)
470-
{
471-
if (prep->payload.data[0])
472-
crypto_free_skcipher(prep->payload.data[0]);
473-
}
474-
475399
/*
476400
* dispose of the data dangling from the corpse of a rxrpc key
477401
*/
@@ -480,17 +404,6 @@ static void rxrpc_destroy(struct key *key)
480404
rxrpc_free_token_list(key->payload.data[0]);
481405
}
482406

483-
/*
484-
* dispose of the data dangling from the corpse of a rxrpc key
485-
*/
486-
static void rxrpc_destroy_s(struct key *key)
487-
{
488-
if (key->payload.data[0]) {
489-
crypto_free_skcipher(key->payload.data[0]);
490-
key->payload.data[0] = NULL;
491-
}
492-
}
493-
494407
/*
495408
* describe the rxrpc key
496409
*/
@@ -517,14 +430,6 @@ static void rxrpc_describe(const struct key *key, struct seq_file *m)
517430
}
518431
}
519432

520-
/*
521-
* describe the rxrpc server key
522-
*/
523-
static void rxrpc_describe_s(const struct key *key, struct seq_file *m)
524-
{
525-
seq_puts(m, key->description);
526-
}
527-
528433
/*
529434
* grab the security key for a socket
530435
*/
@@ -555,36 +460,6 @@ int rxrpc_request_key(struct rxrpc_sock *rx, sockptr_t optval, int optlen)
555460
return 0;
556461
}
557462

558-
/*
559-
* grab the security keyring for a server socket
560-
*/
561-
int rxrpc_server_keyring(struct rxrpc_sock *rx, sockptr_t optval, int optlen)
562-
{
563-
struct key *key;
564-
char *description;
565-
566-
_enter("");
567-
568-
if (optlen <= 0 || optlen > PAGE_SIZE - 1)
569-
return -EINVAL;
570-
571-
description = memdup_sockptr_nul(optval, optlen);
572-
if (IS_ERR(description))
573-
return PTR_ERR(description);
574-
575-
key = request_key(&key_type_keyring, description, NULL);
576-
if (IS_ERR(key)) {
577-
kfree(description);
578-
_leave(" = %ld", PTR_ERR(key));
579-
return PTR_ERR(key);
580-
}
581-
582-
rx->securities = key;
583-
kfree(description);
584-
_leave(" = 0 [key %x]", key->serial);
585-
return 0;
586-
}
587-
588463
/*
589464
* generate a server data key
590465
*/

net/rxrpc/server_key.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/* RxRPC key management
3+
*
4+
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5+
* Written by David Howells ([email protected])
6+
*
7+
* RxRPC keys should have a description of describing their purpose:
8+
9+
*/
10+
11+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12+
13+
#include <crypto/skcipher.h>
14+
#include <linux/module.h>
15+
#include <linux/net.h>
16+
#include <linux/skbuff.h>
17+
#include <linux/key-type.h>
18+
#include <linux/ctype.h>
19+
#include <linux/slab.h>
20+
#include <net/sock.h>
21+
#include <net/af_rxrpc.h>
22+
#include <keys/rxrpc-type.h>
23+
#include <keys/user-type.h>
24+
#include "ar-internal.h"
25+
26+
static int rxrpc_vet_description_s(const char *);
27+
static int rxrpc_preparse_s(struct key_preparsed_payload *);
28+
static void rxrpc_free_preparse_s(struct key_preparsed_payload *);
29+
static void rxrpc_destroy_s(struct key *);
30+
static void rxrpc_describe_s(const struct key *, struct seq_file *);
31+
32+
/*
33+
* rxrpc server defined keys take "<serviceId>:<securityIndex>" as the
34+
* description and an 8-byte decryption key as the payload
35+
*/
36+
struct key_type key_type_rxrpc_s = {
37+
.name = "rxrpc_s",
38+
.flags = KEY_TYPE_NET_DOMAIN,
39+
.vet_description = rxrpc_vet_description_s,
40+
.preparse = rxrpc_preparse_s,
41+
.free_preparse = rxrpc_free_preparse_s,
42+
.instantiate = generic_key_instantiate,
43+
.destroy = rxrpc_destroy_s,
44+
.describe = rxrpc_describe_s,
45+
};
46+
47+
/*
48+
* Vet the description for an RxRPC server key
49+
*/
50+
static int rxrpc_vet_description_s(const char *desc)
51+
{
52+
unsigned long num;
53+
char *p;
54+
55+
num = simple_strtoul(desc, &p, 10);
56+
if (*p != ':' || num > 65535)
57+
return -EINVAL;
58+
num = simple_strtoul(p + 1, &p, 10);
59+
if (*p || num < 1 || num > 255)
60+
return -EINVAL;
61+
return 0;
62+
}
63+
64+
/*
65+
* Preparse a server secret key.
66+
*
67+
* The data should be the 8-byte secret key.
68+
*/
69+
static int rxrpc_preparse_s(struct key_preparsed_payload *prep)
70+
{
71+
struct crypto_skcipher *ci;
72+
73+
_enter("%zu", prep->datalen);
74+
75+
if (prep->datalen != 8)
76+
return -EINVAL;
77+
78+
memcpy(&prep->payload.data[2], prep->data, 8);
79+
80+
ci = crypto_alloc_skcipher("pcbc(des)", 0, CRYPTO_ALG_ASYNC);
81+
if (IS_ERR(ci)) {
82+
_leave(" = %ld", PTR_ERR(ci));
83+
return PTR_ERR(ci);
84+
}
85+
86+
if (crypto_skcipher_setkey(ci, prep->data, 8) < 0)
87+
BUG();
88+
89+
prep->payload.data[0] = ci;
90+
_leave(" = 0");
91+
return 0;
92+
}
93+
94+
static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep)
95+
{
96+
if (prep->payload.data[0])
97+
crypto_free_skcipher(prep->payload.data[0]);
98+
}
99+
100+
static void rxrpc_destroy_s(struct key *key)
101+
{
102+
if (key->payload.data[0]) {
103+
crypto_free_skcipher(key->payload.data[0]);
104+
key->payload.data[0] = NULL;
105+
}
106+
}
107+
108+
static void rxrpc_describe_s(const struct key *key, struct seq_file *m)
109+
{
110+
seq_puts(m, key->description);
111+
}
112+
113+
/*
114+
* grab the security keyring for a server socket
115+
*/
116+
int rxrpc_server_keyring(struct rxrpc_sock *rx, sockptr_t optval, int optlen)
117+
{
118+
struct key *key;
119+
char *description;
120+
121+
_enter("");
122+
123+
if (optlen <= 0 || optlen > PAGE_SIZE - 1)
124+
return -EINVAL;
125+
126+
description = memdup_sockptr_nul(optval, optlen);
127+
if (IS_ERR(description))
128+
return PTR_ERR(description);
129+
130+
key = request_key(&key_type_keyring, description, NULL);
131+
if (IS_ERR(key)) {
132+
kfree(description);
133+
_leave(" = %ld", PTR_ERR(key));
134+
return PTR_ERR(key);
135+
}
136+
137+
rx->securities = key;
138+
kfree(description);
139+
_leave(" = 0 [key %x]", key->serial);
140+
return 0;
141+
}

0 commit comments

Comments
 (0)