4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/ptlrpc/gss/gss_keyring.c
33 * Author: Eric Mei <ericm@clusterfs.com>
36 #define DEBUG_SUBSYSTEM S_SEC
37 #include <linux/init.h>
38 #include <linux/module.h>
39 #include <linux/slab.h>
40 #include <linux/dcache.h>
42 #include <linux/crypto.h>
43 #include <linux/key.h>
44 #include <linux/keyctl.h>
45 #include <linux/key-type.h>
46 #include <linux/mutex.h>
47 #include <asm/atomic.h>
49 #include <libcfs/linux/linux-list.h>
51 #include <obd_class.h>
52 #include <obd_support.h>
53 #include <uapi/linux/lustre/lustre_idl.h>
54 #include <lustre_sec.h>
55 #include <lustre_net.h>
56 #include <lustre_import.h>
59 #include "gss_internal.h"
62 #ifdef HAVE_GET_REQUEST_KEY_AUTH
63 #include <keys/request_key_auth-type.h>
66 static struct ptlrpc_sec_policy gss_policy_keyring;
67 static struct ptlrpc_ctx_ops gss_keyring_ctxops;
68 static struct key_type gss_key_type;
70 static int sec_install_rctx_kr(struct ptlrpc_sec *sec,
71 struct ptlrpc_svc_ctx *svc_ctx);
72 static void request_key_unlink(struct key *key);
75 * the timeout is only for the case that upcall child process die abnormally.
76 * in any other cases it should finally update kernel key.
78 * FIXME we'd better to incorporate the client & server side upcall timeouts
79 * into the framework of Adaptive Timeouts, but we need to figure out how to
80 * make sure that kernel knows the upcall processes is in-progress or died
83 #define KEYRING_UPCALL_TIMEOUT (obd_timeout + obd_timeout)
85 /* Check caller's namespace in gss_keyring upcall */
86 unsigned int gss_check_upcall_ns = 1;
88 /****************************************
90 ****************************************/
92 static inline void keyring_upcall_lock(struct gss_sec_keyring *gsec_kr)
94 #ifdef HAVE_KEYRING_UPCALL_SERIALIZED
95 mutex_lock(&gsec_kr->gsk_uc_lock);
99 static inline void keyring_upcall_unlock(struct gss_sec_keyring *gsec_kr)
101 #ifdef HAVE_KEYRING_UPCALL_SERIALIZED
102 mutex_unlock(&gsec_kr->gsk_uc_lock);
106 static inline void key_revoke_locked(struct key *key)
108 set_bit(KEY_FLAG_REVOKED, &key->flags);
111 static void ctx_upcall_timeout_kr(cfs_timer_cb_arg_t data)
113 struct gss_cli_ctx_keyring *gctx_kr = cfs_from_timer(gctx_kr,
115 struct ptlrpc_cli_ctx *ctx = &(gctx_kr->gck_base.gc_base);
116 struct key *key = gctx_kr->gck_key;
118 CWARN("ctx %p, key %p\n", ctx, key);
123 key_revoke_locked(key);
126 static void ctx_start_timer_kr(struct ptlrpc_cli_ctx *ctx, time64_t timeout)
128 struct gss_cli_ctx_keyring *gctx_kr = ctx2gctx_keyring(ctx);
129 struct timer_list *timer = &gctx_kr->gck_timer;
133 CDEBUG(D_SEC, "ctx %p: start timer %llds\n", ctx, timeout);
135 cfs_timer_setup(timer, ctx_upcall_timeout_kr,
136 (unsigned long)gctx_kr, 0);
137 timer->expires = cfs_time_seconds(timeout) + jiffies;
142 * caller should make sure no race with other threads
145 void ctx_clear_timer_kr(struct ptlrpc_cli_ctx *ctx)
147 struct gss_cli_ctx_keyring *gctx_kr = ctx2gctx_keyring(ctx);
148 struct timer_list *timer = &gctx_kr->gck_timer;
150 CDEBUG(D_SEC, "ctx %p, key %p\n", ctx, gctx_kr->gck_key);
152 timer_delete_sync(timer);
156 struct ptlrpc_cli_ctx *ctx_create_kr(struct ptlrpc_sec *sec,
157 struct vfs_cred *vcred)
159 struct ptlrpc_cli_ctx *ctx;
160 struct gss_cli_ctx_keyring *gctx_kr;
162 OBD_ALLOC_PTR(gctx_kr);
166 cfs_timer_setup(&gctx_kr->gck_timer, NULL, 0, 0);
168 ctx = &gctx_kr->gck_base.gc_base;
170 if (gss_cli_ctx_init_common(sec, ctx, &gss_keyring_ctxops, vcred)) {
171 OBD_FREE_PTR(gctx_kr);
175 ctx->cc_expire = ktime_get_real_seconds() + KEYRING_UPCALL_TIMEOUT;
176 clear_bit(PTLRPC_CTX_NEW_BIT, &ctx->cc_flags);
177 atomic_inc(&ctx->cc_refcount); /* for the caller */
182 static void ctx_destroy_kr(struct ptlrpc_cli_ctx *ctx)
184 struct ptlrpc_sec *sec = ctx->cc_sec;
185 struct gss_cli_ctx_keyring *gctx_kr = ctx2gctx_keyring(ctx);
187 CDEBUG(D_SEC, "destroying ctx %p\n", ctx);
189 /* at this time the association with key has been broken. */
191 LASSERT(atomic_read(&sec->ps_refcount) > 0);
192 LASSERT(atomic_read(&sec->ps_nctx) > 0);
193 LASSERT(test_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags) == 0);
194 LASSERT(gctx_kr->gck_key == NULL);
196 ctx_clear_timer_kr(ctx);
198 if (gss_cli_ctx_fini_common(sec, ctx))
201 OBD_FREE_PTR(gctx_kr);
203 atomic_dec(&sec->ps_nctx);
204 sptlrpc_sec_put(sec);
207 static void ctx_release_kr(struct ptlrpc_cli_ctx *ctx, int sync)
212 atomic_inc(&ctx->cc_refcount);
213 sptlrpc_gc_add_ctx(ctx);
217 static void ctx_put_kr(struct ptlrpc_cli_ctx *ctx, int sync)
219 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
221 if (atomic_dec_and_test(&ctx->cc_refcount))
222 ctx_release_kr(ctx, sync);
226 * key <-> ctx association and rules:
227 * - ctx might not bind with any key
228 * - key/ctx binding is protected by key semaphore (if the key present)
229 * - key and ctx each take a reference of the other
230 * - ctx enlist/unlist is protected by ctx spinlock
231 * - never enlist a ctx after it's been unlisted
232 * - whoever do enlist should also do bind, lock key before enlist:
233 * - lock key -> lock ctx -> enlist -> unlock ctx -> bind -> unlock key
234 * - whoever do unlist should also do unbind:
235 * - lock key -> lock ctx -> unlist -> unlock ctx -> unbind -> unlock key
236 * - lock ctx -> unlist -> unlock ctx -> lock key -> unbind -> unlock key
239 static inline void spin_lock_if(spinlock_t *lock, int condition)
245 static inline void spin_unlock_if(spinlock_t *lock, int condition)
251 static void ctx_enlist_kr(struct ptlrpc_cli_ctx *ctx, int is_root, int locked)
253 struct ptlrpc_sec *sec = ctx->cc_sec;
254 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
256 LASSERT(!test_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags));
257 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
259 spin_lock_if(&sec->ps_lock, !locked);
261 atomic_inc(&ctx->cc_refcount);
262 set_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags);
263 hlist_add_head(&ctx->cc_cache, &gsec_kr->gsk_clist);
265 gsec_kr->gsk_root_ctx = ctx;
267 spin_unlock_if(&sec->ps_lock, !locked);
271 * Note after this get called, caller should not access ctx again because
272 * it might have been freed, unless caller hold at least one refcount of
275 * return non-zero if we indeed unlist this ctx.
277 static int ctx_unlist_kr(struct ptlrpc_cli_ctx *ctx, int locked)
279 struct ptlrpc_sec *sec = ctx->cc_sec;
280 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
282 /* if hashed bit has gone, leave the job to somebody who is doing it */
283 if (test_and_clear_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags) == 0)
286 /* drop ref inside spin lock to prevent race with other operations */
287 spin_lock_if(&sec->ps_lock, !locked);
289 if (gsec_kr->gsk_root_ctx == ctx)
290 gsec_kr->gsk_root_ctx = NULL;
291 hlist_del_init(&ctx->cc_cache);
292 atomic_dec(&ctx->cc_refcount);
294 spin_unlock_if(&sec->ps_lock, !locked);
300 * Get specific payload. Newer kernels support 4 slots.
303 key_get_payload(struct key *key, unsigned int index)
305 void *key_ptr = NULL;
307 #ifdef HAVE_KEY_PAYLOAD_DATA_ARRAY
308 key_ptr = key->payload.data[index];
311 key_ptr = key->payload.data;
317 * Set specific payload. Newer kernels support 4 slots.
319 static int key_set_payload(struct key *key, unsigned int index,
320 struct ptlrpc_cli_ctx *ctx)
324 #ifdef HAVE_KEY_PAYLOAD_DATA_ARRAY
326 key->payload.data[index] = ctx;
329 key->payload.data = ctx;
337 * bind a key with a ctx together.
338 * caller must hold write lock of the key, as well as ref on key & ctx.
340 static void bind_key_ctx(struct key *key, struct ptlrpc_cli_ctx *ctx)
342 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
343 LASSERT(ll_read_key_usage(key) > 0);
344 LASSERT(ctx2gctx_keyring(ctx)->gck_key == NULL);
345 LASSERT(!key_get_payload(key, 0));
347 /* at this time context may or may not in list. */
349 atomic_inc(&ctx->cc_refcount);
350 ctx2gctx_keyring(ctx)->gck_key = key;
351 LASSERT(!key_set_payload(key, 0, ctx));
355 * unbind a key and a ctx.
356 * caller must hold write lock, as well as a ref of the key.
358 static void unbind_key_ctx(struct key *key, struct ptlrpc_cli_ctx *ctx)
360 LASSERT(key_get_payload(key, 0) == ctx);
361 LASSERT(test_bit(PTLRPC_CTX_CACHED_BIT, &ctx->cc_flags) == 0);
363 /* must revoke the key, or others may treat it as newly created */
364 key_revoke_locked(key);
366 key_set_payload(key, 0, NULL);
367 ctx2gctx_keyring(ctx)->gck_key = NULL;
369 /* once ctx get split from key, the timer is meaningless */
370 ctx_clear_timer_kr(ctx);
377 * given a ctx, unbind with its coupled key, if any.
378 * unbind could only be called once, so we don't worry the key be released
381 static void unbind_ctx_kr(struct ptlrpc_cli_ctx *ctx)
383 struct key *key = ctx2gctx_keyring(ctx)->gck_key;
386 LASSERT(key_get_payload(key, 0) == ctx);
389 down_write(&key->sem);
390 unbind_key_ctx(key, ctx);
393 request_key_unlink(key);
398 * given a key, unbind with its coupled ctx, if any.
399 * caller must hold write lock, as well as a ref of the key.
401 static void unbind_key_locked(struct key *key)
403 struct ptlrpc_cli_ctx *ctx = key_get_payload(key, 0);
406 unbind_key_ctx(key, ctx);
410 * unlist a ctx, and unbind from coupled key
412 static void kill_ctx_kr(struct ptlrpc_cli_ctx *ctx)
414 if (ctx_unlist_kr(ctx, 0))
419 * given a key, unlist and unbind with the coupled ctx (if any).
420 * caller must hold write lock, as well as a ref of the key.
422 static void kill_key_locked(struct key *key)
424 struct ptlrpc_cli_ctx *ctx = key_get_payload(key, 0);
426 if (ctx && ctx_unlist_kr(ctx, 0))
427 unbind_key_locked(key);
431 * caller should hold one ref on contexts in freelist.
433 static void dispose_ctx_list_kr(struct hlist_head *freelist)
435 struct hlist_node *next;
436 struct ptlrpc_cli_ctx *ctx;
437 struct gss_cli_ctx *gctx;
439 hlist_for_each_entry_safe(ctx, next, freelist, cc_cache) {
440 hlist_del_init(&ctx->cc_cache);
442 /* reverse ctx: update current seq to buddy svcctx if exist.
443 * ideally this should be done at gss_cli_ctx_finalize(), but
444 * the ctx destroy could be delayed by:
445 * 1) ctx still has reference;
446 * 2) ctx destroy is asynchronous;
447 * and reverse import call inval_all_ctx() require this be done
448 * _immediately_ otherwise newly created reverse ctx might copy
449 * the very old sequence number from svcctx. */
450 gctx = ctx2gctx(ctx);
451 if (!rawobj_empty(&gctx->gc_svc_handle) &&
452 sec_is_reverse(gctx->gc_base.cc_sec)) {
453 gss_svc_upcall_update_sequence(&gctx->gc_svc_handle,
454 (__u32) atomic_read(&gctx->gc_seq));
457 /* we need to wakeup waiting reqs here. the context might
458 * be forced released before upcall finished, then the
459 * late-arrived downcall can't find the ctx even. */
460 sptlrpc_cli_ctx_wakeup(ctx);
468 * lookup a root context directly in a sec, return root ctx with a
469 * reference taken or NULL.
472 struct ptlrpc_cli_ctx * sec_lookup_root_ctx_kr(struct ptlrpc_sec *sec)
474 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
475 struct ptlrpc_cli_ctx *ctx = NULL;
477 spin_lock(&sec->ps_lock);
479 ctx = gsec_kr->gsk_root_ctx;
481 if (ctx == NULL && unlikely(sec_is_reverse(sec))) {
482 struct ptlrpc_cli_ctx *tmp;
484 /* reverse ctx, search root ctx in list, choose the one
485 * with shortest expire time, which is most possibly have
486 * an established peer ctx at client side. */
487 hlist_for_each_entry(tmp, &gsec_kr->gsk_clist, cc_cache) {
488 if (ctx == NULL || ctx->cc_expire == 0 ||
489 ctx->cc_expire > tmp->cc_expire) {
491 /* promote to be root_ctx */
492 gsec_kr->gsk_root_ctx = ctx;
498 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
499 LASSERT(!hlist_empty(&gsec_kr->gsk_clist));
500 atomic_inc(&ctx->cc_refcount);
503 spin_unlock(&sec->ps_lock);
508 #define RVS_CTX_EXPIRE_NICE (10)
511 void rvs_sec_install_root_ctx_kr(struct ptlrpc_sec *sec,
512 struct ptlrpc_cli_ctx *new_ctx,
515 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
516 struct ptlrpc_cli_ctx *ctx;
520 LASSERT(sec_is_reverse(sec));
522 spin_lock(&sec->ps_lock);
524 now = ktime_get_real_seconds();
526 /* set all existing ctxs short expiry */
527 hlist_for_each_entry(ctx, &gsec_kr->gsk_clist, cc_cache) {
528 if (ctx->cc_expire > now + RVS_CTX_EXPIRE_NICE) {
529 ctx->cc_early_expire = 1;
530 ctx->cc_expire = now + RVS_CTX_EXPIRE_NICE;
534 /* if there's root_ctx there, instead obsolete the current
535 * immediately, we leave it continue operating for a little while.
536 * hopefully when the first backward rpc with newest ctx send out,
537 * the client side already have the peer ctx well established. */
538 ctx_enlist_kr(new_ctx, gsec_kr->gsk_root_ctx ? 0 : 1, 1);
541 bind_key_ctx(key, new_ctx);
543 spin_unlock(&sec->ps_lock);
546 static void construct_key_desc(void *buf, int bufsize,
547 struct ptlrpc_sec *sec, uid_t uid)
549 snprintf(buf, bufsize, "%d@%x", uid, sec->ps_id);
550 ((char *)buf)[bufsize - 1] = '\0';
553 /****************************************
555 ****************************************/
558 struct ptlrpc_sec * gss_sec_create_kr(struct obd_import *imp,
559 struct ptlrpc_svc_ctx *svcctx,
560 struct sptlrpc_flavor *sf)
562 struct gss_sec_keyring *gsec_kr;
565 OBD_ALLOC(gsec_kr, sizeof(*gsec_kr));
569 INIT_HLIST_HEAD(&gsec_kr->gsk_clist);
570 gsec_kr->gsk_root_ctx = NULL;
571 mutex_init(&gsec_kr->gsk_root_uc_lock);
572 #ifdef HAVE_KEYRING_UPCALL_SERIALIZED
573 mutex_init(&gsec_kr->gsk_uc_lock);
576 if (gss_sec_create_common(&gsec_kr->gsk_base, &gss_policy_keyring,
580 if (svcctx != NULL &&
581 sec_install_rctx_kr(&gsec_kr->gsk_base.gs_base, svcctx)) {
582 gss_sec_destroy_common(&gsec_kr->gsk_base);
586 RETURN(&gsec_kr->gsk_base.gs_base);
589 OBD_FREE(gsec_kr, sizeof(*gsec_kr));
594 void gss_sec_destroy_kr(struct ptlrpc_sec *sec)
596 struct gss_sec *gsec = sec2gsec(sec);
597 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
599 CDEBUG(D_SEC, "destroy %s@%p\n", sec->ps_policy->sp_name, sec);
601 LASSERT(hlist_empty(&gsec_kr->gsk_clist));
602 LASSERT(gsec_kr->gsk_root_ctx == NULL);
604 gss_sec_destroy_common(gsec);
606 OBD_FREE(gsec_kr, sizeof(*gsec_kr));
609 static inline int user_is_root(struct ptlrpc_sec *sec, struct vfs_cred *vcred)
611 /* except the ROOTONLY flag, treat it as root user only if real uid
612 * is 0, euid/fsuid being 0 are handled as setuid scenarios */
613 if (sec_is_rootonly(sec) || (vcred->vc_uid == 0))
620 * When lookup_user_key is available use the kernel API rather than directly
621 * accessing the uid_keyring and session_keyring via the current process
624 #ifdef HAVE_LOOKUP_USER_KEY
626 #ifdef HAVE_KEY_NEED_UNLINK
627 /* from Linux security/keys/internal.h: */
628 # ifndef KEY_LOOKUP_PARTIAL
629 # define KEY_LOOKUP_PARTIAL 0x2
632 # define KEY_NEED_UNLINK 0
633 # ifndef KEY_LOOKUP_FOR_UNLINK
634 # define KEY_LOOKUP_FOR_UNLINK 0x4
636 # define KEY_LOOKUP_PARTIAL KEY_LOOKUP_FOR_UNLINK
637 #endif /* HAVE_KEY_NEED_UNLINK */
639 static struct key *_user_key(key_serial_t id)
644 ref = lookup_user_key(id, KEY_LOOKUP_PARTIAL, KEY_NEED_UNLINK);
647 return key_ref_to_ptr(ref);
650 static inline struct key *get_user_session_keyring(const struct cred *cred)
652 return _user_key(KEY_SPEC_USER_SESSION_KEYRING);
655 static inline struct key *get_user_keyring(const struct cred *cred)
657 return _user_key(KEY_SPEC_USER_KEYRING);
660 static inline struct key *get_user_session_keyring(const struct cred *cred)
662 return key_get(cred->user->session_keyring);
665 static inline struct key *get_user_keyring(const struct cred *cred)
667 return key_get(cred->user->uid_keyring);
672 * unlink request key from it's ring, which is linked during request_key().
673 * sadly, we have to 'guess' which keyring it's linked to.
675 * FIXME this code is fragile, it depends on how request_key() is implemented.
677 static void request_key_unlink(struct key *key)
679 const struct cred *cred = current_cred();
680 struct key *ring = NULL;
682 switch (cred->jit_keyring) {
683 case KEY_REQKEY_DEFL_DEFAULT:
684 case KEY_REQKEY_DEFL_REQUESTOR_KEYRING:
685 #ifdef HAVE_GET_REQUEST_KEY_AUTH
686 if (cred->request_key_auth) {
687 struct request_key_auth *rka;
688 struct key *authkey = cred->request_key_auth;
690 down_read(&authkey->sem);
691 rka = get_request_key_auth(authkey);
692 if (!test_bit(KEY_FLAG_REVOKED, &authkey->flags))
693 ring = key_get(rka->dest_keyring);
694 up_read(&authkey->sem);
700 case KEY_REQKEY_DEFL_THREAD_KEYRING:
701 ring = key_get(cred->thread_keyring);
705 case KEY_REQKEY_DEFL_PROCESS_KEYRING:
706 ring = key_get(cred->process_keyring);
710 case KEY_REQKEY_DEFL_SESSION_KEYRING:
712 ring = key_get(rcu_dereference(cred->session_keyring));
717 case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
718 ring = get_user_session_keyring(cred);
720 case KEY_REQKEY_DEFL_USER_KEYRING:
721 ring = get_user_keyring(cred);
723 case KEY_REQKEY_DEFL_GROUP_KEYRING:
729 int res = key_unlink(ring, key);
731 "Unlink key %08x (%p) from keyring %08x: %d\n",
732 key->serial, key, ring->serial, res);
736 "Missing keyring, key %08x (%p) could not be unlinked, ignored\n",
742 struct ptlrpc_cli_ctx * gss_sec_lookup_ctx_kr(struct ptlrpc_sec *sec,
743 struct vfs_cred *vcred,
744 int create, int remove_dead)
746 struct obd_import *imp = sec->ps_import;
747 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
748 struct ptlrpc_cli_ctx *ctx = NULL;
749 unsigned int is_root = 0, create_new = 0;
754 const char *sec_part_flags = "";
757 struct lnet_nid primary;
760 LASSERT(imp != NULL);
762 is_root = user_is_root(sec, vcred);
764 /* a little bit optimization for root context */
766 ctx = sec_lookup_root_ctx_kr(sec);
768 * Only lookup directly for REVERSE sec, which should
771 if (ctx || sec_is_reverse(sec))
775 LASSERT(create != 0);
777 /* for root context, obtain lock and check again, this time hold
778 * the root upcall lock, make sure nobody else populated new root
779 * context after last check.
782 mutex_lock(&gsec_kr->gsk_root_uc_lock);
784 ctx = sec_lookup_root_ctx_kr(sec);
788 /* update reverse handle for root user */
789 sec2gsec(sec)->gs_rvs_hdl = gss_get_next_ctx_index();
791 switch (sec->ps_part) {
793 sec_part_flags = "m";
796 sec_part_flags = "o";
799 sec_part_flags = "rmo";
802 sec_part_flags = "r";
809 switch (SPTLRPC_FLVR_SVC(sec->ps_flvr.sf_rpc)) {
810 case SPTLRPC_SVC_NULL:
813 case SPTLRPC_SVC_AUTH:
816 case SPTLRPC_SVC_INTG:
819 case SPTLRPC_SVC_PRIV:
827 /* in case of setuid, key will be constructed as owner of fsuid/fsgid,
828 * but we do authentication based on real uid/gid. the key permission
829 * bits will be exactly as POS_ALL, so only processes who subscribed
830 * this key could have the access, although the quota might be counted
831 * on others (fsuid/fsgid).
833 * keyring will use fsuid/fsgid as upcall parameters, so we have to
834 * encode real uid/gid into callout info.
837 /* But first we need to make sure the obd type is supported */
838 if (strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
839 strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
840 strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MGC_NAME) &&
841 strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
842 strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSP_NAME)) {
843 CERROR("obd %s is not a supported device\n",
844 imp->imp_obd->obd_name);
845 GOTO(out, ctx = NULL);
848 construct_key_desc(desc, sizeof(desc), sec, vcred->vc_uid);
850 /* callout info format:
851 * secid:mech:uid:gid:sec_flags:svc_flag:svc_type:peer_nid:target_uuid:
854 coinfo_size = sizeof(struct obd_uuid) + MAX_OBD_NAME + 64;
855 OBD_ALLOC(coinfo, coinfo_size);
859 /* Last callout parameter is pid of process whose namespace will be used
860 * for credentials' retrieval.
862 if (gss_check_upcall_ns) {
863 /* For user's credentials (in which case sec_part_flags is
864 * empty), use current PID instead of import's reference
865 * PID to get reference namespace.
867 if (sec_part_flags[0] == '\0')
868 caller_pid = current->pid;
870 caller_pid = imp->imp_sec_refpid;
872 /* Do not switch namespace in gss keyring upcall. */
875 primary = imp->imp_connection->c_self;
876 LNetPrimaryNID(&primary);
878 /* FIXME !! Needs to support larger NIDs */
879 snprintf(coinfo, coinfo_size, "%d:%s:%u:%u:%s:%c:%d:%#llx:%s:%#llx:%d",
880 sec->ps_id, sec2gsec(sec)->gs_mech->gm_name,
881 vcred->vc_uid, vcred->vc_gid,
882 sec_part_flags, svc_flag, import_to_gss_svc(imp),
883 lnet_nid_to_nid4(&imp->imp_connection->c_peer.nid),
884 imp->imp_obd->obd_name,
885 lnet_nid_to_nid4(&primary),
888 CDEBUG(D_SEC, "requesting key for %s\n", desc);
890 keyring_upcall_lock(gsec_kr);
891 key = request_key(&gss_key_type, desc, coinfo);
892 keyring_upcall_unlock(gsec_kr);
894 OBD_FREE(coinfo, coinfo_size);
897 CERROR("failed request key: %ld\n", PTR_ERR(key));
900 CDEBUG(D_SEC, "obtained key %08x for %s\n", key->serial, desc);
902 /* once payload.data was pointed to a ctx, it never changes until
903 * we de-associate them; but parallel request_key() may return
904 * a key with payload.data == NULL at the same time. so we still
905 * need wirtelock of key->sem to serialize them.
907 down_write(&key->sem);
909 ctx = key_get_payload(key, 0);
911 LASSERT(atomic_read(&ctx->cc_refcount) >= 1);
912 LASSERT(ctx2gctx_keyring(ctx)->gck_key == key);
913 LASSERT(ll_read_key_usage(key) >= 2);
915 /* simply take a ref and return. it's upper layer's
916 * responsibility to detect & replace dead ctx.
918 atomic_inc(&ctx->cc_refcount);
920 /* pre initialization with a cli_ctx. this can't be done in
921 * key_instantiate() because we'v no enough information
924 ctx = ctx_create_kr(sec, vcred);
926 ctx_enlist_kr(ctx, is_root, 0);
927 bind_key_ctx(key, ctx);
929 ctx_start_timer_kr(ctx, KEYRING_UPCALL_TIMEOUT);
931 CDEBUG(D_SEC, "installed key %p <-> ctx %p (sec %p)\n",
934 /* we'd prefer to call key_revoke(), but we more like
935 * to revoke it within this key->sem locked period.
937 CDEBUG(D_SEC, "revoking key %08x (%p)\n",
939 key_revoke_locked(key);
947 if (is_root && create_new)
948 request_key_unlink(key);
953 mutex_unlock(&gsec_kr->gsk_root_uc_lock);
958 void gss_sec_release_ctx_kr(struct ptlrpc_sec *sec,
959 struct ptlrpc_cli_ctx *ctx,
962 LASSERT(atomic_read(&sec->ps_refcount) > 0);
963 LASSERT(atomic_read(&ctx->cc_refcount) == 0);
964 ctx_release_kr(ctx, sync);
968 * flush context of normal user, we must resort to keyring itself to find out
969 * contexts which belong to me.
971 * Note here we suppose only to flush _my_ context, the "uid" will
972 * be ignored in the search.
975 void flush_user_ctx_cache_kr(struct ptlrpc_sec *sec,
977 int grace, int force)
982 /* nothing to do for reverse or rootonly sec */
983 if (sec_is_reverse(sec) || sec_is_rootonly(sec))
986 construct_key_desc(desc, sizeof(desc), sec, uid);
988 /* there should be only one valid key, but we put it in the
989 * loop in case of any weird cases */
991 key = request_key(&gss_key_type, desc, NULL);
993 CDEBUG(D_SEC, "No more key found for current user\n");
997 down_write(&key->sem);
999 kill_key_locked(key);
1001 /* kill_key_locked() should usually revoke the key, but we
1002 * revoke it again to make sure, e.g. some case the key may
1003 * not well coupled with a context. */
1004 key_revoke_locked(key);
1006 up_write(&key->sem);
1008 request_key_unlink(key);
1015 * flush context of root or all, we iterate through the list.
1018 void flush_spec_ctx_cache_kr(struct ptlrpc_sec *sec, uid_t uid, int grace,
1021 struct gss_sec_keyring *gsec_kr;
1022 struct hlist_head freelist = HLIST_HEAD_INIT;
1023 struct hlist_node *next;
1024 struct ptlrpc_cli_ctx *ctx;
1027 gsec_kr = sec2gsec_keyring(sec);
1029 spin_lock(&sec->ps_lock);
1030 hlist_for_each_entry_safe(ctx, next, &gsec_kr->gsk_clist,
1032 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
1034 if (uid != -1 && uid != ctx->cc_vcred.vc_uid)
1037 /* at this moment there's at least 2 base reference:
1038 * key association and in-list. */
1039 if (atomic_read(&ctx->cc_refcount) > 2) {
1042 CWARN("flush busy ctx %p(%u->%s, extra ref %d)\n",
1043 ctx, ctx->cc_vcred.vc_uid,
1044 sec2target_str(ctx->cc_sec),
1045 atomic_read(&ctx->cc_refcount) - 2);
1048 set_bit(PTLRPC_CTX_DEAD_BIT, &ctx->cc_flags);
1050 clear_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
1052 atomic_inc(&ctx->cc_refcount);
1054 if (ctx_unlist_kr(ctx, 1)) {
1055 hlist_add_head(&ctx->cc_cache, &freelist);
1057 LASSERT(atomic_read(&ctx->cc_refcount) >= 2);
1058 atomic_dec(&ctx->cc_refcount);
1061 spin_unlock(&sec->ps_lock);
1063 dispose_ctx_list_kr(&freelist);
1068 int gss_sec_flush_ctx_cache_kr(struct ptlrpc_sec *sec,
1069 uid_t uid, int grace, int force)
1073 CDEBUG(D_SEC, "sec %p(%d, nctx %d), uid %d, grace %d, force %d\n",
1074 sec, atomic_read(&sec->ps_refcount),
1075 atomic_read(&sec->ps_nctx),
1078 if (uid != -1 && uid != 0)
1079 flush_user_ctx_cache_kr(sec, uid, grace, force);
1081 flush_spec_ctx_cache_kr(sec, uid, grace, force);
1087 void gss_sec_gc_ctx_kr(struct ptlrpc_sec *sec)
1089 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
1090 struct hlist_head freelist = HLIST_HEAD_INIT;
1091 struct hlist_node *next;
1092 struct ptlrpc_cli_ctx *ctx;
1095 CWARN("running gc\n");
1097 spin_lock(&sec->ps_lock);
1098 hlist_for_each_entry_safe(ctx, next, &gsec_kr->gsk_clist,
1100 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
1102 atomic_inc(&ctx->cc_refcount);
1104 if (cli_ctx_check_death(ctx) && ctx_unlist_kr(ctx, 1)) {
1105 hlist_add_head(&ctx->cc_cache, &freelist);
1106 CWARN("unhashed ctx %p\n", ctx);
1108 LASSERT(atomic_read(&ctx->cc_refcount) >= 2);
1109 atomic_dec(&ctx->cc_refcount);
1112 spin_unlock(&sec->ps_lock);
1114 dispose_ctx_list_kr(&freelist);
1119 int gss_sec_display_kr(struct ptlrpc_sec *sec, struct seq_file *seq)
1121 struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
1122 struct hlist_node *next;
1123 struct ptlrpc_cli_ctx *ctx;
1124 struct gss_cli_ctx *gctx;
1125 time64_t now = ktime_get_real_seconds();
1128 spin_lock(&sec->ps_lock);
1129 hlist_for_each_entry_safe(ctx, next, &gsec_kr->gsk_clist,
1135 gctx = ctx2gctx(ctx);
1136 key = ctx2gctx_keyring(ctx)->gck_key;
1138 gss_cli_ctx_flags2str(ctx->cc_flags,
1139 flags_str, sizeof(flags_str));
1141 if (gctx->gc_mechctx)
1142 lgss_display(gctx->gc_mechctx, mech, sizeof(mech));
1144 snprintf(mech, sizeof(mech), "N/A");
1145 mech[sizeof(mech) - 1] = '\0';
1148 "%p: uid %u, ref %d, expire %lld(%+lld), fl %s, seq %d, win %u, key %08x(ref %d), hdl %#llx:%#llx, mech: %s\n",
1149 ctx, ctx->cc_vcred.vc_uid,
1150 atomic_read(&ctx->cc_refcount),
1152 ctx->cc_expire ? ctx->cc_expire - now : 0,
1154 atomic_read(&gctx->gc_seq),
1156 key ? key->serial : 0,
1157 key ? ll_read_key_usage(key) : 0,
1158 gss_handle_to_u64(&gctx->gc_handle),
1159 gss_handle_to_u64(&gctx->gc_svc_handle),
1162 spin_unlock(&sec->ps_lock);
1167 /****************************************
1169 ****************************************/
1172 int gss_cli_ctx_refresh_kr(struct ptlrpc_cli_ctx *ctx)
1174 /* upcall is already on the way */
1175 struct gss_cli_ctx *gctx = ctx ? ctx2gctx(ctx) : NULL;
1177 /* record latest sequence number in buddy svcctx */
1178 if (gctx && !rawobj_empty(&gctx->gc_svc_handle) &&
1179 sec_is_reverse(gctx->gc_base.cc_sec)) {
1180 return gss_svc_upcall_update_sequence(&gctx->gc_svc_handle,
1181 (__u32)atomic_read(&gctx->gc_seq));
1187 int gss_cli_ctx_validate_kr(struct ptlrpc_cli_ctx *ctx)
1189 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
1190 LASSERT(ctx->cc_sec);
1192 if (cli_ctx_check_death(ctx)) {
1197 if (cli_ctx_is_ready(ctx))
1203 void gss_cli_ctx_die_kr(struct ptlrpc_cli_ctx *ctx, int grace)
1205 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
1206 LASSERT(ctx->cc_sec);
1208 cli_ctx_expire(ctx);
1212 /****************************************
1213 * (reverse) service *
1214 ****************************************/
1217 * reverse context could have nothing to do with keyrings. here we still keep
1218 * the version which bind to a key, for future reference.
1220 #define HAVE_REVERSE_CTX_NOKEY
1222 #ifdef HAVE_REVERSE_CTX_NOKEY
1225 int sec_install_rctx_kr(struct ptlrpc_sec *sec,
1226 struct ptlrpc_svc_ctx *svc_ctx)
1228 struct ptlrpc_cli_ctx *cli_ctx;
1229 struct vfs_cred vcred = { .vc_uid = 0 };
1235 cli_ctx = ctx_create_kr(sec, &vcred);
1236 if (cli_ctx == NULL)
1239 rc = gss_copy_rvc_cli_ctx(cli_ctx, svc_ctx);
1241 CERROR("failed copy reverse cli ctx: %d\n", rc);
1243 ctx_put_kr(cli_ctx, 1);
1247 rvs_sec_install_root_ctx_kr(sec, cli_ctx, NULL);
1249 ctx_put_kr(cli_ctx, 1);
1254 #else /* ! HAVE_REVERSE_CTX_NOKEY */
1257 int sec_install_rctx_kr(struct ptlrpc_sec *sec,
1258 struct ptlrpc_svc_ctx *svc_ctx)
1260 struct ptlrpc_cli_ctx *cli_ctx = NULL;
1262 struct vfs_cred vcred = { .vc_uid = 0 };
1270 construct_key_desc(desc, sizeof(desc), sec, 0);
1272 key = key_alloc(&gss_key_type, desc, 0, 0,
1273 KEY_POS_ALL | KEY_USR_ALL, 1);
1275 CERROR("failed to alloc key: %ld\n", PTR_ERR(key));
1276 return PTR_ERR(key);
1279 rc = key_instantiate_and_link(key, NULL, 0, NULL, NULL);
1281 CERROR("failed to instantiate key: %d\n", rc);
1285 down_write(&key->sem);
1287 LASSERT(!key_get_payload(key, 0));
1289 cli_ctx = ctx_create_kr(sec, &vcred);
1290 if (cli_ctx == NULL) {
1295 rc = gss_copy_rvc_cli_ctx(cli_ctx, svc_ctx);
1297 CERROR("failed copy reverse cli ctx: %d\n", rc);
1301 rvs_sec_install_root_ctx_kr(sec, cli_ctx, key);
1303 ctx_put_kr(cli_ctx, 1);
1304 up_write(&key->sem);
1313 ctx_put_kr(cli_ctx, 1);
1315 up_write(&key->sem);
1321 #endif /* HAVE_REVERSE_CTX_NOKEY */
1323 /****************************************
1325 ****************************************/
1328 int gss_svc_accept_kr(struct ptlrpc_request *req)
1330 return gss_svc_accept(&gss_policy_keyring, req);
1334 int gss_svc_install_rctx_kr(struct obd_import *imp,
1335 struct ptlrpc_svc_ctx *svc_ctx)
1337 struct ptlrpc_sec *sec;
1340 sec = sptlrpc_import_sec_ref(imp);
1343 rc = sec_install_rctx_kr(sec, svc_ctx);
1344 sptlrpc_sec_put(sec);
1349 /****************************************
1351 ****************************************/
1354 #ifdef HAVE_KEY_TYPE_INSTANTIATE_2ARGS
1355 int gss_kt_instantiate(struct key *key, struct key_preparsed_payload *prep)
1357 const void *data = prep->data;
1358 size_t datalen = prep->datalen;
1360 int gss_kt_instantiate(struct key *key, const void *data, size_t datalen)
1366 CDEBUG(D_SEC, "instantiating key %08x (%p)\n", key->serial, key);
1368 if (data != NULL || datalen != 0) {
1369 CERROR("invalid: data %p, len %lu\n", data, (long)datalen);
1373 if (key_get_payload(key, 0)) {
1374 CERROR("key already have payload\n");
1378 /* link the key to session keyring, so following context negotiation
1379 * rpc fired from user space could find this key. This will be unlinked
1380 * automatically when upcall processes die.
1382 * we can't do this through keyctl from userspace, because the upcall
1383 * might be neither possessor nor owner of the key (setuid).
1385 * the session keyring is created upon upcall, and don't change all
1386 * the way until upcall finished, so rcu lock is not needed here.
1388 LASSERT(current_cred()->session_keyring);
1391 rc = key_link(current_cred()->session_keyring, key);
1394 CERROR("failed to link key %08x to keyring %08x: %d\n",
1396 current_cred()->session_keyring->serial, rc);
1401 "key %08x (%p) linked to keyring %08x and instantiated, ctx %p\n",
1402 key->serial, key, current_cred()->session_keyring->serial,
1403 key_get_payload(key, 0));
1408 * called with key semaphore write locked. it means we can operate
1409 * on the context without fear of loosing refcount.
1412 #ifdef HAVE_KEY_TYPE_INSTANTIATE_2ARGS
1413 int gss_kt_update(struct key *key, struct key_preparsed_payload *prep)
1415 const void *data = prep->data;
1416 __u32 datalen32 = (__u32) prep->datalen;
1418 int gss_kt_update(struct key *key, const void *data, size_t datalen)
1420 __u32 datalen32 = (__u32) datalen;
1422 struct ptlrpc_cli_ctx *ctx = key_get_payload(key, 0);
1423 struct gss_cli_ctx *gctx;
1424 rawobj_t tmpobj = RAWOBJ_EMPTY;
1428 CDEBUG(D_SEC, "updating key %08x (%p)\n", key->serial, key);
1430 if (data == NULL || datalen32 == 0) {
1431 CWARN("invalid: data %p, len %lu\n", data, (long)datalen32);
1435 /* if upcall finished negotiation too fast (mostly likely because
1436 * of local error happened) and call kt_update(), the ctx
1437 * might be still NULL. but the key will finally be associate
1438 * with a context, or be revoked. if key status is fine, return
1439 * -EAGAIN to allow userspace sleep a while and call again. */
1441 CDEBUG(D_SEC, "update too soon: key %08x (%p) flags %lx\n",
1442 key->serial, key, key->flags);
1444 rc = key_validate(key);
1451 LASSERT(atomic_read(&ctx->cc_refcount) > 0);
1452 LASSERT(ctx->cc_sec);
1454 ctx_clear_timer_kr(ctx);
1456 /* don't proceed if already refreshed */
1457 if (cli_ctx_is_refreshed(ctx)) {
1458 CWARN("ctx already done refresh\n");
1462 sptlrpc_cli_ctx_get(ctx);
1463 gctx = ctx2gctx(ctx);
1465 rc = buffer_extract_bytes(&data, &datalen32, &gctx->gc_win,
1466 sizeof(gctx->gc_win));
1468 CERROR("failed extract seq_win\n");
1472 if (gctx->gc_win == 0) {
1473 __u32 nego_rpc_err, nego_gss_err;
1475 rc = buffer_extract_bytes(&data, &datalen32, &nego_rpc_err,
1476 sizeof(nego_rpc_err));
1478 CERROR("cannot extract RPC: rc = %d\n", rc);
1482 rc = buffer_extract_bytes(&data, &datalen32, &nego_gss_err,
1483 sizeof(nego_gss_err));
1485 CERROR("failed to extract gss rc = %d\n", rc);
1489 CERROR("negotiation: rpc err %d, gss err %x\n",
1490 nego_rpc_err, nego_gss_err);
1492 rc = nego_rpc_err ? nego_rpc_err : -EACCES;
1494 rc = rawobj_extract_local_alloc(&gctx->gc_handle,
1495 (__u32 **) &data, &datalen32);
1497 CERROR("failed extract handle\n");
1501 rc = rawobj_extract_local(&tmpobj,
1502 (__u32 **) &data, &datalen32);
1504 CERROR("failed extract mech\n");
1508 rc = lgss_import_sec_context(&tmpobj,
1509 sec2gsec(ctx->cc_sec)->gs_mech,
1511 if (rc != GSS_S_COMPLETE)
1512 CERROR("failed import context\n");
1517 CDEBUG(D_SEC, "update of key %08x (%p): %d\n", key->serial, key, rc);
1518 /* we don't care what current status of this ctx, even someone else
1519 * is operating on the ctx at the same time. we just add up our own
1522 gss_cli_ctx_uptodate(gctx);
1524 /* this will also revoke the key. has to be done before
1525 * wakeup waiters otherwise they can find the stale key */
1526 kill_key_locked(key);
1528 cli_ctx_expire(ctx);
1530 if (rc != -ERESTART)
1531 set_bit(PTLRPC_CTX_ERROR_BIT, &ctx->cc_flags);
1534 /* let user space think it's a success */
1535 sptlrpc_cli_ctx_put(ctx, 1);
1539 #ifndef HAVE_KEY_MATCH_DATA
1541 gss_kt_match(const struct key *key, const void *desc)
1543 return strcmp(key->description, (const char *) desc) == 0 &&
1544 !test_bit(KEY_FLAG_REVOKED, &key->flags);
1546 #else /* ! HAVE_KEY_MATCH_DATA */
1548 gss_kt_match(const struct key *key, const struct key_match_data *match_data)
1550 const char *desc = match_data->raw_data;
1552 return strcmp(key->description, desc) == 0 &&
1553 !test_bit(KEY_FLAG_REVOKED, &key->flags);
1557 * Preparse the match criterion.
1559 static int gss_kt_match_preparse(struct key_match_data *match_data)
1561 match_data->lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT;
1562 match_data->cmp = gss_kt_match;
1565 #endif /* HAVE_KEY_MATCH_DATA */
1568 void gss_kt_destroy(struct key *key)
1571 LASSERT(!key_get_payload(key, 0));
1572 CDEBUG(D_SEC, "destroy key %p\n", key);
1577 void gss_kt_describe(const struct key *key, struct seq_file *s)
1579 if (key->description == NULL)
1580 seq_puts(s, "[null]");
1582 seq_puts(s, key->description);
1585 static struct key_type gss_key_type =
1589 .instantiate = gss_kt_instantiate,
1590 .update = gss_kt_update,
1591 #ifdef HAVE_KEY_MATCH_DATA
1592 .match_preparse = gss_kt_match_preparse,
1594 .match = gss_kt_match,
1596 .destroy = gss_kt_destroy,
1597 .describe = gss_kt_describe,
1600 /****************************************
1601 * lustre gss keyring policy *
1602 ****************************************/
1604 static struct ptlrpc_ctx_ops gss_keyring_ctxops = {
1605 .match = gss_cli_ctx_match,
1606 .refresh = gss_cli_ctx_refresh_kr,
1607 .validate = gss_cli_ctx_validate_kr,
1608 .die = gss_cli_ctx_die_kr,
1609 .sign = gss_cli_ctx_sign,
1610 .verify = gss_cli_ctx_verify,
1611 .seal = gss_cli_ctx_seal,
1612 .unseal = gss_cli_ctx_unseal,
1613 .wrap_bulk = gss_cli_ctx_wrap_bulk,
1614 .unwrap_bulk = gss_cli_ctx_unwrap_bulk,
1617 static struct ptlrpc_sec_cops gss_sec_keyring_cops = {
1618 .create_sec = gss_sec_create_kr,
1619 .destroy_sec = gss_sec_destroy_kr,
1620 .kill_sec = gss_sec_kill,
1621 .lookup_ctx = gss_sec_lookup_ctx_kr,
1622 .release_ctx = gss_sec_release_ctx_kr,
1623 .flush_ctx_cache = gss_sec_flush_ctx_cache_kr,
1624 .gc_ctx = gss_sec_gc_ctx_kr,
1625 .install_rctx = gss_sec_install_rctx,
1626 .alloc_reqbuf = gss_alloc_reqbuf,
1627 .free_reqbuf = gss_free_reqbuf,
1628 .alloc_repbuf = gss_alloc_repbuf,
1629 .free_repbuf = gss_free_repbuf,
1630 .enlarge_reqbuf = gss_enlarge_reqbuf,
1631 .display = gss_sec_display_kr,
1634 static struct ptlrpc_sec_sops gss_sec_keyring_sops = {
1635 .accept = gss_svc_accept_kr,
1636 .invalidate_ctx = gss_svc_invalidate_ctx,
1637 .alloc_rs = gss_svc_alloc_rs,
1638 .authorize = gss_svc_authorize,
1639 .free_rs = gss_svc_free_rs,
1640 .free_ctx = gss_svc_free_ctx,
1641 .prep_bulk = gss_svc_prep_bulk,
1642 .unwrap_bulk = gss_svc_unwrap_bulk,
1643 .wrap_bulk = gss_svc_wrap_bulk,
1644 .install_rctx = gss_svc_install_rctx_kr,
1647 static struct ptlrpc_sec_policy gss_policy_keyring = {
1648 .sp_owner = THIS_MODULE,
1649 .sp_name = "gss.keyring",
1650 .sp_policy = SPTLRPC_POLICY_GSS,
1651 .sp_cops = &gss_sec_keyring_cops,
1652 .sp_sops = &gss_sec_keyring_sops,
1656 int __init gss_init_keyring(void)
1660 rc = register_key_type(&gss_key_type);
1662 CERROR("failed to register keyring type: %d\n", rc);
1666 rc = sptlrpc_register_policy(&gss_policy_keyring);
1668 unregister_key_type(&gss_key_type);
1675 void __exit gss_exit_keyring(void)
1677 unregister_key_type(&gss_key_type);
1678 sptlrpc_unregister_policy(&gss_policy_keyring);