Skip to content

Commit 8323c3a

Browse files
Tommi Virtanenliewegas
authored andcommitted
ceph: Move secret key parsing earlier.
This makes the base64 logic be contained in mount option parsing, and prepares us for replacing the homebew key management with the kernel key retention service. Signed-off-by: Tommi Virtanen <tommi.virtanen@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent fbdb919 commit 8323c3a

9 files changed

Lines changed: 63 additions & 19 deletions

File tree

‎fs/ceph/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt)
353353

354354
if (opt->name)
355355
seq_printf(m, ",name=%s", opt->name);
356-
if (opt->secret)
356+
if (opt->key)
357357
seq_puts(m, ",secret=<hidden>");
358358

359359
if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)

‎include/linux/ceph/auth.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ struct ceph_auth_client {
6767
bool negotiating; /* true if negotiating protocol */
6868
const char *name; /* entity name */
6969
u64 global_id; /* our unique id in system */
70-
const char *secret; /* our secret key */
70+
const struct ceph_crypto_key *key; /* our secret key */
7171
unsigned want_keys; /* which services we want */
7272
};
7373

7474
extern struct ceph_auth_client *ceph_auth_init(const char *name,
75-
const char *secret);
75+
const struct ceph_crypto_key *key);
7676
extern void ceph_auth_destroy(struct ceph_auth_client *ac);
7777

7878
extern void ceph_auth_reset(struct ceph_auth_client *ac);

‎include/linux/ceph/libceph.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct ceph_options {
6161
pointer type of args */
6262
int num_mon;
6363
char *name;
64-
char *secret;
64+
struct ceph_crypto_key *key;
6565
};
6666

6767
/*

‎net/ceph/auth.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ static int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol)
3535
/*
3636
* setup, teardown.
3737
*/
38-
struct ceph_auth_client *ceph_auth_init(const char *name, const char *secret)
38+
struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_crypto_key *key)
3939
{
4040
struct ceph_auth_client *ac;
4141
int ret;
4242

43-
dout("auth_init name '%s' secret '%s'\n", name, secret);
43+
dout("auth_init name '%s'\n", name);
4444

4545
ret = -ENOMEM;
4646
ac = kzalloc(sizeof(*ac), GFP_NOFS);
@@ -52,8 +52,8 @@ struct ceph_auth_client *ceph_auth_init(const char *name, const char *secret)
5252
ac->name = name;
5353
else
5454
ac->name = CEPH_AUTH_NAME_DEFAULT;
55-
dout("auth_init name %s secret %s\n", ac->name, secret);
56-
ac->secret = secret;
55+
dout("auth_init name %s\n", ac->name);
56+
ac->key = key;
5757
return ac;
5858

5959
out:

‎net/ceph/auth_x.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,16 @@ int ceph_x_init(struct ceph_auth_client *ac)
662662
goto out;
663663

664664
ret = -EINVAL;
665-
if (!ac->secret) {
665+
if (!ac->key) {
666666
pr_err("no secret set (for auth_x protocol)\n");
667667
goto out_nomem;
668668
}
669669

670-
ret = ceph_crypto_key_unarmor(&xi->secret, ac->secret);
671-
if (ret)
670+
ret = ceph_crypto_key_clone(&xi->secret, ac->key);
671+
if (ret < 0) {
672+
pr_err("cannot clone key: %d\n", ret);
672673
goto out_nomem;
674+
}
673675

674676
xi->starting = true;
675677
xi->ticket_handlers = RB_ROOT;

‎net/ceph/ceph_common.c‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/ceph/decode.h>
2121
#include <linux/ceph/mon_client.h>
2222
#include <linux/ceph/auth.h>
23+
#include "crypto.h"
2324

2425

2526

@@ -117,9 +118,29 @@ int ceph_compare_options(struct ceph_options *new_opt,
117118
if (ret)
118119
return ret;
119120

120-
ret = strcmp_null(opt1->secret, opt2->secret);
121-
if (ret)
122-
return ret;
121+
if (opt1->key && !opt2->key)
122+
return -1;
123+
if (!opt1->key && opt2->key)
124+
return 1;
125+
if (opt1->key && opt2->key) {
126+
if (opt1->key->type != opt2->key->type)
127+
return -1;
128+
if (opt1->key->created.tv_sec != opt2->key->created.tv_sec)
129+
return -1;
130+
if (opt1->key->created.tv_nsec != opt2->key->created.tv_nsec)
131+
return -1;
132+
if (opt1->key->len != opt2->key->len)
133+
return -1;
134+
if (opt1->key->key && !opt2->key->key)
135+
return -1;
136+
if (!opt1->key->key && opt2->key->key)
137+
return 1;
138+
if (opt1->key->key && opt2->key->key) {
139+
ret = memcmp(opt1->key->key, opt2->key->key, opt1->key->len);
140+
if (ret)
141+
return ret;
142+
}
143+
}
123144

124145
/* any matching mon ip implies a match */
125146
for (i = 0; i < opt1->num_mon; i++) {
@@ -203,7 +224,10 @@ void ceph_destroy_options(struct ceph_options *opt)
203224
{
204225
dout("destroy_options %p\n", opt);
205226
kfree(opt->name);
206-
kfree(opt->secret);
227+
if (opt->key) {
228+
ceph_crypto_key_destroy(opt->key);
229+
kfree(opt->key);
230+
}
207231
kfree(opt);
208232
}
209233
EXPORT_SYMBOL(ceph_destroy_options);
@@ -295,9 +319,14 @@ int ceph_parse_options(struct ceph_options **popt, char *options,
295319
GFP_KERNEL);
296320
break;
297321
case Opt_secret:
298-
opt->secret = kstrndup(argstr[0].from,
299-
argstr[0].to-argstr[0].from,
300-
GFP_KERNEL);
322+
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
323+
if (!opt->key) {
324+
err = -ENOMEM;
325+
goto out;
326+
}
327+
err = ceph_crypto_key_unarmor(opt->key, argstr[0].from);
328+
if (err < 0)
329+
goto out;
301330
break;
302331

303332
/* misc */

‎net/ceph/crypto.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
#include <linux/ceph/decode.h>
1010
#include "crypto.h"
1111

12+
int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
13+
const struct ceph_crypto_key *src)
14+
{
15+
memcpy(dst, src, sizeof(struct ceph_crypto_key));
16+
dst->key = kmalloc(src->len, GFP_NOFS);
17+
if (!dst->key)
18+
return -ENOMEM;
19+
memcpy(dst->key, src->key, src->len);
20+
return 0;
21+
}
22+
1223
int ceph_crypto_key_encode(struct ceph_crypto_key *key, void **p, void *end)
1324
{
1425
if (*p + sizeof(u16) + sizeof(key->created) +

‎net/ceph/crypto.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ static inline void ceph_crypto_key_destroy(struct ceph_crypto_key *key)
1919
kfree(key->key);
2020
}
2121

22+
extern int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
23+
const struct ceph_crypto_key *src);
2224
extern int ceph_crypto_key_encode(struct ceph_crypto_key *key,
2325
void **p, void *end);
2426
extern int ceph_crypto_key_decode(struct ceph_crypto_key *key,

‎net/ceph/mon_client.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
759759

760760
/* authentication */
761761
monc->auth = ceph_auth_init(cl->options->name,
762-
cl->options->secret);
762+
cl->options->key);
763763
if (IS_ERR(monc->auth))
764764
return PTR_ERR(monc->auth);
765765
monc->auth->want_keys =

0 commit comments

Comments
 (0)