2 * Modifications for Lustre
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Copyright (c) 2011, 2014, Intel Corporation.
8 * Author: Eric Mei <ericm@clusterfs.com>
12 * linux/net/sunrpc/auth_gss.c
14 * RPCSEC_GSS client authentication.
16 * Copyright (c) 2000 The Regents of the University of Michigan.
17 * All rights reserved.
19 * Dug Song <dugsong@monkey.org>
20 * Andy Adamson <andros@umich.edu>
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. Neither the name of the University nor the names of its
32 * contributors may be used to endorse or promote products derived
33 * from this software without specific prior written permission.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
37 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 #define DEBUG_SUBSYSTEM S_SEC
50 #include <linux/init.h>
51 #include <linux/module.h>
52 #include <linux/slab.h>
53 #include <linux/dcache.h>
55 #include <linux/mutex.h>
56 #include <asm/atomic.h>
59 #include <obd_class.h>
60 #include <obd_support.h>
61 #include <obd_cksum.h>
62 #include <lustre/lustre_idl.h>
63 #include <lustre_net.h>
64 #include <lustre_import.h>
65 #include <lustre_sec.h>
68 #include "gss_internal.h"
71 #include <linux/crypto.h>
72 #include <linux/crc32.h>
75 * early reply have fixed size, respectively in privacy and integrity mode.
76 * so we calculate them only once.
78 static int gss_at_reply_off_integ;
79 static int gss_at_reply_off_priv;
82 static inline int msg_last_segidx(struct lustre_msg *msg)
84 LASSERT(msg->lm_bufcount > 0);
85 return msg->lm_bufcount - 1;
87 static inline int msg_last_seglen(struct lustre_msg *msg)
89 return msg->lm_buflens[msg_last_segidx(msg)];
92 /********************************************
94 ********************************************/
97 void gss_header_swabber(struct gss_header *ghdr)
99 __swab32s(&ghdr->gh_flags);
100 __swab32s(&ghdr->gh_proc);
101 __swab32s(&ghdr->gh_seq);
102 __swab32s(&ghdr->gh_svc);
103 __swab32s(&ghdr->gh_pad1);
104 __swab32s(&ghdr->gh_handle.len);
107 struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment,
110 struct gss_header *ghdr;
112 ghdr = lustre_msg_buf(msg, segment, sizeof(*ghdr));
117 gss_header_swabber(ghdr);
119 if (sizeof(*ghdr) + ghdr->gh_handle.len > msg->lm_buflens[segment]) {
120 CERROR("gss header has length %d, now %u received\n",
121 (int) sizeof(*ghdr) + ghdr->gh_handle.len,
122 msg->lm_buflens[segment]);
131 void gss_netobj_swabber(netobj_t *obj)
133 __swab32s(&obj->len);
136 netobj_t *gss_swab_netobj(struct lustre_msg *msg, int segment)
140 obj = lustre_swab_buf(msg, segment, sizeof(*obj), gss_netobj_swabber);
141 if (obj && sizeof(*obj) + obj->len > msg->lm_buflens[segment]) {
142 CERROR("netobj require length %u but only %u received\n",
143 (unsigned int) sizeof(*obj) + obj->len,
144 msg->lm_buflens[segment]);
153 * payload should be obtained from mechanism. but currently since we
154 * only support kerberos, we could simply use fixed value.
157 * - krb5 checksum: 20
159 * for privacy mode, payload also include the cipher text which has the same
160 * size as plain text, plus possible confounder, padding both at maximum cipher
163 #define GSS_KRB5_INTEG_MAX_PAYLOAD (40)
166 int gss_mech_payload(struct gss_ctx *mechctx, int msgsize, int privacy)
169 return GSS_KRB5_INTEG_MAX_PAYLOAD + 16 + 16 + 16 + msgsize;
171 return GSS_KRB5_INTEG_MAX_PAYLOAD;
175 * return signature size, otherwise < 0 to indicate error
177 static int gss_sign_msg(struct lustre_msg *msg,
178 struct gss_ctx *mechctx,
179 enum lustre_sec_part sp,
180 __u32 flags, __u32 proc, __u32 seq, __u32 svc,
183 struct gss_header *ghdr;
184 rawobj_t text[4], mic;
185 int textcnt, max_textcnt, mic_idx;
188 LASSERT(msg->lm_bufcount >= 2);
191 LASSERT(msg->lm_buflens[0] >=
192 sizeof(*ghdr) + (handle ? handle->len : 0));
193 ghdr = lustre_msg_buf(msg, 0, 0);
195 ghdr->gh_version = PTLRPC_GSS_VERSION;
196 ghdr->gh_sp = (__u8) sp;
197 ghdr->gh_flags = flags;
198 ghdr->gh_proc = proc;
202 /* fill in a fake one */
203 ghdr->gh_handle.len = 0;
205 ghdr->gh_handle.len = handle->len;
206 memcpy(ghdr->gh_handle.data, handle->data, handle->len);
209 /* no actual signature for null mode */
210 if (svc == SPTLRPC_SVC_NULL)
211 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
214 mic_idx = msg_last_segidx(msg);
215 max_textcnt = (svc == SPTLRPC_SVC_AUTH) ? 1 : mic_idx;
217 for (textcnt = 0; textcnt < max_textcnt; textcnt++) {
218 text[textcnt].len = msg->lm_buflens[textcnt];
219 text[textcnt].data = lustre_msg_buf(msg, textcnt, 0);
222 mic.len = msg->lm_buflens[mic_idx];
223 mic.data = lustre_msg_buf(msg, mic_idx, 0);
225 major = lgss_get_mic(mechctx, textcnt, text, 0, NULL, &mic);
226 if (major != GSS_S_COMPLETE) {
227 CERROR("fail to generate MIC: %08x\n", major);
230 LASSERT(mic.len <= msg->lm_buflens[mic_idx]);
232 return lustre_shrink_msg(msg, mic_idx, mic.len, 0);
239 __u32 gss_verify_msg(struct lustre_msg *msg,
240 struct gss_ctx *mechctx,
243 rawobj_t text[4], mic;
244 int textcnt, max_textcnt;
248 LASSERT(msg->lm_bufcount >= 2);
250 if (svc == SPTLRPC_SVC_NULL)
251 return GSS_S_COMPLETE;
253 mic_idx = msg_last_segidx(msg);
254 max_textcnt = (svc == SPTLRPC_SVC_AUTH) ? 1 : mic_idx;
256 for (textcnt = 0; textcnt < max_textcnt; textcnt++) {
257 text[textcnt].len = msg->lm_buflens[textcnt];
258 text[textcnt].data = lustre_msg_buf(msg, textcnt, 0);
261 mic.len = msg->lm_buflens[mic_idx];
262 mic.data = lustre_msg_buf(msg, mic_idx, 0);
264 major = lgss_verify_mic(mechctx, textcnt, text, 0, NULL, &mic);
265 if (major != GSS_S_COMPLETE)
266 CERROR("mic verify error: %08x\n", major);
272 * return gss error code
275 __u32 gss_unseal_msg(struct gss_ctx *mechctx,
276 struct lustre_msg *msgbuf,
277 int *msg_len, int msgbuf_len)
279 rawobj_t clear_obj, hdrobj, token;
285 if (msgbuf->lm_bufcount != 2) {
286 CERROR("invalid bufcount %d\n", msgbuf->lm_bufcount);
287 RETURN(GSS_S_FAILURE);
290 /* allocate a temporary clear text buffer, same sized as token,
291 * we assume the final clear text size <= token size */
292 clear_buflen = lustre_msg_buflen(msgbuf, 1);
293 OBD_ALLOC_LARGE(clear_buf, clear_buflen);
295 RETURN(GSS_S_FAILURE);
298 hdrobj.len = lustre_msg_buflen(msgbuf, 0);
299 hdrobj.data = lustre_msg_buf(msgbuf, 0, 0);
300 token.len = lustre_msg_buflen(msgbuf, 1);
301 token.data = lustre_msg_buf(msgbuf, 1, 0);
302 clear_obj.len = clear_buflen;
303 clear_obj.data = clear_buf;
305 major = lgss_unwrap(mechctx, &hdrobj, &token, &clear_obj);
306 if (major != GSS_S_COMPLETE) {
307 CERROR("unwrap message error: %08x\n", major);
308 GOTO(out_free, major = GSS_S_FAILURE);
310 LASSERT(clear_obj.len <= clear_buflen);
311 LASSERT(clear_obj.len <= msgbuf_len);
313 /* now the decrypted message */
314 memcpy(msgbuf, clear_obj.data, clear_obj.len);
315 *msg_len = clear_obj.len;
317 major = GSS_S_COMPLETE;
319 OBD_FREE_LARGE(clear_buf, clear_buflen);
323 /********************************************
324 * gss client context manipulation helpers *
325 ********************************************/
327 int cli_ctx_expire(struct ptlrpc_cli_ctx *ctx)
329 LASSERT(atomic_read(&ctx->cc_refcount));
331 if (!test_and_set_bit(PTLRPC_CTX_DEAD_BIT, &ctx->cc_flags)) {
332 if (!ctx->cc_early_expire)
333 clear_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
335 CWARN("ctx %p(%u->%s) get expired: %lu(%+lds)\n",
336 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
338 ctx->cc_expire == 0 ? 0 :
339 cfs_time_sub(ctx->cc_expire, cfs_time_current_sec()));
341 sptlrpc_cli_ctx_wakeup(ctx);
349 * return 1 if the context is dead.
351 int cli_ctx_check_death(struct ptlrpc_cli_ctx *ctx)
353 if (unlikely(cli_ctx_is_dead(ctx)))
356 /* expire is 0 means never expire. a newly created gss context
357 * which during upcall may has 0 expiration */
358 if (ctx->cc_expire == 0)
361 /* check real expiration */
362 if (cfs_time_after(ctx->cc_expire, cfs_time_current_sec()))
369 void gss_cli_ctx_uptodate(struct gss_cli_ctx *gctx)
371 struct ptlrpc_cli_ctx *ctx = &gctx->gc_base;
372 unsigned long ctx_expiry;
374 if (lgss_inquire_context(gctx->gc_mechctx, &ctx_expiry)) {
375 CERROR("ctx %p(%u): unable to inquire, expire it now\n",
376 gctx, ctx->cc_vcred.vc_uid);
377 ctx_expiry = 1; /* make it expired now */
380 ctx->cc_expire = gss_round_ctx_expiry(ctx_expiry,
381 ctx->cc_sec->ps_flvr.sf_flags);
383 /* At this point this ctx might have been marked as dead by
384 * someone else, in which case nobody will make further use
385 * of it. we don't care, and mark it UPTODATE will help
386 * destroying server side context when it be destroyed. */
387 set_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
389 if (sec_is_reverse(ctx->cc_sec)) {
390 CWARN("server installed reverse ctx %p idx "LPX64", "
391 "expiry %lu(%+lds)\n", ctx,
392 gss_handle_to_u64(&gctx->gc_handle),
394 cfs_time_sub(ctx->cc_expire, cfs_time_current_sec()));
396 CWARN("client refreshed ctx %p idx "LPX64" (%u->%s), "
397 "expiry %lu(%+lds)\n", ctx,
398 gss_handle_to_u64(&gctx->gc_handle),
399 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
401 cfs_time_sub(ctx->cc_expire, cfs_time_current_sec()));
403 /* install reverse svc ctx for root context */
404 if (ctx->cc_vcred.vc_uid == 0)
405 gss_sec_install_rctx(ctx->cc_sec->ps_import,
409 sptlrpc_cli_ctx_wakeup(ctx);
412 static void gss_cli_ctx_finalize(struct gss_cli_ctx *gctx)
414 LASSERT(gctx->gc_base.cc_sec);
416 if (gctx->gc_mechctx) {
417 lgss_delete_sec_context(&gctx->gc_mechctx);
418 gctx->gc_mechctx = NULL;
421 if (!rawobj_empty(&gctx->gc_svc_handle)) {
422 /* forward ctx: mark buddy reverse svcctx soon-expire. */
423 if (!sec_is_reverse(gctx->gc_base.cc_sec) &&
424 !rawobj_empty(&gctx->gc_svc_handle))
425 gss_svc_upcall_expire_rvs_ctx(&gctx->gc_svc_handle);
427 rawobj_free(&gctx->gc_svc_handle);
430 rawobj_free(&gctx->gc_handle);
434 * Based on sequence number algorithm as specified in RFC 2203.
436 * Modified for our own problem: arriving request has valid sequence number,
437 * but unwrapping request might cost a long time, after that its sequence
438 * are not valid anymore (fall behind the window). It rarely happen, mostly
439 * under extreme load.
441 * Note we should not check sequence before verifying the integrity of incoming
442 * request, because just one attacking request with high sequence number might
443 * cause all following requests be dropped.
445 * So here we use a multi-phase approach: prepare 2 sequence windows,
446 * "main window" for normal sequence and "back window" for fall behind sequence.
447 * and 3-phase checking mechanism:
448 * 0 - before integrity verification, perform an initial sequence checking in
449 * main window, which only tries and doesn't actually set any bits. if the
450 * sequence is high above the window or fits in the window and the bit
451 * is 0, then accept and proceed to integrity verification. otherwise
452 * reject this sequence.
453 * 1 - after integrity verification, check in main window again. if this
454 * sequence is high above the window or fits in the window and the bit
455 * is 0, then set the bit and accept; if it fits in the window but bit
456 * already set, then reject; if it falls behind the window, then proceed
458 * 2 - check in back window. if it is high above the window or fits in the
459 * window and the bit is 0, then set the bit and accept. otherwise reject.
461 * \return 1: looks like a replay
463 * \return -1: is a replay
465 * Note phase 0 is necessary, because otherwise replay attacking request of
466 * sequence which between the 2 windows can't be detected.
468 * This mechanism can't totally solve the problem, but could help reduce the
469 * number of valid requests be dropped.
472 int gss_do_check_seq(unsigned long *window, __u32 win_size, __u32 *max_seq,
473 __u32 seq_num, int phase)
475 LASSERT(phase >= 0 && phase <= 2);
477 if (seq_num > *max_seq) {
479 * 1. high above the window
484 if (seq_num >= *max_seq + win_size) {
485 memset(window, 0, win_size / 8);
488 while(*max_seq < seq_num) {
490 __clear_bit((*max_seq) % win_size, window);
493 __set_bit(seq_num % win_size, window);
494 } else if (seq_num + win_size <= *max_seq) {
496 * 2. low behind the window
498 if (phase == 0 || phase == 2)
501 CWARN("seq %u is %u behind (size %d), check backup window\n",
502 seq_num, *max_seq - win_size - seq_num, win_size);
506 * 3. fit into the window
510 if (test_bit(seq_num % win_size, window))
515 if (__test_and_set_bit(seq_num % win_size, window))
524 CERROR("seq %u (%s %s window) is a replay: max %u, winsize %d\n",
526 seq_num + win_size > *max_seq ? "in" : "behind",
527 phase == 2 ? "backup " : "main",
533 * Based on sequence number algorithm as specified in RFC 2203.
535 * if @set == 0: initial check, don't set any bit in window
536 * if @sec == 1: final check, set bit in window
538 int gss_check_seq_num(struct gss_svc_seq_data *ssd, __u32 seq_num, int set)
542 spin_lock(&ssd->ssd_lock);
548 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
549 &ssd->ssd_max_main, seq_num, 0);
551 gss_stat_oos_record_svc(0, 1);
554 * phase 1 checking main window
556 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
557 &ssd->ssd_max_main, seq_num, 1);
560 gss_stat_oos_record_svc(1, 1);
566 * phase 2 checking back window
568 rc = gss_do_check_seq(ssd->ssd_win_back, GSS_SEQ_WIN_BACK,
569 &ssd->ssd_max_back, seq_num, 2);
571 gss_stat_oos_record_svc(2, 1);
573 gss_stat_oos_record_svc(2, 0);
576 spin_unlock(&ssd->ssd_lock);
580 /***************************************
582 ***************************************/
584 static inline int gss_cli_payload(struct ptlrpc_cli_ctx *ctx,
585 int msgsize, int privacy)
587 return gss_mech_payload(NULL, msgsize, privacy);
590 static int gss_cli_bulk_payload(struct ptlrpc_cli_ctx *ctx,
591 struct sptlrpc_flavor *flvr,
594 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
596 LASSERT(SPTLRPC_FLVR_BULK_TYPE(flvr->sf_rpc) == SPTLRPC_BULK_DEFAULT);
598 if ((!reply && !read) || (reply && read)) {
599 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
600 case SPTLRPC_BULK_SVC_NULL:
602 case SPTLRPC_BULK_SVC_INTG:
603 payload += gss_cli_payload(ctx, 0, 0);
605 case SPTLRPC_BULK_SVC_PRIV:
606 payload += gss_cli_payload(ctx, 0, 1);
608 case SPTLRPC_BULK_SVC_AUTH:
617 int gss_cli_ctx_match(struct ptlrpc_cli_ctx *ctx, struct vfs_cred *vcred)
619 return (ctx->cc_vcred.vc_uid == vcred->vc_uid);
622 void gss_cli_ctx_flags2str(unsigned long flags, char *buf, int bufsize)
626 if (flags & PTLRPC_CTX_NEW)
627 strlcat(buf, "new,", bufsize);
628 if (flags & PTLRPC_CTX_UPTODATE)
629 strlcat(buf, "uptodate,", bufsize);
630 if (flags & PTLRPC_CTX_DEAD)
631 strlcat(buf, "dead,", bufsize);
632 if (flags & PTLRPC_CTX_ERROR)
633 strlcat(buf, "error,", bufsize);
634 if (flags & PTLRPC_CTX_CACHED)
635 strlcat(buf, "cached,", bufsize);
636 if (flags & PTLRPC_CTX_ETERNAL)
637 strlcat(buf, "eternal,", bufsize);
639 strlcat(buf, "-,", bufsize);
642 int gss_cli_ctx_sign(struct ptlrpc_cli_ctx *ctx,
643 struct ptlrpc_request *req)
645 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
646 __u32 flags = 0, seq, svc;
650 LASSERT(req->rq_reqbuf);
651 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
652 LASSERT(req->rq_cli_ctx == ctx);
654 /* nothing to do for context negotiation RPCs */
655 if (req->rq_ctx_init)
658 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
659 if (req->rq_pack_bulk)
660 flags |= LUSTRE_GSS_PACK_BULK;
661 if (req->rq_pack_udesc)
662 flags |= LUSTRE_GSS_PACK_USER;
665 seq = atomic_inc_return(&gctx->gc_seq);
667 rc = gss_sign_msg(req->rq_reqbuf, gctx->gc_mechctx,
668 ctx->cc_sec->ps_part,
669 flags, gctx->gc_proc, seq, svc,
674 /* gss_sign_msg() msg might take long time to finish, in which period
675 * more rpcs could be wrapped up and sent out. if we found too many
676 * of them we should repack this rpc, because sent it too late might
677 * lead to the sequence number fall behind the window on server and
678 * be dropped. also applies to gss_cli_ctx_seal().
680 * Note: null mode doesn't check sequence number. */
681 if (svc != SPTLRPC_SVC_NULL &&
682 atomic_read(&gctx->gc_seq) - seq > GSS_SEQ_REPACK_THRESHOLD) {
683 int behind = atomic_read(&gctx->gc_seq) - seq;
685 gss_stat_oos_record_cli(behind);
686 CWARN("req %p: %u behind, retry signing\n", req, behind);
690 req->rq_reqdata_len = rc;
695 int gss_cli_ctx_handle_err_notify(struct ptlrpc_cli_ctx *ctx,
696 struct ptlrpc_request *req,
697 struct gss_header *ghdr)
699 struct gss_err_header *errhdr;
702 LASSERT(ghdr->gh_proc == PTLRPC_GSS_PROC_ERR);
704 errhdr = (struct gss_err_header *) ghdr;
706 CWARN("req x"LPU64"/t"LPU64", ctx %p idx "LPX64"(%u->%s): "
707 "%sserver respond (%08x/%08x)\n",
708 req->rq_xid, req->rq_transno, ctx,
709 gss_handle_to_u64(&ctx2gctx(ctx)->gc_handle),
710 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
711 sec_is_reverse(ctx->cc_sec) ? "reverse" : "",
712 errhdr->gh_major, errhdr->gh_minor);
714 /* context fini rpc, let it failed */
715 if (req->rq_ctx_fini) {
716 CWARN("context fini rpc failed\n");
720 /* reverse sec, just return error, don't expire this ctx because it's
721 * crucial to callback rpcs. note if the callback rpc failed because
722 * of bit flip during network transfer, the client will be evicted
723 * directly. so more gracefully we probably want let it retry for
724 * number of times. */
725 if (sec_is_reverse(ctx->cc_sec))
728 if (errhdr->gh_major != GSS_S_NO_CONTEXT &&
729 errhdr->gh_major != GSS_S_BAD_SIG)
732 /* server return NO_CONTEXT might be caused by context expire
733 * or server reboot/failover. we try to refresh a new ctx which
734 * be transparent to upper layer.
736 * In some cases, our gss handle is possible to be incidentally
737 * identical to another handle since the handle itself is not
738 * fully random. In krb5 case, the GSS_S_BAD_SIG will be
739 * returned, maybe other gss error for other mechanism.
741 * if we add new mechanism, make sure the correct error are
742 * returned in this case. */
743 CWARN("%s: server might lost the context, retrying\n",
744 errhdr->gh_major == GSS_S_NO_CONTEXT ? "NO_CONTEXT" : "BAD_SIG");
746 sptlrpc_cli_ctx_expire(ctx);
748 /* we need replace the ctx right here, otherwise during
749 * resent we'll hit the logic in sptlrpc_req_refresh_ctx()
750 * which keep the ctx with RESEND flag, thus we'll never
751 * get rid of this ctx. */
752 rc = sptlrpc_req_replace_dead_ctx(req);
759 int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
760 struct ptlrpc_request *req)
762 struct gss_cli_ctx *gctx;
763 struct gss_header *ghdr, *reqhdr;
764 struct lustre_msg *msg = req->rq_repdata;
766 int pack_bulk, swabbed, rc = 0;
769 LASSERT(req->rq_cli_ctx == ctx);
772 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
774 /* special case for context negotiation, rq_repmsg/rq_replen actually
775 * are not used currently. but early reply always be treated normally */
776 if (req->rq_ctx_init && !req->rq_early) {
777 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
778 req->rq_replen = msg->lm_buflens[1];
782 if (msg->lm_bufcount < 2 || msg->lm_bufcount > 4) {
783 CERROR("unexpected bufcount %u\n", msg->lm_bufcount);
787 swabbed = ptlrpc_rep_need_swab(req);
789 ghdr = gss_swab_header(msg, 0, swabbed);
791 CERROR("can't decode gss header\n");
796 reqhdr = lustre_msg_buf(msg, 0, sizeof(*reqhdr));
799 if (ghdr->gh_version != reqhdr->gh_version) {
800 CERROR("gss version %u mismatch, expect %u\n",
801 ghdr->gh_version, reqhdr->gh_version);
805 switch (ghdr->gh_proc) {
806 case PTLRPC_GSS_PROC_DATA:
807 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
809 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
810 CERROR("%s bulk flag in reply\n",
811 req->rq_pack_bulk ? "missing" : "unexpected");
815 if (ghdr->gh_seq != reqhdr->gh_seq) {
816 CERROR("seqnum %u mismatch, expect %u\n",
817 ghdr->gh_seq, reqhdr->gh_seq);
821 if (ghdr->gh_svc != reqhdr->gh_svc) {
822 CERROR("svc %u mismatch, expect %u\n",
823 ghdr->gh_svc, reqhdr->gh_svc);
828 gss_header_swabber(ghdr);
830 major = gss_verify_msg(msg, gctx->gc_mechctx, reqhdr->gh_svc);
831 if (major != GSS_S_COMPLETE) {
832 CERROR("failed to verify reply: %x\n", major);
836 if (req->rq_early && reqhdr->gh_svc == SPTLRPC_SVC_NULL) {
839 cksum = crc32_le(!(__u32) 0,
840 lustre_msg_buf(msg, 1, 0),
841 lustre_msg_buflen(msg, 1));
842 if (cksum != msg->lm_cksum) {
843 CWARN("early reply checksum mismatch: "
844 "%08x != %08x\n", cksum, msg->lm_cksum);
850 /* bulk checksum is right after the lustre msg */
851 if (msg->lm_bufcount < 3) {
852 CERROR("Invalid reply bufcount %u\n",
857 rc = bulk_sec_desc_unpack(msg, 2, swabbed);
859 CERROR("unpack bulk desc: %d\n", rc);
864 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
865 req->rq_replen = msg->lm_buflens[1];
867 case PTLRPC_GSS_PROC_ERR:
869 CERROR("server return error with early reply\n");
872 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
876 CERROR("unknown gss proc %d\n", ghdr->gh_proc);
883 int gss_cli_ctx_seal(struct ptlrpc_cli_ctx *ctx,
884 struct ptlrpc_request *req)
886 struct gss_cli_ctx *gctx;
887 rawobj_t hdrobj, msgobj, token;
888 struct gss_header *ghdr;
889 __u32 buflens[2], major;
893 LASSERT(req->rq_clrbuf);
894 LASSERT(req->rq_cli_ctx == ctx);
895 LASSERT(req->rq_reqlen);
897 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
899 /* final clear data length */
900 req->rq_clrdata_len = lustre_msg_size_v2(req->rq_clrbuf->lm_bufcount,
901 req->rq_clrbuf->lm_buflens);
903 /* calculate wire data length */
904 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
905 buflens[1] = gss_cli_payload(&gctx->gc_base, req->rq_clrdata_len, 1);
906 wiresize = lustre_msg_size_v2(2, buflens);
908 /* allocate wire buffer */
911 LASSERT(req->rq_reqbuf);
912 LASSERT(req->rq_reqbuf != req->rq_clrbuf);
913 LASSERT(req->rq_reqbuf_len >= wiresize);
915 OBD_ALLOC_LARGE(req->rq_reqbuf, wiresize);
918 req->rq_reqbuf_len = wiresize;
921 lustre_init_msg_v2(req->rq_reqbuf, 2, buflens, NULL);
922 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
925 ghdr = lustre_msg_buf(req->rq_reqbuf, 0, 0);
926 ghdr->gh_version = PTLRPC_GSS_VERSION;
927 ghdr->gh_sp = (__u8) ctx->cc_sec->ps_part;
929 ghdr->gh_proc = gctx->gc_proc;
930 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
931 ghdr->gh_handle.len = gctx->gc_handle.len;
932 memcpy(ghdr->gh_handle.data, gctx->gc_handle.data, gctx->gc_handle.len);
933 if (req->rq_pack_bulk)
934 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
935 if (req->rq_pack_udesc)
936 ghdr->gh_flags |= LUSTRE_GSS_PACK_USER;
939 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
942 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
943 hdrobj.data = (__u8 *) ghdr;
944 msgobj.len = req->rq_clrdata_len;
945 msgobj.data = (__u8 *) req->rq_clrbuf;
946 token.len = lustre_msg_buflen(req->rq_reqbuf, 1);
947 token.data = lustre_msg_buf(req->rq_reqbuf, 1, 0);
949 major = lgss_wrap(gctx->gc_mechctx, &hdrobj, &msgobj,
950 req->rq_clrbuf_len, &token);
951 if (major != GSS_S_COMPLETE) {
952 CERROR("priv: wrap message error: %08x\n", major);
953 GOTO(err_free, rc = -EPERM);
955 LASSERT(token.len <= buflens[1]);
957 /* see explain in gss_cli_ctx_sign() */
958 if (unlikely(atomic_read(&gctx->gc_seq) - ghdr->gh_seq >
959 GSS_SEQ_REPACK_THRESHOLD)) {
960 int behind = atomic_read(&gctx->gc_seq) - ghdr->gh_seq;
962 gss_stat_oos_record_cli(behind);
963 CWARN("req %p: %u behind, retry sealing\n", req, behind);
965 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
969 /* now set the final wire data length */
970 req->rq_reqdata_len = lustre_shrink_msg(req->rq_reqbuf, 1, token.len,0);
975 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
976 req->rq_reqbuf = NULL;
977 req->rq_reqbuf_len = 0;
982 int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
983 struct ptlrpc_request *req)
985 struct gss_cli_ctx *gctx;
986 struct gss_header *ghdr;
987 struct lustre_msg *msg = req->rq_repdata;
988 int msglen, pack_bulk, swabbed, rc;
992 LASSERT(req->rq_cli_ctx == ctx);
993 LASSERT(req->rq_ctx_init == 0);
996 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
997 swabbed = ptlrpc_rep_need_swab(req);
999 ghdr = gss_swab_header(msg, 0, swabbed);
1001 CERROR("can't decode gss header\n");
1006 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
1007 CERROR("gss version %u mismatch, expect %u\n",
1008 ghdr->gh_version, PTLRPC_GSS_VERSION);
1012 switch (ghdr->gh_proc) {
1013 case PTLRPC_GSS_PROC_DATA:
1014 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
1016 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
1017 CERROR("%s bulk flag in reply\n",
1018 req->rq_pack_bulk ? "missing" : "unexpected");
1023 gss_header_swabber(ghdr);
1025 /* use rq_repdata_len as buffer size, which assume unseal
1026 * doesn't need extra memory space. for precise control, we'd
1027 * better calculate out actual buffer size as
1028 * (repbuf_len - offset - repdata_len) */
1029 major = gss_unseal_msg(gctx->gc_mechctx, msg,
1030 &msglen, req->rq_repdata_len);
1031 if (major != GSS_S_COMPLETE) {
1032 CERROR("failed to unwrap reply: %x\n", major);
1037 swabbed = __lustre_unpack_msg(msg, msglen);
1039 CERROR("Failed to unpack after decryption\n");
1043 if (msg->lm_bufcount < 1) {
1044 CERROR("Invalid reply buffer: empty\n");
1049 if (msg->lm_bufcount < 2) {
1050 CERROR("bufcount %u: missing bulk sec desc\n",
1055 /* bulk checksum is the last segment */
1056 if (bulk_sec_desc_unpack(msg, msg->lm_bufcount - 1,
1061 req->rq_repmsg = lustre_msg_buf(msg, 0, 0);
1062 req->rq_replen = msg->lm_buflens[0];
1066 case PTLRPC_GSS_PROC_ERR:
1067 if (req->rq_early) {
1068 CERROR("server return error with early reply\n");
1071 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
1075 CERROR("unexpected proc %d\n", ghdr->gh_proc);
1082 /*********************************************
1083 * reverse context installation *
1084 *********************************************/
1087 int gss_install_rvs_svc_ctx(struct obd_import *imp,
1088 struct gss_sec *gsec,
1089 struct gss_cli_ctx *gctx)
1091 return gss_svc_upcall_install_rvs_ctx(imp, gsec, gctx);
1094 /*********************************************
1095 * GSS security APIs *
1096 *********************************************/
1097 int gss_sec_create_common(struct gss_sec *gsec,
1098 struct ptlrpc_sec_policy *policy,
1099 struct obd_import *imp,
1100 struct ptlrpc_svc_ctx *svcctx,
1101 struct sptlrpc_flavor *sf)
1103 struct ptlrpc_sec *sec;
1106 LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_GSS);
1108 gsec->gs_mech = lgss_subflavor_to_mech(
1109 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1110 if (!gsec->gs_mech) {
1111 CERROR("gss backend 0x%x not found\n",
1112 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1116 spin_lock_init(&gsec->gs_lock);
1117 gsec->gs_rvs_hdl = 0ULL;
1119 /* initialize upper ptlrpc_sec */
1120 sec = &gsec->gs_base;
1121 sec->ps_policy = policy;
1122 atomic_set(&sec->ps_refcount, 0);
1123 atomic_set(&sec->ps_nctx, 0);
1124 sec->ps_id = sptlrpc_get_next_secid();
1126 sec->ps_import = class_import_get(imp);
1127 spin_lock_init(&sec->ps_lock);
1128 INIT_LIST_HEAD(&sec->ps_gc_list);
1131 sec->ps_gc_interval = GSS_GC_INTERVAL;
1133 LASSERT(sec_is_reverse(sec));
1135 /* never do gc on reverse sec */
1136 sec->ps_gc_interval = 0;
1139 if (SPTLRPC_FLVR_BULK_SVC(sec->ps_flvr.sf_rpc) == SPTLRPC_BULK_SVC_PRIV)
1140 sptlrpc_enc_pool_add_user();
1142 CDEBUG(D_SEC, "create %s%s@%p\n", (svcctx ? "reverse " : ""),
1143 policy->sp_name, gsec);
1147 void gss_sec_destroy_common(struct gss_sec *gsec)
1149 struct ptlrpc_sec *sec = &gsec->gs_base;
1152 LASSERT(sec->ps_import);
1153 LASSERT(atomic_read(&sec->ps_refcount) == 0);
1154 LASSERT(atomic_read(&sec->ps_nctx) == 0);
1156 if (gsec->gs_mech) {
1157 lgss_mech_put(gsec->gs_mech);
1158 gsec->gs_mech = NULL;
1161 class_import_put(sec->ps_import);
1163 if (SPTLRPC_FLVR_BULK_SVC(sec->ps_flvr.sf_rpc) == SPTLRPC_BULK_SVC_PRIV)
1164 sptlrpc_enc_pool_del_user();
1169 void gss_sec_kill(struct ptlrpc_sec *sec)
1174 int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
1175 struct ptlrpc_cli_ctx *ctx,
1176 struct ptlrpc_ctx_ops *ctxops,
1177 struct vfs_cred *vcred)
1179 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1182 atomic_set(&gctx->gc_seq, 0);
1184 INIT_HLIST_NODE(&ctx->cc_cache);
1185 atomic_set(&ctx->cc_refcount, 0);
1187 ctx->cc_ops = ctxops;
1189 ctx->cc_flags = PTLRPC_CTX_NEW;
1190 ctx->cc_vcred = *vcred;
1191 spin_lock_init(&ctx->cc_lock);
1192 INIT_LIST_HEAD(&ctx->cc_req_list);
1193 INIT_LIST_HEAD(&ctx->cc_gc_chain);
1195 /* take a ref on belonging sec, balanced in ctx destroying */
1196 atomic_inc(&sec->ps_refcount);
1197 /* statistic only */
1198 atomic_inc(&sec->ps_nctx);
1200 CDEBUG(D_SEC, "%s@%p: create ctx %p(%u->%s)\n",
1201 sec->ps_policy->sp_name, ctx->cc_sec,
1202 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1208 * 1: the context has been taken care of by someone else
1209 * 0: proceed to really destroy the context locally
1211 int gss_cli_ctx_fini_common(struct ptlrpc_sec *sec,
1212 struct ptlrpc_cli_ctx *ctx)
1214 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1216 LASSERT(atomic_read(&sec->ps_nctx) > 0);
1217 LASSERT(atomic_read(&ctx->cc_refcount) == 0);
1218 LASSERT(ctx->cc_sec == sec);
1221 * remove UPTODATE flag of reverse ctx thus we won't send fini rpc,
1222 * this is to avoid potential problems of client side reverse svc ctx
1223 * be mis-destroyed in various recovery senarios. anyway client can
1224 * manage its reverse ctx well by associating it with its buddy ctx.
1226 if (sec_is_reverse(sec))
1227 ctx->cc_flags &= ~PTLRPC_CTX_UPTODATE;
1229 if (gctx->gc_mechctx) {
1230 /* the final context fini rpc will use this ctx too, and it's
1231 * asynchronous which finished by request_out_callback(). so
1232 * we add refcount, whoever drop finally drop the refcount to
1233 * 0 should responsible for the rest of destroy. */
1234 atomic_inc(&ctx->cc_refcount);
1236 gss_do_ctx_fini_rpc(gctx);
1237 gss_cli_ctx_finalize(gctx);
1239 if (!atomic_dec_and_test(&ctx->cc_refcount))
1243 if (sec_is_reverse(sec))
1244 CWARN("reverse sec %p: destroy ctx %p\n",
1247 CWARN("%s@%p: destroy ctx %p(%u->%s)\n",
1248 sec->ps_policy->sp_name, ctx->cc_sec,
1249 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1255 int gss_alloc_reqbuf_intg(struct ptlrpc_sec *sec,
1256 struct ptlrpc_request *req,
1257 int svc, int msgsize)
1259 int bufsize, txtsize;
1265 * on-wire data layout:
1268 * - user descriptor (optional)
1269 * - bulk sec descriptor (optional)
1270 * - signature (optional)
1271 * - svc == NULL: NULL
1272 * - svc == AUTH: signature of gss header
1273 * - svc == INTG: signature of all above
1275 * if this is context negotiation, reserver fixed space
1276 * at the last (signature) segment regardless of svc mode.
1279 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1280 txtsize = buflens[0];
1282 buflens[1] = msgsize;
1283 if (svc == SPTLRPC_SVC_INTG)
1284 txtsize += buflens[1];
1286 if (req->rq_pack_udesc) {
1287 buflens[bufcnt] = sptlrpc_current_user_desc_size();
1288 if (svc == SPTLRPC_SVC_INTG)
1289 txtsize += buflens[bufcnt];
1293 if (req->rq_pack_bulk) {
1294 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1296 0, req->rq_bulk_read);
1297 if (svc == SPTLRPC_SVC_INTG)
1298 txtsize += buflens[bufcnt];
1302 if (req->rq_ctx_init)
1303 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1304 else if (svc != SPTLRPC_SVC_NULL)
1305 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1307 bufsize = lustre_msg_size_v2(bufcnt, buflens);
1309 if (!req->rq_reqbuf) {
1310 bufsize = size_roundup_power2(bufsize);
1312 OBD_ALLOC_LARGE(req->rq_reqbuf, bufsize);
1313 if (!req->rq_reqbuf)
1316 req->rq_reqbuf_len = bufsize;
1318 LASSERT(req->rq_pool);
1319 LASSERT(req->rq_reqbuf_len >= bufsize);
1320 memset(req->rq_reqbuf, 0, bufsize);
1323 lustre_init_msg_v2(req->rq_reqbuf, bufcnt, buflens, NULL);
1324 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
1326 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, msgsize);
1327 LASSERT(req->rq_reqmsg);
1329 /* pack user desc here, later we might leave current user's process */
1330 if (req->rq_pack_udesc)
1331 sptlrpc_pack_user_desc(req->rq_reqbuf, 2);
1337 int gss_alloc_reqbuf_priv(struct ptlrpc_sec *sec,
1338 struct ptlrpc_request *req,
1341 __u32 ibuflens[3], wbuflens[2];
1343 int clearsize, wiresize;
1346 LASSERT(req->rq_clrbuf == NULL);
1347 LASSERT(req->rq_clrbuf_len == 0);
1349 /* Inner (clear) buffers
1351 * - user descriptor (optional)
1352 * - bulk checksum (optional)
1355 ibuflens[0] = msgsize;
1357 if (req->rq_pack_udesc)
1358 ibuflens[ibufcnt++] = sptlrpc_current_user_desc_size();
1359 if (req->rq_pack_bulk)
1360 ibuflens[ibufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1364 clearsize = lustre_msg_size_v2(ibufcnt, ibuflens);
1365 /* to allow append padding during encryption */
1366 clearsize += GSS_MAX_CIPHER_BLOCK;
1368 /* Wrapper (wire) buffers
1372 wbuflens[0] = PTLRPC_GSS_HEADER_SIZE;
1373 wbuflens[1] = gss_cli_payload(req->rq_cli_ctx, clearsize, 1);
1374 wiresize = lustre_msg_size_v2(2, wbuflens);
1377 /* rq_reqbuf is preallocated */
1378 LASSERT(req->rq_reqbuf);
1379 LASSERT(req->rq_reqbuf_len >= wiresize);
1381 memset(req->rq_reqbuf, 0, req->rq_reqbuf_len);
1383 /* if the pre-allocated buffer is big enough, we just pack
1384 * both clear buf & request buf in it, to avoid more alloc. */
1385 if (clearsize + wiresize <= req->rq_reqbuf_len) {
1387 (void *) (((char *) req->rq_reqbuf) + wiresize);
1389 CWARN("pre-allocated buf size %d is not enough for "
1390 "both clear (%d) and cipher (%d) text, proceed "
1391 "with extra allocation\n", req->rq_reqbuf_len,
1392 clearsize, wiresize);
1396 if (!req->rq_clrbuf) {
1397 clearsize = size_roundup_power2(clearsize);
1399 OBD_ALLOC_LARGE(req->rq_clrbuf, clearsize);
1400 if (!req->rq_clrbuf)
1403 req->rq_clrbuf_len = clearsize;
1405 lustre_init_msg_v2(req->rq_clrbuf, ibufcnt, ibuflens, NULL);
1406 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, msgsize);
1408 if (req->rq_pack_udesc)
1409 sptlrpc_pack_user_desc(req->rq_clrbuf, 1);
1415 * NOTE: any change of request buffer allocation should also consider
1416 * changing enlarge_reqbuf() series functions.
1418 int gss_alloc_reqbuf(struct ptlrpc_sec *sec,
1419 struct ptlrpc_request *req,
1422 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1424 LASSERT(!req->rq_pack_bulk ||
1425 (req->rq_bulk_read || req->rq_bulk_write));
1428 case SPTLRPC_SVC_NULL:
1429 case SPTLRPC_SVC_AUTH:
1430 case SPTLRPC_SVC_INTG:
1431 return gss_alloc_reqbuf_intg(sec, req, svc, msgsize);
1432 case SPTLRPC_SVC_PRIV:
1433 return gss_alloc_reqbuf_priv(sec, req, msgsize);
1435 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1440 void gss_free_reqbuf(struct ptlrpc_sec *sec,
1441 struct ptlrpc_request *req)
1446 LASSERT(!req->rq_pool || req->rq_reqbuf);
1447 privacy = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc) == SPTLRPC_SVC_PRIV;
1449 if (!req->rq_clrbuf)
1450 goto release_reqbuf;
1452 /* release clear buffer */
1454 LASSERT(req->rq_clrbuf_len);
1456 if (req->rq_pool == NULL ||
1457 req->rq_clrbuf < req->rq_reqbuf ||
1458 (char *) req->rq_clrbuf >=
1459 (char *) req->rq_reqbuf + req->rq_reqbuf_len)
1460 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1462 req->rq_clrbuf = NULL;
1463 req->rq_clrbuf_len = 0;
1466 if (!req->rq_pool && req->rq_reqbuf) {
1467 LASSERT(req->rq_reqbuf_len);
1469 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1470 req->rq_reqbuf = NULL;
1471 req->rq_reqbuf_len = 0;
1477 static int do_alloc_repbuf(struct ptlrpc_request *req, int bufsize)
1479 bufsize = size_roundup_power2(bufsize);
1481 OBD_ALLOC_LARGE(req->rq_repbuf, bufsize);
1482 if (!req->rq_repbuf)
1485 req->rq_repbuf_len = bufsize;
1490 int gss_alloc_repbuf_intg(struct ptlrpc_sec *sec,
1491 struct ptlrpc_request *req,
1492 int svc, int msgsize)
1500 * on-wire data layout:
1503 * - bulk sec descriptor (optional)
1504 * - signature (optional)
1505 * - svc == NULL: NULL
1506 * - svc == AUTH: signature of gss header
1507 * - svc == INTG: signature of all above
1509 * if this is context negotiation, reserver fixed space
1510 * at the last (signature) segment regardless of svc mode.
1513 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1514 txtsize = buflens[0];
1516 buflens[1] = msgsize;
1517 if (svc == SPTLRPC_SVC_INTG)
1518 txtsize += buflens[1];
1520 if (req->rq_pack_bulk) {
1521 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1523 1, req->rq_bulk_read);
1524 if (svc == SPTLRPC_SVC_INTG)
1525 txtsize += buflens[bufcnt];
1529 if (req->rq_ctx_init)
1530 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1531 else if (svc != SPTLRPC_SVC_NULL)
1532 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1534 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1536 /* add space for early reply */
1537 alloc_size += gss_at_reply_off_integ;
1539 return do_alloc_repbuf(req, alloc_size);
1543 int gss_alloc_repbuf_priv(struct ptlrpc_sec *sec,
1544 struct ptlrpc_request *req,
1554 buflens[0] = msgsize;
1556 if (req->rq_pack_bulk)
1557 buflens[bufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1559 1, req->rq_bulk_read);
1560 txtsize = lustre_msg_size_v2(bufcnt, buflens);
1561 txtsize += GSS_MAX_CIPHER_BLOCK;
1563 /* wrapper buffers */
1565 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1566 buflens[1] = gss_cli_payload(req->rq_cli_ctx, txtsize, 1);
1568 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1569 /* add space for early reply */
1570 alloc_size += gss_at_reply_off_priv;
1572 return do_alloc_repbuf(req, alloc_size);
1575 int gss_alloc_repbuf(struct ptlrpc_sec *sec,
1576 struct ptlrpc_request *req,
1579 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1582 LASSERT(!req->rq_pack_bulk ||
1583 (req->rq_bulk_read || req->rq_bulk_write));
1586 case SPTLRPC_SVC_NULL:
1587 case SPTLRPC_SVC_AUTH:
1588 case SPTLRPC_SVC_INTG:
1589 return gss_alloc_repbuf_intg(sec, req, svc, msgsize);
1590 case SPTLRPC_SVC_PRIV:
1591 return gss_alloc_repbuf_priv(sec, req, msgsize);
1593 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1598 void gss_free_repbuf(struct ptlrpc_sec *sec,
1599 struct ptlrpc_request *req)
1601 OBD_FREE_LARGE(req->rq_repbuf, req->rq_repbuf_len);
1602 req->rq_repbuf = NULL;
1603 req->rq_repbuf_len = 0;
1604 req->rq_repdata = NULL;
1605 req->rq_repdata_len = 0;
1608 static int get_enlarged_msgsize(struct lustre_msg *msg,
1609 int segment, int newsize)
1611 int save, newmsg_size;
1613 LASSERT(newsize >= msg->lm_buflens[segment]);
1615 save = msg->lm_buflens[segment];
1616 msg->lm_buflens[segment] = newsize;
1617 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1618 msg->lm_buflens[segment] = save;
1623 static int get_enlarged_msgsize2(struct lustre_msg *msg,
1624 int segment1, int newsize1,
1625 int segment2, int newsize2)
1627 int save1, save2, newmsg_size;
1629 LASSERT(newsize1 >= msg->lm_buflens[segment1]);
1630 LASSERT(newsize2 >= msg->lm_buflens[segment2]);
1632 save1 = msg->lm_buflens[segment1];
1633 save2 = msg->lm_buflens[segment2];
1634 msg->lm_buflens[segment1] = newsize1;
1635 msg->lm_buflens[segment2] = newsize2;
1636 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1637 msg->lm_buflens[segment1] = save1;
1638 msg->lm_buflens[segment2] = save2;
1644 int gss_enlarge_reqbuf_intg(struct ptlrpc_sec *sec,
1645 struct ptlrpc_request *req,
1647 int segment, int newsize)
1649 struct lustre_msg *newbuf;
1650 int txtsize, sigsize = 0, i;
1651 int newmsg_size, newbuf_size;
1654 * gss header is at seg 0;
1655 * embedded msg is at seg 1;
1656 * signature (if any) is at the last seg
1658 LASSERT(req->rq_reqbuf);
1659 LASSERT(req->rq_reqbuf_len > req->rq_reqlen);
1660 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
1661 LASSERT(lustre_msg_buf(req->rq_reqbuf, 1, 0) == req->rq_reqmsg);
1663 /* 1. compute new embedded msg size */
1664 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1665 LASSERT(newmsg_size >= req->rq_reqbuf->lm_buflens[1]);
1667 /* 2. compute new wrapper msg size */
1668 if (svc == SPTLRPC_SVC_NULL) {
1669 /* no signature, get size directly */
1670 newbuf_size = get_enlarged_msgsize(req->rq_reqbuf,
1673 txtsize = req->rq_reqbuf->lm_buflens[0];
1675 if (svc == SPTLRPC_SVC_INTG) {
1676 for (i = 1; i < req->rq_reqbuf->lm_bufcount; i++)
1677 txtsize += req->rq_reqbuf->lm_buflens[i];
1678 txtsize += newmsg_size - req->rq_reqbuf->lm_buflens[1];
1681 sigsize = gss_cli_payload(req->rq_cli_ctx, txtsize, 0);
1682 LASSERT(sigsize >= msg_last_seglen(req->rq_reqbuf));
1684 newbuf_size = get_enlarged_msgsize2(
1687 msg_last_segidx(req->rq_reqbuf),
1691 /* request from pool should always have enough buffer */
1692 LASSERT(!req->rq_pool || req->rq_reqbuf_len >= newbuf_size);
1694 if (req->rq_reqbuf_len < newbuf_size) {
1695 newbuf_size = size_roundup_power2(newbuf_size);
1697 OBD_ALLOC_LARGE(newbuf, newbuf_size);
1701 /* Must lock this, so that otherwise unprotected change of
1702 * rq_reqmsg is not racing with parallel processing of
1703 * imp_replay_list traversing threads. See LU-3333
1704 * This is a bandaid at best, we really need to deal with this
1705 * in request enlarging code before unpacking that's already
1708 spin_lock(&req->rq_import->imp_lock);
1710 memcpy(newbuf, req->rq_reqbuf, req->rq_reqbuf_len);
1712 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1713 req->rq_reqbuf = newbuf;
1714 req->rq_reqbuf_len = newbuf_size;
1715 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, 0);
1718 spin_unlock(&req->rq_import->imp_lock);
1721 /* do enlargement, from wrapper to embedded, from end to begin */
1722 if (svc != SPTLRPC_SVC_NULL)
1723 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf,
1724 msg_last_segidx(req->rq_reqbuf),
1727 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf, 1, newmsg_size);
1728 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1730 req->rq_reqlen = newmsg_size;
1735 int gss_enlarge_reqbuf_priv(struct ptlrpc_sec *sec,
1736 struct ptlrpc_request *req,
1737 int segment, int newsize)
1739 struct lustre_msg *newclrbuf;
1740 int newmsg_size, newclrbuf_size, newcipbuf_size;
1744 * embedded msg is at seg 0 of clear buffer;
1745 * cipher text is at seg 2 of cipher buffer;
1747 LASSERT(req->rq_pool ||
1748 (req->rq_reqbuf == NULL && req->rq_reqbuf_len == 0));
1749 LASSERT(req->rq_reqbuf == NULL ||
1750 (req->rq_pool && req->rq_reqbuf->lm_bufcount == 3));
1751 LASSERT(req->rq_clrbuf);
1752 LASSERT(req->rq_clrbuf_len > req->rq_reqlen);
1753 LASSERT(lustre_msg_buf(req->rq_clrbuf, 0, 0) == req->rq_reqmsg);
1755 /* compute new embedded msg size */
1756 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1758 /* compute new clear buffer size */
1759 newclrbuf_size = get_enlarged_msgsize(req->rq_clrbuf, 0, newmsg_size);
1760 newclrbuf_size += GSS_MAX_CIPHER_BLOCK;
1762 /* compute new cipher buffer size */
1763 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1764 buflens[1] = gss_cli_payload(req->rq_cli_ctx, buflens[0], 0);
1765 buflens[2] = gss_cli_payload(req->rq_cli_ctx, newclrbuf_size, 1);
1766 newcipbuf_size = lustre_msg_size_v2(3, buflens);
1768 /* handle the case that we put both clear buf and cipher buf into
1769 * pre-allocated single buffer. */
1770 if (unlikely(req->rq_pool) &&
1771 req->rq_clrbuf >= req->rq_reqbuf &&
1772 (char *) req->rq_clrbuf <
1773 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1774 /* it couldn't be better we still fit into the
1775 * pre-allocated buffer. */
1776 if (newclrbuf_size + newcipbuf_size <= req->rq_reqbuf_len) {
1780 spin_lock(&req->rq_import->imp_lock);
1781 /* move clear text backward. */
1782 src = req->rq_clrbuf;
1783 dst = (char *) req->rq_reqbuf + newcipbuf_size;
1785 memmove(dst, src, req->rq_clrbuf_len);
1787 req->rq_clrbuf = (struct lustre_msg *) dst;
1788 req->rq_clrbuf_len = newclrbuf_size;
1789 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1792 spin_unlock(&req->rq_import->imp_lock);
1794 /* sadly we have to split out the clear buffer */
1795 LASSERT(req->rq_reqbuf_len >= newcipbuf_size);
1796 LASSERT(req->rq_clrbuf_len < newclrbuf_size);
1800 if (req->rq_clrbuf_len < newclrbuf_size) {
1801 newclrbuf_size = size_roundup_power2(newclrbuf_size);
1803 OBD_ALLOC_LARGE(newclrbuf, newclrbuf_size);
1804 if (newclrbuf == NULL)
1807 /* Must lock this, so that otherwise unprotected change of
1808 * rq_reqmsg is not racing with parallel processing of
1809 * imp_replay_list traversing threads. See LU-3333
1810 * This is a bandaid at best, we really need to deal with this
1811 * in request enlarging code before unpacking that's already
1814 spin_lock(&req->rq_import->imp_lock);
1816 memcpy(newclrbuf, req->rq_clrbuf, req->rq_clrbuf_len);
1818 if (req->rq_reqbuf == NULL ||
1819 req->rq_clrbuf < req->rq_reqbuf ||
1820 (char *) req->rq_clrbuf >=
1821 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1822 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1825 req->rq_clrbuf = newclrbuf;
1826 req->rq_clrbuf_len = newclrbuf_size;
1827 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1830 spin_unlock(&req->rq_import->imp_lock);
1833 _sptlrpc_enlarge_msg_inplace(req->rq_clrbuf, 0, newmsg_size);
1834 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1835 req->rq_reqlen = newmsg_size;
1840 int gss_enlarge_reqbuf(struct ptlrpc_sec *sec,
1841 struct ptlrpc_request *req,
1842 int segment, int newsize)
1844 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1846 LASSERT(!req->rq_ctx_init && !req->rq_ctx_fini);
1849 case SPTLRPC_SVC_NULL:
1850 case SPTLRPC_SVC_AUTH:
1851 case SPTLRPC_SVC_INTG:
1852 return gss_enlarge_reqbuf_intg(sec, req, svc, segment, newsize);
1853 case SPTLRPC_SVC_PRIV:
1854 return gss_enlarge_reqbuf_priv(sec, req, segment, newsize);
1856 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1861 int gss_sec_install_rctx(struct obd_import *imp,
1862 struct ptlrpc_sec *sec,
1863 struct ptlrpc_cli_ctx *ctx)
1865 struct gss_sec *gsec;
1866 struct gss_cli_ctx *gctx;
1869 gsec = container_of(sec, struct gss_sec, gs_base);
1870 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
1872 rc = gss_install_rvs_svc_ctx(imp, gsec, gctx);
1876 /********************************************
1878 ********************************************/
1881 int gss_svc_reqctx_is_special(struct gss_svc_reqctx *grctx)
1884 return (grctx->src_init || grctx->src_init_continue ||
1885 grctx->src_err_notify);
1889 void gss_svc_reqctx_free(struct gss_svc_reqctx *grctx)
1892 gss_svc_upcall_put_ctx(grctx->src_ctx);
1894 sptlrpc_policy_put(grctx->src_base.sc_policy);
1895 OBD_FREE_PTR(grctx);
1899 void gss_svc_reqctx_addref(struct gss_svc_reqctx *grctx)
1901 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1902 atomic_inc(&grctx->src_base.sc_refcount);
1906 void gss_svc_reqctx_decref(struct gss_svc_reqctx *grctx)
1908 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1910 if (atomic_dec_and_test(&grctx->src_base.sc_refcount))
1911 gss_svc_reqctx_free(grctx);
1915 int gss_svc_sign(struct ptlrpc_request *req,
1916 struct ptlrpc_reply_state *rs,
1917 struct gss_svc_reqctx *grctx,
1924 LASSERT(rs->rs_msg == lustre_msg_buf(rs->rs_repbuf, 1, 0));
1926 /* embedded lustre_msg might have been shrunk */
1927 if (req->rq_replen != rs->rs_repbuf->lm_buflens[1])
1928 lustre_shrink_msg(rs->rs_repbuf, 1, req->rq_replen, 1);
1930 if (req->rq_pack_bulk)
1931 flags |= LUSTRE_GSS_PACK_BULK;
1933 rc = gss_sign_msg(rs->rs_repbuf, grctx->src_ctx->gsc_mechctx,
1934 LUSTRE_SP_ANY, flags, PTLRPC_GSS_PROC_DATA,
1935 grctx->src_wirectx.gw_seq, svc, NULL);
1939 rs->rs_repdata_len = rc;
1941 if (likely(req->rq_packed_final)) {
1942 if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
1943 req->rq_reply_off = gss_at_reply_off_integ;
1945 req->rq_reply_off = 0;
1947 if (svc == SPTLRPC_SVC_NULL)
1948 rs->rs_repbuf->lm_cksum = crc32_le(!(__u32) 0,
1949 lustre_msg_buf(rs->rs_repbuf, 1, 0),
1950 lustre_msg_buflen(rs->rs_repbuf, 1));
1951 req->rq_reply_off = 0;
1957 int gss_pack_err_notify(struct ptlrpc_request *req, __u32 major, __u32 minor)
1959 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
1960 struct ptlrpc_reply_state *rs;
1961 struct gss_err_header *ghdr;
1962 int replen = sizeof(struct ptlrpc_body);
1966 //if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_SVCGSS_ERR_NOTIFY, OBD_FAIL_ONCE))
1969 grctx->src_err_notify = 1;
1970 grctx->src_reserve_len = 0;
1972 rc = lustre_pack_reply_v2(req, 1, &replen, NULL, 0);
1974 CERROR("could not pack reply, err %d\n", rc);
1979 rs = req->rq_reply_state;
1980 LASSERT(rs->rs_repbuf->lm_buflens[1] >= sizeof(*ghdr));
1981 ghdr = lustre_msg_buf(rs->rs_repbuf, 0, 0);
1982 ghdr->gh_version = PTLRPC_GSS_VERSION;
1984 ghdr->gh_proc = PTLRPC_GSS_PROC_ERR;
1985 ghdr->gh_major = major;
1986 ghdr->gh_minor = minor;
1987 ghdr->gh_handle.len = 0; /* fake context handle */
1989 rs->rs_repdata_len = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
1990 rs->rs_repbuf->lm_buflens);
1992 CDEBUG(D_SEC, "prepare gss error notify(0x%x/0x%x) to %s\n",
1993 major, minor, libcfs_nid2str(req->rq_peer.nid));
1998 int gss_svc_handle_init(struct ptlrpc_request *req,
1999 struct gss_wire_ctx *gw)
2001 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2002 struct lustre_msg *reqbuf = req->rq_reqbuf;
2003 struct obd_uuid *uuid;
2004 struct obd_device *target;
2005 rawobj_t uuid_obj, rvs_hdl, in_token;
2007 __u32 *secdata, seclen;
2011 CDEBUG(D_SEC, "processing gss init(%d) request from %s\n", gw->gw_proc,
2012 libcfs_nid2str(req->rq_peer.nid));
2014 req->rq_ctx_init = 1;
2016 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2017 CERROR("unexpected bulk flag\n");
2018 RETURN(SECSVC_DROP);
2021 if (gw->gw_proc == PTLRPC_GSS_PROC_INIT && gw->gw_handle.len != 0) {
2022 CERROR("proc %u: invalid handle length %u\n",
2023 gw->gw_proc, gw->gw_handle.len);
2024 RETURN(SECSVC_DROP);
2027 if (reqbuf->lm_bufcount < 3 || reqbuf->lm_bufcount > 4){
2028 CERROR("Invalid bufcount %d\n", reqbuf->lm_bufcount);
2029 RETURN(SECSVC_DROP);
2032 swabbed = ptlrpc_req_need_swab(req);
2034 /* ctx initiate payload is in last segment */
2035 secdata = lustre_msg_buf(reqbuf, reqbuf->lm_bufcount - 1, 0);
2036 seclen = reqbuf->lm_buflens[reqbuf->lm_bufcount - 1];
2038 if (seclen < 4 + 4) {
2039 CERROR("sec size %d too small\n", seclen);
2040 RETURN(SECSVC_DROP);
2043 /* lustre svc type */
2044 lustre_svc = le32_to_cpu(*secdata++);
2047 /* extract target uuid, note this code is somewhat fragile
2048 * because touched internal structure of obd_uuid */
2049 if (rawobj_extract(&uuid_obj, &secdata, &seclen)) {
2050 CERROR("failed to extract target uuid\n");
2051 RETURN(SECSVC_DROP);
2053 uuid_obj.data[uuid_obj.len - 1] = '\0';
2055 uuid = (struct obd_uuid *) uuid_obj.data;
2056 target = class_uuid2obd(uuid);
2057 if (!target || target->obd_stopping || !target->obd_set_up) {
2058 CERROR("target '%s' is not available for context init (%s)\n",
2059 uuid->uuid, target == NULL ? "no target" :
2060 (target->obd_stopping ? "stopping" : "not set up"));
2061 RETURN(SECSVC_DROP);
2064 /* extract reverse handle */
2065 if (rawobj_extract(&rvs_hdl, &secdata, &seclen)) {
2066 CERROR("failed extract reverse handle\n");
2067 RETURN(SECSVC_DROP);
2071 if (rawobj_extract(&in_token, &secdata, &seclen)) {
2072 CERROR("can't extract token\n");
2073 RETURN(SECSVC_DROP);
2076 rc = gss_svc_upcall_handle_init(req, grctx, gw, target, lustre_svc,
2077 &rvs_hdl, &in_token);
2078 if (rc != SECSVC_OK)
2081 if (grctx->src_ctx->gsc_usr_mds || grctx->src_ctx->gsc_usr_oss ||
2082 grctx->src_ctx->gsc_usr_root)
2083 CWARN("create svc ctx %p: user from %s authenticated as %s\n",
2084 grctx->src_ctx, libcfs_nid2str(req->rq_peer.nid),
2085 grctx->src_ctx->gsc_usr_mds ? "mds" :
2086 (grctx->src_ctx->gsc_usr_oss ? "oss" : "root"));
2088 CWARN("create svc ctx %p: accept user %u from %s\n",
2089 grctx->src_ctx, grctx->src_ctx->gsc_uid,
2090 libcfs_nid2str(req->rq_peer.nid));
2092 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2093 if (reqbuf->lm_bufcount < 4) {
2094 CERROR("missing user descriptor\n");
2095 RETURN(SECSVC_DROP);
2097 if (sptlrpc_unpack_user_desc(reqbuf, 2, swabbed)) {
2098 CERROR("Mal-formed user descriptor\n");
2099 RETURN(SECSVC_DROP);
2102 req->rq_pack_udesc = 1;
2103 req->rq_user_desc = lustre_msg_buf(reqbuf, 2, 0);
2106 req->rq_reqmsg = lustre_msg_buf(reqbuf, 1, 0);
2107 req->rq_reqlen = lustre_msg_buflen(reqbuf, 1);
2113 * last segment must be the gss signature.
2116 int gss_svc_verify_request(struct ptlrpc_request *req,
2117 struct gss_svc_reqctx *grctx,
2118 struct gss_wire_ctx *gw,
2121 struct gss_svc_ctx *gctx = grctx->src_ctx;
2122 struct lustre_msg *msg = req->rq_reqbuf;
2127 *major = GSS_S_COMPLETE;
2129 if (msg->lm_bufcount < 2) {
2130 CERROR("Too few segments (%u) in request\n", msg->lm_bufcount);
2134 if (gw->gw_svc == SPTLRPC_SVC_NULL)
2137 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2138 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2139 *major = GSS_S_DUPLICATE_TOKEN;
2143 *major = gss_verify_msg(msg, gctx->gsc_mechctx, gw->gw_svc);
2144 if (*major != GSS_S_COMPLETE) {
2145 CERROR("failed to verify request: %x\n", *major);
2149 if (gctx->gsc_reverse == 0 &&
2150 gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2151 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2152 *major = GSS_S_DUPLICATE_TOKEN;
2157 swabbed = ptlrpc_req_need_swab(req);
2159 /* user descriptor */
2160 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2161 if (msg->lm_bufcount < (offset + 1)) {
2162 CERROR("no user desc included\n");
2166 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2167 CERROR("Mal-formed user descriptor\n");
2171 req->rq_pack_udesc = 1;
2172 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2176 /* check bulk_sec_desc data */
2177 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2178 if (msg->lm_bufcount < (offset + 1)) {
2179 CERROR("missing bulk sec descriptor\n");
2183 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2186 req->rq_pack_bulk = 1;
2187 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2188 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2191 req->rq_reqmsg = lustre_msg_buf(msg, 1, 0);
2192 req->rq_reqlen = msg->lm_buflens[1];
2197 int gss_svc_unseal_request(struct ptlrpc_request *req,
2198 struct gss_svc_reqctx *grctx,
2199 struct gss_wire_ctx *gw,
2202 struct gss_svc_ctx *gctx = grctx->src_ctx;
2203 struct lustre_msg *msg = req->rq_reqbuf;
2204 int swabbed, msglen, offset = 1;
2207 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2208 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2209 *major = GSS_S_DUPLICATE_TOKEN;
2213 *major = gss_unseal_msg(gctx->gsc_mechctx, msg,
2214 &msglen, req->rq_reqdata_len);
2215 if (*major != GSS_S_COMPLETE) {
2216 CERROR("failed to unwrap request: %x\n", *major);
2220 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2221 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2222 *major = GSS_S_DUPLICATE_TOKEN;
2226 swabbed = __lustre_unpack_msg(msg, msglen);
2228 CERROR("Failed to unpack after decryption\n");
2231 req->rq_reqdata_len = msglen;
2233 if (msg->lm_bufcount < 1) {
2234 CERROR("Invalid buffer: is empty\n");
2238 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2239 if (msg->lm_bufcount < offset + 1) {
2240 CERROR("no user descriptor included\n");
2244 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2245 CERROR("Mal-formed user descriptor\n");
2249 req->rq_pack_udesc = 1;
2250 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2254 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2255 if (msg->lm_bufcount < offset + 1) {
2256 CERROR("no bulk checksum included\n");
2260 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2263 req->rq_pack_bulk = 1;
2264 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2265 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2268 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 0, 0);
2269 req->rq_reqlen = req->rq_reqbuf->lm_buflens[0];
2274 int gss_svc_handle_data(struct ptlrpc_request *req,
2275 struct gss_wire_ctx *gw)
2277 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2282 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2283 if (!grctx->src_ctx) {
2284 major = GSS_S_NO_CONTEXT;
2288 switch (gw->gw_svc) {
2289 case SPTLRPC_SVC_NULL:
2290 case SPTLRPC_SVC_AUTH:
2291 case SPTLRPC_SVC_INTG:
2292 rc = gss_svc_verify_request(req, grctx, gw, &major);
2294 case SPTLRPC_SVC_PRIV:
2295 rc = gss_svc_unseal_request(req, grctx, gw, &major);
2298 CERROR("unsupported gss service %d\n", gw->gw_svc);
2305 CERROR("svc %u failed: major 0x%08x: req xid "LPU64" ctx %p idx "
2306 LPX64"(%u->%s)\n", gw->gw_svc, major, req->rq_xid,
2307 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2308 grctx->src_ctx->gsc_uid, libcfs_nid2str(req->rq_peer.nid));
2310 /* we only notify client in case of NO_CONTEXT/BAD_SIG, which
2311 * might happen after server reboot, to allow recovery. */
2312 if ((major == GSS_S_NO_CONTEXT || major == GSS_S_BAD_SIG) &&
2313 gss_pack_err_notify(req, major, 0) == 0)
2314 RETURN(SECSVC_COMPLETE);
2316 RETURN(SECSVC_DROP);
2320 int gss_svc_handle_destroy(struct ptlrpc_request *req,
2321 struct gss_wire_ctx *gw)
2323 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2327 req->rq_ctx_fini = 1;
2328 req->rq_no_reply = 1;
2330 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2331 if (!grctx->src_ctx) {
2332 CDEBUG(D_SEC, "invalid gss context handle for destroy.\n");
2333 RETURN(SECSVC_DROP);
2336 if (gw->gw_svc != SPTLRPC_SVC_INTG) {
2337 CERROR("svc %u is not supported in destroy.\n", gw->gw_svc);
2338 RETURN(SECSVC_DROP);
2341 if (gss_svc_verify_request(req, grctx, gw, &major))
2342 RETURN(SECSVC_DROP);
2344 CWARN("destroy svc ctx %p idx "LPX64" (%u->%s)\n",
2345 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2346 grctx->src_ctx->gsc_uid, libcfs_nid2str(req->rq_peer.nid));
2348 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2350 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2351 if (req->rq_reqbuf->lm_bufcount < 4) {
2352 CERROR("missing user descriptor, ignore it\n");
2355 if (sptlrpc_unpack_user_desc(req->rq_reqbuf, 2,
2356 ptlrpc_req_need_swab(req))) {
2357 CERROR("Mal-formed user descriptor, ignore it\n");
2361 req->rq_pack_udesc = 1;
2362 req->rq_user_desc = lustre_msg_buf(req->rq_reqbuf, 2, 0);
2368 int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
2370 struct gss_header *ghdr;
2371 struct gss_svc_reqctx *grctx;
2372 struct gss_wire_ctx *gw;
2376 LASSERT(req->rq_reqbuf);
2377 LASSERT(req->rq_svc_ctx == NULL);
2379 if (req->rq_reqbuf->lm_bufcount < 2) {
2380 CERROR("buf count only %d\n", req->rq_reqbuf->lm_bufcount);
2381 RETURN(SECSVC_DROP);
2384 swabbed = ptlrpc_req_need_swab(req);
2386 ghdr = gss_swab_header(req->rq_reqbuf, 0, swabbed);
2388 CERROR("can't decode gss header\n");
2389 RETURN(SECSVC_DROP);
2393 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
2394 CERROR("gss version %u, expect %u\n", ghdr->gh_version,
2395 PTLRPC_GSS_VERSION);
2396 RETURN(SECSVC_DROP);
2399 req->rq_sp_from = ghdr->gh_sp;
2401 /* alloc grctx data */
2402 OBD_ALLOC_PTR(grctx);
2404 RETURN(SECSVC_DROP);
2406 grctx->src_base.sc_policy = sptlrpc_policy_get(policy);
2407 atomic_set(&grctx->src_base.sc_refcount, 1);
2408 req->rq_svc_ctx = &grctx->src_base;
2409 gw = &grctx->src_wirectx;
2411 /* save wire context */
2412 gw->gw_flags = ghdr->gh_flags;
2413 gw->gw_proc = ghdr->gh_proc;
2414 gw->gw_seq = ghdr->gh_seq;
2415 gw->gw_svc = ghdr->gh_svc;
2416 rawobj_from_netobj(&gw->gw_handle, &ghdr->gh_handle);
2418 /* keep original wire header which subject to checksum verification */
2420 gss_header_swabber(ghdr);
2422 switch(ghdr->gh_proc) {
2423 case PTLRPC_GSS_PROC_INIT:
2424 case PTLRPC_GSS_PROC_CONTINUE_INIT:
2425 rc = gss_svc_handle_init(req, gw);
2427 case PTLRPC_GSS_PROC_DATA:
2428 rc = gss_svc_handle_data(req, gw);
2430 case PTLRPC_GSS_PROC_DESTROY:
2431 rc = gss_svc_handle_destroy(req, gw);
2434 CERROR("unknown proc %u\n", gw->gw_proc);
2441 LASSERT (grctx->src_ctx);
2443 req->rq_auth_gss = 1;
2444 req->rq_auth_usr_mdt = grctx->src_ctx->gsc_usr_mds;
2445 req->rq_auth_usr_ost = grctx->src_ctx->gsc_usr_oss;
2446 req->rq_auth_usr_root = grctx->src_ctx->gsc_usr_root;
2447 req->rq_auth_uid = grctx->src_ctx->gsc_uid;
2448 req->rq_auth_mapped_uid = grctx->src_ctx->gsc_mapped_uid;
2450 case SECSVC_COMPLETE:
2453 gss_svc_reqctx_free(grctx);
2454 req->rq_svc_ctx = NULL;
2461 void gss_svc_invalidate_ctx(struct ptlrpc_svc_ctx *svc_ctx)
2463 struct gss_svc_reqctx *grctx;
2466 if (svc_ctx == NULL) {
2471 grctx = gss_svc_ctx2reqctx(svc_ctx);
2473 CWARN("gss svc invalidate ctx %p(%u)\n",
2474 grctx->src_ctx, grctx->src_ctx->gsc_uid);
2475 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2481 int gss_svc_payload(struct gss_svc_reqctx *grctx, int early,
2482 int msgsize, int privacy)
2484 /* we should treat early reply normally, but which is actually sharing
2485 * the same ctx with original request, so in this case we should
2486 * ignore the special ctx's special flags */
2487 if (early == 0 && gss_svc_reqctx_is_special(grctx))
2488 return grctx->src_reserve_len;
2490 return gss_mech_payload(NULL, msgsize, privacy);
2493 static int gss_svc_bulk_payload(struct gss_svc_ctx *gctx,
2494 struct sptlrpc_flavor *flvr,
2497 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
2500 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
2501 case SPTLRPC_BULK_SVC_NULL:
2503 case SPTLRPC_BULK_SVC_INTG:
2504 payload += gss_mech_payload(NULL, 0, 0);
2506 case SPTLRPC_BULK_SVC_PRIV:
2507 payload += gss_mech_payload(NULL, 0, 1);
2509 case SPTLRPC_BULK_SVC_AUTH:
2518 int gss_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
2520 struct gss_svc_reqctx *grctx;
2521 struct ptlrpc_reply_state *rs;
2522 int early, privacy, svc, bsd_off = 0;
2523 __u32 ibuflens[2], buflens[4];
2524 int ibufcnt = 0, bufcnt;
2525 int txtsize, wmsg_size, rs_size;
2528 LASSERT(msglen % 8 == 0);
2530 if (req->rq_pack_bulk && !req->rq_bulk_read && !req->rq_bulk_write) {
2531 CERROR("client request bulk sec on non-bulk rpc\n");
2535 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
2536 early = (req->rq_packed_final == 0);
2538 grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2539 if (!early && gss_svc_reqctx_is_special(grctx))
2542 privacy = (svc == SPTLRPC_SVC_PRIV);
2545 /* inner clear buffers */
2547 ibuflens[0] = msglen;
2549 if (req->rq_pack_bulk) {
2550 LASSERT(grctx->src_reqbsd);
2553 ibuflens[ibufcnt++] = gss_svc_bulk_payload(
2559 txtsize = lustre_msg_size_v2(ibufcnt, ibuflens);
2560 txtsize += GSS_MAX_CIPHER_BLOCK;
2562 /* wrapper buffer */
2564 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2565 buflens[1] = gss_svc_payload(grctx, early, txtsize, 1);
2568 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2569 buflens[1] = msglen;
2571 txtsize = buflens[0];
2572 if (svc == SPTLRPC_SVC_INTG)
2573 txtsize += buflens[1];
2575 if (req->rq_pack_bulk) {
2576 LASSERT(grctx->src_reqbsd);
2579 buflens[bufcnt] = gss_svc_bulk_payload(
2583 if (svc == SPTLRPC_SVC_INTG)
2584 txtsize += buflens[bufcnt];
2588 if ((!early && gss_svc_reqctx_is_special(grctx)) ||
2589 svc != SPTLRPC_SVC_NULL)
2590 buflens[bufcnt++] = gss_svc_payload(grctx, early,
2594 wmsg_size = lustre_msg_size_v2(bufcnt, buflens);
2596 rs_size = sizeof(*rs) + wmsg_size;
2597 rs = req->rq_reply_state;
2601 LASSERT(rs->rs_size >= rs_size);
2603 OBD_ALLOC_LARGE(rs, rs_size);
2607 rs->rs_size = rs_size;
2610 rs->rs_repbuf = (struct lustre_msg *) (rs + 1);
2611 rs->rs_repbuf_len = wmsg_size;
2613 /* initialize the buffer */
2615 lustre_init_msg_v2(rs->rs_repbuf, ibufcnt, ibuflens, NULL);
2616 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 0, msglen);
2618 lustre_init_msg_v2(rs->rs_repbuf, bufcnt, buflens, NULL);
2619 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2621 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 1, 0);
2625 grctx->src_repbsd = lustre_msg_buf(rs->rs_repbuf, bsd_off, 0);
2626 grctx->src_repbsd_size = lustre_msg_buflen(rs->rs_repbuf,
2630 gss_svc_reqctx_addref(grctx);
2631 rs->rs_svc_ctx = req->rq_svc_ctx;
2633 LASSERT(rs->rs_msg);
2634 req->rq_reply_state = rs;
2638 static int gss_svc_seal(struct ptlrpc_request *req,
2639 struct ptlrpc_reply_state *rs,
2640 struct gss_svc_reqctx *grctx)
2642 struct gss_svc_ctx *gctx = grctx->src_ctx;
2643 rawobj_t hdrobj, msgobj, token;
2644 struct gss_header *ghdr;
2647 __u32 buflens[2], major;
2651 /* get clear data length. note embedded lustre_msg might
2652 * have been shrunk */
2653 if (req->rq_replen != lustre_msg_buflen(rs->rs_repbuf, 0))
2654 msglen = lustre_shrink_msg(rs->rs_repbuf, 0, req->rq_replen, 1);
2656 msglen = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
2657 rs->rs_repbuf->lm_buflens);
2659 /* temporarily use tail of buffer to hold gss header data */
2660 LASSERT(msglen + PTLRPC_GSS_HEADER_SIZE <= rs->rs_repbuf_len);
2661 ghdr = (struct gss_header *) ((char *) rs->rs_repbuf +
2662 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE);
2663 ghdr->gh_version = PTLRPC_GSS_VERSION;
2664 ghdr->gh_sp = LUSTRE_SP_ANY;
2666 ghdr->gh_proc = PTLRPC_GSS_PROC_DATA;
2667 ghdr->gh_seq = grctx->src_wirectx.gw_seq;
2668 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
2669 ghdr->gh_handle.len = 0;
2670 if (req->rq_pack_bulk)
2671 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
2673 /* allocate temporary cipher buffer */
2674 token_buflen = gss_mech_payload(gctx->gsc_mechctx, msglen, 1);
2675 OBD_ALLOC_LARGE(token_buf, token_buflen);
2676 if (token_buf == NULL)
2679 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
2680 hdrobj.data = (__u8 *) ghdr;
2681 msgobj.len = msglen;
2682 msgobj.data = (__u8 *) rs->rs_repbuf;
2683 token.len = token_buflen;
2684 token.data = token_buf;
2686 major = lgss_wrap(gctx->gsc_mechctx, &hdrobj, &msgobj,
2687 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE, &token);
2688 if (major != GSS_S_COMPLETE) {
2689 CERROR("wrap message error: %08x\n", major);
2690 GOTO(out_free, rc = -EPERM);
2692 LASSERT(token.len <= token_buflen);
2694 /* we are about to override data at rs->rs_repbuf, nullify pointers
2695 * to which to catch further illegal usage. */
2696 if (req->rq_pack_bulk) {
2697 grctx->src_repbsd = NULL;
2698 grctx->src_repbsd_size = 0;
2701 /* now fill the actual wire data
2705 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2706 buflens[1] = token.len;
2708 rs->rs_repdata_len = lustre_msg_size_v2(2, buflens);
2709 LASSERT(rs->rs_repdata_len <= rs->rs_repbuf_len);
2711 lustre_init_msg_v2(rs->rs_repbuf, 2, buflens, NULL);
2712 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2714 memcpy(lustre_msg_buf(rs->rs_repbuf, 0, 0), ghdr,
2715 PTLRPC_GSS_HEADER_SIZE);
2716 memcpy(lustre_msg_buf(rs->rs_repbuf, 1, 0), token.data, token.len);
2719 if (req->rq_packed_final &&
2720 (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))
2721 req->rq_reply_off = gss_at_reply_off_priv;
2723 req->rq_reply_off = 0;
2725 /* to catch upper layer's further access */
2727 req->rq_repmsg = NULL;
2732 OBD_FREE_LARGE(token_buf, token_buflen);
2736 int gss_svc_authorize(struct ptlrpc_request *req)
2738 struct ptlrpc_reply_state *rs = req->rq_reply_state;
2739 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2740 struct gss_wire_ctx *gw = &grctx->src_wirectx;
2744 early = (req->rq_packed_final == 0);
2746 if (!early && gss_svc_reqctx_is_special(grctx)) {
2747 LASSERT(rs->rs_repdata_len != 0);
2749 req->rq_reply_off = gss_at_reply_off_integ;
2753 /* early reply could happen in many cases */
2755 gw->gw_proc != PTLRPC_GSS_PROC_DATA &&
2756 gw->gw_proc != PTLRPC_GSS_PROC_DESTROY) {
2757 CERROR("proc %d not support\n", gw->gw_proc);
2761 LASSERT(grctx->src_ctx);
2763 switch (gw->gw_svc) {
2764 case SPTLRPC_SVC_NULL:
2765 case SPTLRPC_SVC_AUTH:
2766 case SPTLRPC_SVC_INTG:
2767 rc = gss_svc_sign(req, rs, grctx, gw->gw_svc);
2769 case SPTLRPC_SVC_PRIV:
2770 rc = gss_svc_seal(req, rs, grctx);
2773 CERROR("Unknown service %d\n", gw->gw_svc);
2774 GOTO(out, rc = -EINVAL);
2782 void gss_svc_free_rs(struct ptlrpc_reply_state *rs)
2784 struct gss_svc_reqctx *grctx;
2786 LASSERT(rs->rs_svc_ctx);
2787 grctx = container_of(rs->rs_svc_ctx, struct gss_svc_reqctx, src_base);
2789 gss_svc_reqctx_decref(grctx);
2790 rs->rs_svc_ctx = NULL;
2792 if (!rs->rs_prealloc)
2793 OBD_FREE_LARGE(rs, rs->rs_size);
2796 void gss_svc_free_ctx(struct ptlrpc_svc_ctx *ctx)
2798 LASSERT(atomic_read(&ctx->sc_refcount) == 0);
2799 gss_svc_reqctx_free(gss_svc_ctx2reqctx(ctx));
2802 int gss_copy_rvc_cli_ctx(struct ptlrpc_cli_ctx *cli_ctx,
2803 struct ptlrpc_svc_ctx *svc_ctx)
2805 struct gss_cli_ctx *cli_gctx = ctx2gctx(cli_ctx);
2806 struct gss_svc_ctx *svc_gctx = gss_svc_ctx2gssctx(svc_ctx);
2807 struct gss_ctx *mechctx = NULL;
2810 LASSERT(svc_gctx && svc_gctx->gsc_mechctx);
2812 cli_gctx->gc_proc = PTLRPC_GSS_PROC_DATA;
2813 cli_gctx->gc_win = GSS_SEQ_WIN;
2815 /* The problem is the reverse ctx might get lost in some recovery
2816 * situations, and the same svc_ctx will be used to re-create it.
2817 * if there's callback be sentout before that, new reverse ctx start
2818 * with sequence 0 will lead to future callback rpc be treated as
2821 * each reverse root ctx will record its latest sequence number on its
2822 * buddy svcctx before be destroyed, so here we continue use it.
2824 atomic_set(&cli_gctx->gc_seq, svc_gctx->gsc_rvs_seq);
2826 if (gss_svc_upcall_dup_handle(&cli_gctx->gc_svc_handle, svc_gctx)) {
2827 CERROR("failed to dup svc handle\n");
2831 if (lgss_copy_reverse_context(svc_gctx->gsc_mechctx, &mechctx) !=
2833 CERROR("failed to copy mech context\n");
2834 goto err_svc_handle;
2837 if (rawobj_dup(&cli_gctx->gc_handle, &svc_gctx->gsc_rvs_hdl)) {
2838 CERROR("failed to dup reverse handle\n");
2842 cli_gctx->gc_mechctx = mechctx;
2843 gss_cli_ctx_uptodate(cli_gctx);
2848 lgss_delete_sec_context(&mechctx);
2850 rawobj_free(&cli_gctx->gc_svc_handle);
2855 static void gss_init_at_reply_offset(void)
2860 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2861 buflens[1] = lustre_msg_early_size();
2862 buflens[2] = gss_cli_payload(NULL, buflens[1], 0);
2863 gss_at_reply_off_integ = lustre_msg_size_v2(3, buflens);
2865 buflens[0] = lustre_msg_early_size();
2866 clearsize = lustre_msg_size_v2(1, buflens);
2867 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2868 buflens[1] = gss_cli_payload(NULL, clearsize, 0);
2869 buflens[2] = gss_cli_payload(NULL, clearsize, 1);
2870 gss_at_reply_off_priv = lustre_msg_size_v2(3, buflens);
2873 static int __init sptlrpc_gss_init(void)
2877 rc = gss_init_lproc();
2881 rc = gss_init_cli_upcall();
2885 rc = gss_init_svc_upcall();
2887 goto out_cli_upcall;
2889 rc = init_null_module();
2891 goto out_svc_upcall;
2893 rc = init_kerberos_module();
2897 rc = init_sk_module();
2901 /* register policy after all other stuff be initialized, because it
2902 * might be in used immediately after the registration. */
2904 rc = gss_init_keyring();
2908 rc = gss_init_pipefs();
2912 gss_init_at_reply_offset();
2919 cleanup_sk_module();
2921 cleanup_kerberos_module();
2923 cleanup_null_module();
2925 gss_exit_svc_upcall();
2927 gss_exit_cli_upcall();
2933 static void __exit sptlrpc_gss_exit(void)
2937 cleanup_kerberos_module();
2938 gss_exit_svc_upcall();
2939 gss_exit_cli_upcall();
2943 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2944 MODULE_DESCRIPTION("Lustre GSS security policy");
2945 MODULE_VERSION(LUSTRE_VERSION_STRING);
2946 MODULE_LICENSE("GPL");
2948 module_init(sptlrpc_gss_init);
2949 module_exit(sptlrpc_gss_exit);