Skip to content

Commit e2c3d29

Browse files
Tommi Virtanenliewegas
authored andcommitted
libceph: Get secret from the kernel keys api when mounting with key=NAME.
Signed-off-by: Tommi Virtanen <tommi.virtanen@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 8323c3a commit e2c3d29

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎net/ceph/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config CEPH_LIB
44
select LIBCRC32C
55
select CRYPTO_AES
66
select CRYPTO
7+
select KEYS
78
default n
89
help
910
Choose Y or M here to include cephlib, which provides the

‎net/ceph/ceph_common.c‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <linux/fs.h>
66
#include <linux/inet.h>
77
#include <linux/in6.h>
8+
#include <linux/key.h>
9+
#include <keys/user-type.h>
810
#include <linux/module.h>
911
#include <linux/mount.h>
1012
#include <linux/parser.h>
@@ -197,6 +199,7 @@ enum {
197199
Opt_fsid,
198200
Opt_name,
199201
Opt_secret,
202+
Opt_key,
200203
Opt_ip,
201204
Opt_last_string,
202205
/* string args above */
@@ -213,6 +216,7 @@ static match_table_t opt_tokens = {
213216
{Opt_fsid, "fsid=%s"},
214217
{Opt_name, "name=%s"},
215218
{Opt_secret, "secret=%s"},
219+
{Opt_key, "key=%s"},
216220
{Opt_ip, "ip=%s"},
217221
/* string args above */
218222
{Opt_noshare, "noshare"},
@@ -232,6 +236,50 @@ void ceph_destroy_options(struct ceph_options *opt)
232236
}
233237
EXPORT_SYMBOL(ceph_destroy_options);
234238

239+
/* get secret from key store */
240+
static int get_secret(struct ceph_crypto_key *dst, const char *name) {
241+
struct key *ukey;
242+
int key_err;
243+
int err = 0;
244+
struct user_key_payload *payload;
245+
void *p;
246+
247+
ukey = request_key(&key_type_user, name, NULL);
248+
if (!ukey || IS_ERR(ukey)) {
249+
/* request_key errors don't map nicely to mount(2)
250+
errors; don't even try, but still printk */
251+
key_err = PTR_ERR(ukey);
252+
switch (key_err) {
253+
case -ENOKEY:
254+
pr_warning("ceph: Mount failed due to key not found: %s\n", name);
255+
break;
256+
case -EKEYEXPIRED:
257+
pr_warning("ceph: Mount failed due to expired key: %s\n", name);
258+
break;
259+
case -EKEYREVOKED:
260+
pr_warning("ceph: Mount failed due to revoked key: %s\n", name);
261+
break;
262+
default:
263+
pr_warning("ceph: Mount failed due to unknown key error"
264+
" %d: %s\n", key_err, name);
265+
}
266+
err = -EPERM;
267+
goto out;
268+
}
269+
270+
payload = ukey->payload.data;
271+
p = payload->data;
272+
err = ceph_crypto_key_decode(dst, &p, p + payload->datalen);
273+
if (err)
274+
goto out_key;
275+
/* pass through, err is 0 */
276+
277+
out_key:
278+
key_put(ukey);
279+
out:
280+
return err;
281+
}
282+
235283
int ceph_parse_options(struct ceph_options **popt, char *options,
236284
const char *dev_name, const char *dev_name_end,
237285
int (*parse_extra_token)(char *c, void *private),
@@ -328,6 +376,16 @@ int ceph_parse_options(struct ceph_options **popt, char *options,
328376
if (err < 0)
329377
goto out;
330378
break;
379+
case Opt_key:
380+
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
381+
if (!opt->key) {
382+
err = -ENOMEM;
383+
goto out;
384+
}
385+
err = get_secret(opt->key, argstr[0].from);
386+
if (err < 0)
387+
goto out;
388+
break;
331389

332390
/* misc */
333391
case Opt_osdtimeout:

0 commit comments

Comments
 (0)