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),
393 ctx->cc_expire, ctx->cc_expire - cfs_time_current_sec());
395 CWARN("client refreshed ctx %p idx "LPX64" (%u->%s), "
396 "expiry %lu(%+lds)\n", ctx,
397 gss_handle_to_u64(&gctx->gc_handle),
398 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
399 ctx->cc_expire, ctx->cc_expire - cfs_time_current_sec());
401 /* install reverse svc ctx for root context */
402 if (ctx->cc_vcred.vc_uid == 0)
403 gss_sec_install_rctx(ctx->cc_sec->ps_import,
407 sptlrpc_cli_ctx_wakeup(ctx);
410 static void gss_cli_ctx_finalize(struct gss_cli_ctx *gctx)
412 LASSERT(gctx->gc_base.cc_sec);
414 if (gctx->gc_mechctx) {
415 lgss_delete_sec_context(&gctx->gc_mechctx);
416 gctx->gc_mechctx = NULL;
419 if (!rawobj_empty(&gctx->gc_svc_handle)) {
420 /* forward ctx: mark buddy reverse svcctx soon-expire. */
421 if (!sec_is_reverse(gctx->gc_base.cc_sec) &&
422 !rawobj_empty(&gctx->gc_svc_handle))
423 gss_svc_upcall_expire_rvs_ctx(&gctx->gc_svc_handle);
425 rawobj_free(&gctx->gc_svc_handle);
428 rawobj_free(&gctx->gc_handle);
432 * Based on sequence number algorithm as specified in RFC 2203.
434 * Modified for our own problem: arriving request has valid sequence number,
435 * but unwrapping request might cost a long time, after that its sequence
436 * are not valid anymore (fall behind the window). It rarely happen, mostly
437 * under extreme load.
439 * Note we should not check sequence before verifying the integrity of incoming
440 * request, because just one attacking request with high sequence number might
441 * cause all following requests be dropped.
443 * So here we use a multi-phase approach: prepare 2 sequence windows,
444 * "main window" for normal sequence and "back window" for fall behind sequence.
445 * and 3-phase checking mechanism:
446 * 0 - before integrity verification, perform an initial sequence checking in
447 * main window, which only tries and doesn't actually set any bits. if the
448 * sequence is high above the window or fits in the window and the bit
449 * is 0, then accept and proceed to integrity verification. otherwise
450 * reject this sequence.
451 * 1 - after integrity verification, check in main window again. if this
452 * sequence is high above the window or fits in the window and the bit
453 * is 0, then set the bit and accept; if it fits in the window but bit
454 * already set, then reject; if it falls behind the window, then proceed
456 * 2 - check in back window. if it is high above the window or fits in the
457 * window and the bit is 0, then set the bit and accept. otherwise reject.
459 * \return 1: looks like a replay
461 * \return -1: is a replay
463 * Note phase 0 is necessary, because otherwise replay attacking request of
464 * sequence which between the 2 windows can't be detected.
466 * This mechanism can't totally solve the problem, but could help reduce the
467 * number of valid requests be dropped.
470 int gss_do_check_seq(unsigned long *window, __u32 win_size, __u32 *max_seq,
471 __u32 seq_num, int phase)
473 LASSERT(phase >= 0 && phase <= 2);
475 if (seq_num > *max_seq) {
477 * 1. high above the window
482 if (seq_num >= *max_seq + win_size) {
483 memset(window, 0, win_size / 8);
486 while(*max_seq < seq_num) {
488 __clear_bit((*max_seq) % win_size, window);
491 __set_bit(seq_num % win_size, window);
492 } else if (seq_num + win_size <= *max_seq) {
494 * 2. low behind the window
496 if (phase == 0 || phase == 2)
499 CWARN("seq %u is %u behind (size %d), check backup window\n",
500 seq_num, *max_seq - win_size - seq_num, win_size);
504 * 3. fit into the window
508 if (test_bit(seq_num % win_size, window))
513 if (__test_and_set_bit(seq_num % win_size, window))
522 CERROR("seq %u (%s %s window) is a replay: max %u, winsize %d\n",
524 seq_num + win_size > *max_seq ? "in" : "behind",
525 phase == 2 ? "backup " : "main",
531 * Based on sequence number algorithm as specified in RFC 2203.
533 * if @set == 0: initial check, don't set any bit in window
534 * if @sec == 1: final check, set bit in window
536 int gss_check_seq_num(struct gss_svc_seq_data *ssd, __u32 seq_num, int set)
540 spin_lock(&ssd->ssd_lock);
546 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
547 &ssd->ssd_max_main, seq_num, 0);
549 gss_stat_oos_record_svc(0, 1);
552 * phase 1 checking main window
554 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
555 &ssd->ssd_max_main, seq_num, 1);
558 gss_stat_oos_record_svc(1, 1);
564 * phase 2 checking back window
566 rc = gss_do_check_seq(ssd->ssd_win_back, GSS_SEQ_WIN_BACK,
567 &ssd->ssd_max_back, seq_num, 2);
569 gss_stat_oos_record_svc(2, 1);
571 gss_stat_oos_record_svc(2, 0);
574 spin_unlock(&ssd->ssd_lock);
578 /***************************************
580 ***************************************/
582 static inline int gss_cli_payload(struct ptlrpc_cli_ctx *ctx,
583 int msgsize, int privacy)
585 return gss_mech_payload(NULL, msgsize, privacy);
588 static int gss_cli_bulk_payload(struct ptlrpc_cli_ctx *ctx,
589 struct sptlrpc_flavor *flvr,
592 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
594 LASSERT(SPTLRPC_FLVR_BULK_TYPE(flvr->sf_rpc) == SPTLRPC_BULK_DEFAULT);
596 if ((!reply && !read) || (reply && read)) {
597 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
598 case SPTLRPC_BULK_SVC_NULL:
600 case SPTLRPC_BULK_SVC_INTG:
601 payload += gss_cli_payload(ctx, 0, 0);
603 case SPTLRPC_BULK_SVC_PRIV:
604 payload += gss_cli_payload(ctx, 0, 1);
606 case SPTLRPC_BULK_SVC_AUTH:
615 int gss_cli_ctx_match(struct ptlrpc_cli_ctx *ctx, struct vfs_cred *vcred)
617 return (ctx->cc_vcred.vc_uid == vcred->vc_uid);
620 void gss_cli_ctx_flags2str(unsigned long flags, char *buf, int bufsize)
624 if (flags & PTLRPC_CTX_NEW)
625 strlcat(buf, "new,", bufsize);
626 if (flags & PTLRPC_CTX_UPTODATE)
627 strlcat(buf, "uptodate,", bufsize);
628 if (flags & PTLRPC_CTX_DEAD)
629 strlcat(buf, "dead,", bufsize);
630 if (flags & PTLRPC_CTX_ERROR)
631 strlcat(buf, "error,", bufsize);
632 if (flags & PTLRPC_CTX_CACHED)
633 strlcat(buf, "cached,", bufsize);
634 if (flags & PTLRPC_CTX_ETERNAL)
635 strlcat(buf, "eternal,", bufsize);
637 strlcat(buf, "-,", bufsize);
640 int gss_cli_ctx_sign(struct ptlrpc_cli_ctx *ctx,
641 struct ptlrpc_request *req)
643 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
644 __u32 flags = 0, seq, svc;
648 LASSERT(req->rq_reqbuf);
649 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
650 LASSERT(req->rq_cli_ctx == ctx);
652 /* nothing to do for context negotiation RPCs */
653 if (req->rq_ctx_init)
656 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
657 if (req->rq_pack_bulk)
658 flags |= LUSTRE_GSS_PACK_BULK;
659 if (req->rq_pack_udesc)
660 flags |= LUSTRE_GSS_PACK_USER;
663 seq = atomic_inc_return(&gctx->gc_seq);
665 rc = gss_sign_msg(req->rq_reqbuf, gctx->gc_mechctx,
666 ctx->cc_sec->ps_part,
667 flags, gctx->gc_proc, seq, svc,
672 /* gss_sign_msg() msg might take long time to finish, in which period
673 * more rpcs could be wrapped up and sent out. if we found too many
674 * of them we should repack this rpc, because sent it too late might
675 * lead to the sequence number fall behind the window on server and
676 * be dropped. also applies to gss_cli_ctx_seal().
678 * Note: null mode doesn't check sequence number. */
679 if (svc != SPTLRPC_SVC_NULL &&
680 atomic_read(&gctx->gc_seq) - seq > GSS_SEQ_REPACK_THRESHOLD) {
681 int behind = atomic_read(&gctx->gc_seq) - seq;
683 gss_stat_oos_record_cli(behind);
684 CWARN("req %p: %u behind, retry signing\n", req, behind);
688 req->rq_reqdata_len = rc;
693 int gss_cli_ctx_handle_err_notify(struct ptlrpc_cli_ctx *ctx,
694 struct ptlrpc_request *req,
695 struct gss_header *ghdr)
697 struct gss_err_header *errhdr;
700 LASSERT(ghdr->gh_proc == PTLRPC_GSS_PROC_ERR);
702 errhdr = (struct gss_err_header *) ghdr;
704 CWARN("req x"LPU64"/t"LPU64", ctx %p idx "LPX64"(%u->%s): "
705 "%sserver respond (%08x/%08x)\n",
706 req->rq_xid, req->rq_transno, ctx,
707 gss_handle_to_u64(&ctx2gctx(ctx)->gc_handle),
708 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
709 sec_is_reverse(ctx->cc_sec) ? "reverse" : "",
710 errhdr->gh_major, errhdr->gh_minor);
712 /* context fini rpc, let it failed */
713 if (req->rq_ctx_fini) {
714 CWARN("context fini rpc failed\n");
718 /* reverse sec, just return error, don't expire this ctx because it's
719 * crucial to callback rpcs. note if the callback rpc failed because
720 * of bit flip during network transfer, the client will be evicted
721 * directly. so more gracefully we probably want let it retry for
722 * number of times. */
723 if (sec_is_reverse(ctx->cc_sec))
726 if (errhdr->gh_major != GSS_S_NO_CONTEXT &&
727 errhdr->gh_major != GSS_S_BAD_SIG)
730 /* server return NO_CONTEXT might be caused by context expire
731 * or server reboot/failover. we try to refresh a new ctx which
732 * be transparent to upper layer.
734 * In some cases, our gss handle is possible to be incidentally
735 * identical to another handle since the handle itself is not
736 * fully random. In krb5 case, the GSS_S_BAD_SIG will be
737 * returned, maybe other gss error for other mechanism.
739 * if we add new mechanism, make sure the correct error are
740 * returned in this case. */
741 CWARN("%s: server might lost the context, retrying\n",
742 errhdr->gh_major == GSS_S_NO_CONTEXT ? "NO_CONTEXT" : "BAD_SIG");
744 sptlrpc_cli_ctx_expire(ctx);
746 /* we need replace the ctx right here, otherwise during
747 * resent we'll hit the logic in sptlrpc_req_refresh_ctx()
748 * which keep the ctx with RESEND flag, thus we'll never
749 * get rid of this ctx. */
750 rc = sptlrpc_req_replace_dead_ctx(req);
757 int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
758 struct ptlrpc_request *req)
760 struct gss_cli_ctx *gctx;
761 struct gss_header *ghdr, *reqhdr;
762 struct lustre_msg *msg = req->rq_repdata;
764 int pack_bulk, swabbed, rc = 0;
767 LASSERT(req->rq_cli_ctx == ctx);
770 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
772 /* special case for context negotiation, rq_repmsg/rq_replen actually
773 * are not used currently. but early reply always be treated normally */
774 if (req->rq_ctx_init && !req->rq_early) {
775 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
776 req->rq_replen = msg->lm_buflens[1];
780 if (msg->lm_bufcount < 2 || msg->lm_bufcount > 4) {
781 CERROR("unexpected bufcount %u\n", msg->lm_bufcount);
785 swabbed = ptlrpc_rep_need_swab(req);
787 ghdr = gss_swab_header(msg, 0, swabbed);
789 CERROR("can't decode gss header\n");
794 reqhdr = lustre_msg_buf(msg, 0, sizeof(*reqhdr));
797 if (ghdr->gh_version != reqhdr->gh_version) {
798 CERROR("gss version %u mismatch, expect %u\n",
799 ghdr->gh_version, reqhdr->gh_version);
803 switch (ghdr->gh_proc) {
804 case PTLRPC_GSS_PROC_DATA:
805 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
807 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
808 CERROR("%s bulk flag in reply\n",
809 req->rq_pack_bulk ? "missing" : "unexpected");
813 if (ghdr->gh_seq != reqhdr->gh_seq) {
814 CERROR("seqnum %u mismatch, expect %u\n",
815 ghdr->gh_seq, reqhdr->gh_seq);
819 if (ghdr->gh_svc != reqhdr->gh_svc) {
820 CERROR("svc %u mismatch, expect %u\n",
821 ghdr->gh_svc, reqhdr->gh_svc);
826 gss_header_swabber(ghdr);
828 major = gss_verify_msg(msg, gctx->gc_mechctx, reqhdr->gh_svc);
829 if (major != GSS_S_COMPLETE) {
830 CERROR("failed to verify reply: %x\n", major);
834 if (req->rq_early && reqhdr->gh_svc == SPTLRPC_SVC_NULL) {
837 cksum = crc32_le(!(__u32) 0,
838 lustre_msg_buf(msg, 1, 0),
839 lustre_msg_buflen(msg, 1));
840 if (cksum != msg->lm_cksum) {
841 CWARN("early reply checksum mismatch: "
842 "%08x != %08x\n", cksum, msg->lm_cksum);
848 /* bulk checksum is right after the lustre msg */
849 if (msg->lm_bufcount < 3) {
850 CERROR("Invalid reply bufcount %u\n",
855 rc = bulk_sec_desc_unpack(msg, 2, swabbed);
857 CERROR("unpack bulk desc: %d\n", rc);
862 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
863 req->rq_replen = msg->lm_buflens[1];
865 case PTLRPC_GSS_PROC_ERR:
867 CERROR("server return error with early reply\n");
870 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
874 CERROR("unknown gss proc %d\n", ghdr->gh_proc);
881 int gss_cli_ctx_seal(struct ptlrpc_cli_ctx *ctx,
882 struct ptlrpc_request *req)
884 struct gss_cli_ctx *gctx;
885 rawobj_t hdrobj, msgobj, token;
886 struct gss_header *ghdr;
887 __u32 buflens[2], major;
891 LASSERT(req->rq_clrbuf);
892 LASSERT(req->rq_cli_ctx == ctx);
893 LASSERT(req->rq_reqlen);
895 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
897 /* final clear data length */
898 req->rq_clrdata_len = lustre_msg_size_v2(req->rq_clrbuf->lm_bufcount,
899 req->rq_clrbuf->lm_buflens);
901 /* calculate wire data length */
902 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
903 buflens[1] = gss_cli_payload(&gctx->gc_base, req->rq_clrdata_len, 1);
904 wiresize = lustre_msg_size_v2(2, buflens);
906 /* allocate wire buffer */
909 LASSERT(req->rq_reqbuf);
910 LASSERT(req->rq_reqbuf != req->rq_clrbuf);
911 LASSERT(req->rq_reqbuf_len >= wiresize);
913 OBD_ALLOC_LARGE(req->rq_reqbuf, wiresize);
916 req->rq_reqbuf_len = wiresize;
919 lustre_init_msg_v2(req->rq_reqbuf, 2, buflens, NULL);
920 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
923 ghdr = lustre_msg_buf(req->rq_reqbuf, 0, 0);
924 ghdr->gh_version = PTLRPC_GSS_VERSION;
925 ghdr->gh_sp = (__u8) ctx->cc_sec->ps_part;
927 ghdr->gh_proc = gctx->gc_proc;
928 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
929 ghdr->gh_handle.len = gctx->gc_handle.len;
930 memcpy(ghdr->gh_handle.data, gctx->gc_handle.data, gctx->gc_handle.len);
931 if (req->rq_pack_bulk)
932 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
933 if (req->rq_pack_udesc)
934 ghdr->gh_flags |= LUSTRE_GSS_PACK_USER;
937 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
940 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
941 hdrobj.data = (__u8 *) ghdr;
942 msgobj.len = req->rq_clrdata_len;
943 msgobj.data = (__u8 *) req->rq_clrbuf;
944 token.len = lustre_msg_buflen(req->rq_reqbuf, 1);
945 token.data = lustre_msg_buf(req->rq_reqbuf, 1, 0);
947 major = lgss_wrap(gctx->gc_mechctx, &hdrobj, &msgobj,
948 req->rq_clrbuf_len, &token);
949 if (major != GSS_S_COMPLETE) {
950 CERROR("priv: wrap message error: %08x\n", major);
951 GOTO(err_free, rc = -EPERM);
953 LASSERT(token.len <= buflens[1]);
955 /* see explain in gss_cli_ctx_sign() */
956 if (unlikely(atomic_read(&gctx->gc_seq) - ghdr->gh_seq >
957 GSS_SEQ_REPACK_THRESHOLD)) {
958 int behind = atomic_read(&gctx->gc_seq) - ghdr->gh_seq;
960 gss_stat_oos_record_cli(behind);
961 CWARN("req %p: %u behind, retry sealing\n", req, behind);
963 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
967 /* now set the final wire data length */
968 req->rq_reqdata_len = lustre_shrink_msg(req->rq_reqbuf, 1, token.len,0);
973 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
974 req->rq_reqbuf = NULL;
975 req->rq_reqbuf_len = 0;
980 int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
981 struct ptlrpc_request *req)
983 struct gss_cli_ctx *gctx;
984 struct gss_header *ghdr;
985 struct lustre_msg *msg = req->rq_repdata;
986 int msglen, pack_bulk, swabbed, rc;
990 LASSERT(req->rq_cli_ctx == ctx);
991 LASSERT(req->rq_ctx_init == 0);
994 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
995 swabbed = ptlrpc_rep_need_swab(req);
997 ghdr = gss_swab_header(msg, 0, swabbed);
999 CERROR("can't decode gss header\n");
1004 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
1005 CERROR("gss version %u mismatch, expect %u\n",
1006 ghdr->gh_version, PTLRPC_GSS_VERSION);
1010 switch (ghdr->gh_proc) {
1011 case PTLRPC_GSS_PROC_DATA:
1012 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
1014 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
1015 CERROR("%s bulk flag in reply\n",
1016 req->rq_pack_bulk ? "missing" : "unexpected");
1021 gss_header_swabber(ghdr);
1023 /* use rq_repdata_len as buffer size, which assume unseal
1024 * doesn't need extra memory space. for precise control, we'd
1025 * better calculate out actual buffer size as
1026 * (repbuf_len - offset - repdata_len) */
1027 major = gss_unseal_msg(gctx->gc_mechctx, msg,
1028 &msglen, req->rq_repdata_len);
1029 if (major != GSS_S_COMPLETE) {
1030 CERROR("failed to unwrap reply: %x\n", major);
1035 swabbed = __lustre_unpack_msg(msg, msglen);
1037 CERROR("Failed to unpack after decryption\n");
1041 if (msg->lm_bufcount < 1) {
1042 CERROR("Invalid reply buffer: empty\n");
1047 if (msg->lm_bufcount < 2) {
1048 CERROR("bufcount %u: missing bulk sec desc\n",
1053 /* bulk checksum is the last segment */
1054 if (bulk_sec_desc_unpack(msg, msg->lm_bufcount - 1,
1059 req->rq_repmsg = lustre_msg_buf(msg, 0, 0);
1060 req->rq_replen = msg->lm_buflens[0];
1064 case PTLRPC_GSS_PROC_ERR:
1065 if (req->rq_early) {
1066 CERROR("server return error with early reply\n");
1069 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
1073 CERROR("unexpected proc %d\n", ghdr->gh_proc);
1080 /*********************************************
1081 * reverse context installation *
1082 *********************************************/
1085 int gss_install_rvs_svc_ctx(struct obd_import *imp,
1086 struct gss_sec *gsec,
1087 struct gss_cli_ctx *gctx)
1089 return gss_svc_upcall_install_rvs_ctx(imp, gsec, gctx);
1092 /*********************************************
1093 * GSS security APIs *
1094 *********************************************/
1095 int gss_sec_create_common(struct gss_sec *gsec,
1096 struct ptlrpc_sec_policy *policy,
1097 struct obd_import *imp,
1098 struct ptlrpc_svc_ctx *svcctx,
1099 struct sptlrpc_flavor *sf)
1101 struct ptlrpc_sec *sec;
1104 LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_GSS);
1106 gsec->gs_mech = lgss_subflavor_to_mech(
1107 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1108 if (!gsec->gs_mech) {
1109 CERROR("gss backend 0x%x not found\n",
1110 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1114 spin_lock_init(&gsec->gs_lock);
1115 gsec->gs_rvs_hdl = 0ULL;
1117 /* initialize upper ptlrpc_sec */
1118 sec = &gsec->gs_base;
1119 sec->ps_policy = policy;
1120 atomic_set(&sec->ps_refcount, 0);
1121 atomic_set(&sec->ps_nctx, 0);
1122 sec->ps_id = sptlrpc_get_next_secid();
1124 sec->ps_import = class_import_get(imp);
1125 spin_lock_init(&sec->ps_lock);
1126 INIT_LIST_HEAD(&sec->ps_gc_list);
1129 sec->ps_gc_interval = GSS_GC_INTERVAL;
1131 LASSERT(sec_is_reverse(sec));
1133 /* never do gc on reverse sec */
1134 sec->ps_gc_interval = 0;
1137 if (SPTLRPC_FLVR_BULK_SVC(sec->ps_flvr.sf_rpc) == SPTLRPC_BULK_SVC_PRIV)
1138 sptlrpc_enc_pool_add_user();
1140 CDEBUG(D_SEC, "create %s%s@%p\n", (svcctx ? "reverse " : ""),
1141 policy->sp_name, gsec);
1145 void gss_sec_destroy_common(struct gss_sec *gsec)
1147 struct ptlrpc_sec *sec = &gsec->gs_base;
1150 LASSERT(sec->ps_import);
1151 LASSERT(atomic_read(&sec->ps_refcount) == 0);
1152 LASSERT(atomic_read(&sec->ps_nctx) == 0);
1154 if (gsec->gs_mech) {
1155 lgss_mech_put(gsec->gs_mech);
1156 gsec->gs_mech = NULL;
1159 class_import_put(sec->ps_import);
1161 if (SPTLRPC_FLVR_BULK_SVC(sec->ps_flvr.sf_rpc) == SPTLRPC_BULK_SVC_PRIV)
1162 sptlrpc_enc_pool_del_user();
1167 void gss_sec_kill(struct ptlrpc_sec *sec)
1172 int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
1173 struct ptlrpc_cli_ctx *ctx,
1174 struct ptlrpc_ctx_ops *ctxops,
1175 struct vfs_cred *vcred)
1177 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1180 atomic_set(&gctx->gc_seq, 0);
1182 INIT_HLIST_NODE(&ctx->cc_cache);
1183 atomic_set(&ctx->cc_refcount, 0);
1185 ctx->cc_ops = ctxops;
1187 ctx->cc_flags = PTLRPC_CTX_NEW;
1188 ctx->cc_vcred = *vcred;
1189 spin_lock_init(&ctx->cc_lock);
1190 INIT_LIST_HEAD(&ctx->cc_req_list);
1191 INIT_LIST_HEAD(&ctx->cc_gc_chain);
1193 /* take a ref on belonging sec, balanced in ctx destroying */
1194 atomic_inc(&sec->ps_refcount);
1195 /* statistic only */
1196 atomic_inc(&sec->ps_nctx);
1198 CDEBUG(D_SEC, "%s@%p: create ctx %p(%u->%s)\n",
1199 sec->ps_policy->sp_name, ctx->cc_sec,
1200 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1206 * 1: the context has been taken care of by someone else
1207 * 0: proceed to really destroy the context locally
1209 int gss_cli_ctx_fini_common(struct ptlrpc_sec *sec,
1210 struct ptlrpc_cli_ctx *ctx)
1212 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1214 LASSERT(atomic_read(&sec->ps_nctx) > 0);
1215 LASSERT(atomic_read(&ctx->cc_refcount) == 0);
1216 LASSERT(ctx->cc_sec == sec);
1219 * remove UPTODATE flag of reverse ctx thus we won't send fini rpc,
1220 * this is to avoid potential problems of client side reverse svc ctx
1221 * be mis-destroyed in various recovery senarios. anyway client can
1222 * manage its reverse ctx well by associating it with its buddy ctx.
1224 if (sec_is_reverse(sec))
1225 ctx->cc_flags &= ~PTLRPC_CTX_UPTODATE;
1227 if (gctx->gc_mechctx) {
1228 /* the final context fini rpc will use this ctx too, and it's
1229 * asynchronous which finished by request_out_callback(). so
1230 * we add refcount, whoever drop finally drop the refcount to
1231 * 0 should responsible for the rest of destroy. */
1232 atomic_inc(&ctx->cc_refcount);
1234 gss_do_ctx_fini_rpc(gctx);
1235 gss_cli_ctx_finalize(gctx);
1237 if (!atomic_dec_and_test(&ctx->cc_refcount))
1241 if (sec_is_reverse(sec))
1242 CWARN("reverse sec %p: destroy ctx %p\n",
1245 CWARN("%s@%p: destroy ctx %p(%u->%s)\n",
1246 sec->ps_policy->sp_name, ctx->cc_sec,
1247 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1253 int gss_alloc_reqbuf_intg(struct ptlrpc_sec *sec,
1254 struct ptlrpc_request *req,
1255 int svc, int msgsize)
1257 int bufsize, txtsize;
1263 * on-wire data layout:
1266 * - user descriptor (optional)
1267 * - bulk sec descriptor (optional)
1268 * - signature (optional)
1269 * - svc == NULL: NULL
1270 * - svc == AUTH: signature of gss header
1271 * - svc == INTG: signature of all above
1273 * if this is context negotiation, reserver fixed space
1274 * at the last (signature) segment regardless of svc mode.
1277 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1278 txtsize = buflens[0];
1280 buflens[1] = msgsize;
1281 if (svc == SPTLRPC_SVC_INTG)
1282 txtsize += buflens[1];
1284 if (req->rq_pack_udesc) {
1285 buflens[bufcnt] = sptlrpc_current_user_desc_size();
1286 if (svc == SPTLRPC_SVC_INTG)
1287 txtsize += buflens[bufcnt];
1291 if (req->rq_pack_bulk) {
1292 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1294 0, req->rq_bulk_read);
1295 if (svc == SPTLRPC_SVC_INTG)
1296 txtsize += buflens[bufcnt];
1300 if (req->rq_ctx_init)
1301 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1302 else if (svc != SPTLRPC_SVC_NULL)
1303 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1305 bufsize = lustre_msg_size_v2(bufcnt, buflens);
1307 if (!req->rq_reqbuf) {
1308 bufsize = size_roundup_power2(bufsize);
1310 OBD_ALLOC_LARGE(req->rq_reqbuf, bufsize);
1311 if (!req->rq_reqbuf)
1314 req->rq_reqbuf_len = bufsize;
1316 LASSERT(req->rq_pool);
1317 LASSERT(req->rq_reqbuf_len >= bufsize);
1318 memset(req->rq_reqbuf, 0, bufsize);
1321 lustre_init_msg_v2(req->rq_reqbuf, bufcnt, buflens, NULL);
1322 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
1324 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, msgsize);
1325 LASSERT(req->rq_reqmsg);
1327 /* pack user desc here, later we might leave current user's process */
1328 if (req->rq_pack_udesc)
1329 sptlrpc_pack_user_desc(req->rq_reqbuf, 2);
1335 int gss_alloc_reqbuf_priv(struct ptlrpc_sec *sec,
1336 struct ptlrpc_request *req,
1339 __u32 ibuflens[3], wbuflens[2];
1341 int clearsize, wiresize;
1344 LASSERT(req->rq_clrbuf == NULL);
1345 LASSERT(req->rq_clrbuf_len == 0);
1347 /* Inner (clear) buffers
1349 * - user descriptor (optional)
1350 * - bulk checksum (optional)
1353 ibuflens[0] = msgsize;
1355 if (req->rq_pack_udesc)
1356 ibuflens[ibufcnt++] = sptlrpc_current_user_desc_size();
1357 if (req->rq_pack_bulk)
1358 ibuflens[ibufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1362 clearsize = lustre_msg_size_v2(ibufcnt, ibuflens);
1363 /* to allow append padding during encryption */
1364 clearsize += GSS_MAX_CIPHER_BLOCK;
1366 /* Wrapper (wire) buffers
1370 wbuflens[0] = PTLRPC_GSS_HEADER_SIZE;
1371 wbuflens[1] = gss_cli_payload(req->rq_cli_ctx, clearsize, 1);
1372 wiresize = lustre_msg_size_v2(2, wbuflens);
1375 /* rq_reqbuf is preallocated */
1376 LASSERT(req->rq_reqbuf);
1377 LASSERT(req->rq_reqbuf_len >= wiresize);
1379 memset(req->rq_reqbuf, 0, req->rq_reqbuf_len);
1381 /* if the pre-allocated buffer is big enough, we just pack
1382 * both clear buf & request buf in it, to avoid more alloc. */
1383 if (clearsize + wiresize <= req->rq_reqbuf_len) {
1385 (void *) (((char *) req->rq_reqbuf) + wiresize);
1387 CWARN("pre-allocated buf size %d is not enough for "
1388 "both clear (%d) and cipher (%d) text, proceed "
1389 "with extra allocation\n", req->rq_reqbuf_len,
1390 clearsize, wiresize);
1394 if (!req->rq_clrbuf) {
1395 clearsize = size_roundup_power2(clearsize);
1397 OBD_ALLOC_LARGE(req->rq_clrbuf, clearsize);
1398 if (!req->rq_clrbuf)
1401 req->rq_clrbuf_len = clearsize;
1403 lustre_init_msg_v2(req->rq_clrbuf, ibufcnt, ibuflens, NULL);
1404 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, msgsize);
1406 if (req->rq_pack_udesc)
1407 sptlrpc_pack_user_desc(req->rq_clrbuf, 1);
1413 * NOTE: any change of request buffer allocation should also consider
1414 * changing enlarge_reqbuf() series functions.
1416 int gss_alloc_reqbuf(struct ptlrpc_sec *sec,
1417 struct ptlrpc_request *req,
1420 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1422 LASSERT(!req->rq_pack_bulk ||
1423 (req->rq_bulk_read || req->rq_bulk_write));
1426 case SPTLRPC_SVC_NULL:
1427 case SPTLRPC_SVC_AUTH:
1428 case SPTLRPC_SVC_INTG:
1429 return gss_alloc_reqbuf_intg(sec, req, svc, msgsize);
1430 case SPTLRPC_SVC_PRIV:
1431 return gss_alloc_reqbuf_priv(sec, req, msgsize);
1433 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1438 void gss_free_reqbuf(struct ptlrpc_sec *sec,
1439 struct ptlrpc_request *req)
1444 LASSERT(!req->rq_pool || req->rq_reqbuf);
1445 privacy = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc) == SPTLRPC_SVC_PRIV;
1447 if (!req->rq_clrbuf)
1448 goto release_reqbuf;
1450 /* release clear buffer */
1452 LASSERT(req->rq_clrbuf_len);
1454 if (req->rq_pool == NULL ||
1455 req->rq_clrbuf < req->rq_reqbuf ||
1456 (char *) req->rq_clrbuf >=
1457 (char *) req->rq_reqbuf + req->rq_reqbuf_len)
1458 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1460 req->rq_clrbuf = NULL;
1461 req->rq_clrbuf_len = 0;
1464 if (!req->rq_pool && req->rq_reqbuf) {
1465 LASSERT(req->rq_reqbuf_len);
1467 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1468 req->rq_reqbuf = NULL;
1469 req->rq_reqbuf_len = 0;
1475 static int do_alloc_repbuf(struct ptlrpc_request *req, int bufsize)
1477 bufsize = size_roundup_power2(bufsize);
1479 OBD_ALLOC_LARGE(req->rq_repbuf, bufsize);
1480 if (!req->rq_repbuf)
1483 req->rq_repbuf_len = bufsize;
1488 int gss_alloc_repbuf_intg(struct ptlrpc_sec *sec,
1489 struct ptlrpc_request *req,
1490 int svc, int msgsize)
1498 * on-wire data layout:
1501 * - bulk sec descriptor (optional)
1502 * - signature (optional)
1503 * - svc == NULL: NULL
1504 * - svc == AUTH: signature of gss header
1505 * - svc == INTG: signature of all above
1507 * if this is context negotiation, reserver fixed space
1508 * at the last (signature) segment regardless of svc mode.
1511 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1512 txtsize = buflens[0];
1514 buflens[1] = msgsize;
1515 if (svc == SPTLRPC_SVC_INTG)
1516 txtsize += buflens[1];
1518 if (req->rq_pack_bulk) {
1519 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1521 1, req->rq_bulk_read);
1522 if (svc == SPTLRPC_SVC_INTG)
1523 txtsize += buflens[bufcnt];
1527 if (req->rq_ctx_init)
1528 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1529 else if (svc != SPTLRPC_SVC_NULL)
1530 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1532 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1534 /* add space for early reply */
1535 alloc_size += gss_at_reply_off_integ;
1537 return do_alloc_repbuf(req, alloc_size);
1541 int gss_alloc_repbuf_priv(struct ptlrpc_sec *sec,
1542 struct ptlrpc_request *req,
1552 buflens[0] = msgsize;
1554 if (req->rq_pack_bulk)
1555 buflens[bufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1557 1, req->rq_bulk_read);
1558 txtsize = lustre_msg_size_v2(bufcnt, buflens);
1559 txtsize += GSS_MAX_CIPHER_BLOCK;
1561 /* wrapper buffers */
1563 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1564 buflens[1] = gss_cli_payload(req->rq_cli_ctx, txtsize, 1);
1566 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1567 /* add space for early reply */
1568 alloc_size += gss_at_reply_off_priv;
1570 return do_alloc_repbuf(req, alloc_size);
1573 int gss_alloc_repbuf(struct ptlrpc_sec *sec,
1574 struct ptlrpc_request *req,
1577 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1580 LASSERT(!req->rq_pack_bulk ||
1581 (req->rq_bulk_read || req->rq_bulk_write));
1584 case SPTLRPC_SVC_NULL:
1585 case SPTLRPC_SVC_AUTH:
1586 case SPTLRPC_SVC_INTG:
1587 return gss_alloc_repbuf_intg(sec, req, svc, msgsize);
1588 case SPTLRPC_SVC_PRIV:
1589 return gss_alloc_repbuf_priv(sec, req, msgsize);
1591 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1596 void gss_free_repbuf(struct ptlrpc_sec *sec,
1597 struct ptlrpc_request *req)
1599 OBD_FREE_LARGE(req->rq_repbuf, req->rq_repbuf_len);
1600 req->rq_repbuf = NULL;
1601 req->rq_repbuf_len = 0;
1602 req->rq_repdata = NULL;
1603 req->rq_repdata_len = 0;
1606 static int get_enlarged_msgsize(struct lustre_msg *msg,
1607 int segment, int newsize)
1609 int save, newmsg_size;
1611 LASSERT(newsize >= msg->lm_buflens[segment]);
1613 save = msg->lm_buflens[segment];
1614 msg->lm_buflens[segment] = newsize;
1615 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1616 msg->lm_buflens[segment] = save;
1621 static int get_enlarged_msgsize2(struct lustre_msg *msg,
1622 int segment1, int newsize1,
1623 int segment2, int newsize2)
1625 int save1, save2, newmsg_size;
1627 LASSERT(newsize1 >= msg->lm_buflens[segment1]);
1628 LASSERT(newsize2 >= msg->lm_buflens[segment2]);
1630 save1 = msg->lm_buflens[segment1];
1631 save2 = msg->lm_buflens[segment2];
1632 msg->lm_buflens[segment1] = newsize1;
1633 msg->lm_buflens[segment2] = newsize2;
1634 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1635 msg->lm_buflens[segment1] = save1;
1636 msg->lm_buflens[segment2] = save2;
1642 int gss_enlarge_reqbuf_intg(struct ptlrpc_sec *sec,
1643 struct ptlrpc_request *req,
1645 int segment, int newsize)
1647 struct lustre_msg *newbuf;
1648 int txtsize, sigsize = 0, i;
1649 int newmsg_size, newbuf_size;
1652 * gss header is at seg 0;
1653 * embedded msg is at seg 1;
1654 * signature (if any) is at the last seg
1656 LASSERT(req->rq_reqbuf);
1657 LASSERT(req->rq_reqbuf_len > req->rq_reqlen);
1658 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
1659 LASSERT(lustre_msg_buf(req->rq_reqbuf, 1, 0) == req->rq_reqmsg);
1661 /* 1. compute new embedded msg size */
1662 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1663 LASSERT(newmsg_size >= req->rq_reqbuf->lm_buflens[1]);
1665 /* 2. compute new wrapper msg size */
1666 if (svc == SPTLRPC_SVC_NULL) {
1667 /* no signature, get size directly */
1668 newbuf_size = get_enlarged_msgsize(req->rq_reqbuf,
1671 txtsize = req->rq_reqbuf->lm_buflens[0];
1673 if (svc == SPTLRPC_SVC_INTG) {
1674 for (i = 1; i < req->rq_reqbuf->lm_bufcount; i++)
1675 txtsize += req->rq_reqbuf->lm_buflens[i];
1676 txtsize += newmsg_size - req->rq_reqbuf->lm_buflens[1];
1679 sigsize = gss_cli_payload(req->rq_cli_ctx, txtsize, 0);
1680 LASSERT(sigsize >= msg_last_seglen(req->rq_reqbuf));
1682 newbuf_size = get_enlarged_msgsize2(
1685 msg_last_segidx(req->rq_reqbuf),
1689 /* request from pool should always have enough buffer */
1690 LASSERT(!req->rq_pool || req->rq_reqbuf_len >= newbuf_size);
1692 if (req->rq_reqbuf_len < newbuf_size) {
1693 newbuf_size = size_roundup_power2(newbuf_size);
1695 OBD_ALLOC_LARGE(newbuf, newbuf_size);
1699 /* Must lock this, so that otherwise unprotected change of
1700 * rq_reqmsg is not racing with parallel processing of
1701 * imp_replay_list traversing threads. See LU-3333
1702 * This is a bandaid at best, we really need to deal with this
1703 * in request enlarging code before unpacking that's already
1706 spin_lock(&req->rq_import->imp_lock);
1708 memcpy(newbuf, req->rq_reqbuf, req->rq_reqbuf_len);
1710 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1711 req->rq_reqbuf = newbuf;
1712 req->rq_reqbuf_len = newbuf_size;
1713 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, 0);
1716 spin_unlock(&req->rq_import->imp_lock);
1719 /* do enlargement, from wrapper to embedded, from end to begin */
1720 if (svc != SPTLRPC_SVC_NULL)
1721 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf,
1722 msg_last_segidx(req->rq_reqbuf),
1725 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf, 1, newmsg_size);
1726 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1728 req->rq_reqlen = newmsg_size;
1733 int gss_enlarge_reqbuf_priv(struct ptlrpc_sec *sec,
1734 struct ptlrpc_request *req,
1735 int segment, int newsize)
1737 struct lustre_msg *newclrbuf;
1738 int newmsg_size, newclrbuf_size, newcipbuf_size;
1742 * embedded msg is at seg 0 of clear buffer;
1743 * cipher text is at seg 2 of cipher buffer;
1745 LASSERT(req->rq_pool ||
1746 (req->rq_reqbuf == NULL && req->rq_reqbuf_len == 0));
1747 LASSERT(req->rq_reqbuf == NULL ||
1748 (req->rq_pool && req->rq_reqbuf->lm_bufcount == 3));
1749 LASSERT(req->rq_clrbuf);
1750 LASSERT(req->rq_clrbuf_len > req->rq_reqlen);
1751 LASSERT(lustre_msg_buf(req->rq_clrbuf, 0, 0) == req->rq_reqmsg);
1753 /* compute new embedded msg size */
1754 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1756 /* compute new clear buffer size */
1757 newclrbuf_size = get_enlarged_msgsize(req->rq_clrbuf, 0, newmsg_size);
1758 newclrbuf_size += GSS_MAX_CIPHER_BLOCK;
1760 /* compute new cipher buffer size */
1761 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1762 buflens[1] = gss_cli_payload(req->rq_cli_ctx, buflens[0], 0);
1763 buflens[2] = gss_cli_payload(req->rq_cli_ctx, newclrbuf_size, 1);
1764 newcipbuf_size = lustre_msg_size_v2(3, buflens);
1766 /* handle the case that we put both clear buf and cipher buf into
1767 * pre-allocated single buffer. */
1768 if (unlikely(req->rq_pool) &&
1769 req->rq_clrbuf >= req->rq_reqbuf &&
1770 (char *) req->rq_clrbuf <
1771 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1772 /* it couldn't be better we still fit into the
1773 * pre-allocated buffer. */
1774 if (newclrbuf_size + newcipbuf_size <= req->rq_reqbuf_len) {
1778 spin_lock(&req->rq_import->imp_lock);
1779 /* move clear text backward. */
1780 src = req->rq_clrbuf;
1781 dst = (char *) req->rq_reqbuf + newcipbuf_size;
1783 memmove(dst, src, req->rq_clrbuf_len);
1785 req->rq_clrbuf = (struct lustre_msg *) dst;
1786 req->rq_clrbuf_len = newclrbuf_size;
1787 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1790 spin_unlock(&req->rq_import->imp_lock);
1792 /* sadly we have to split out the clear buffer */
1793 LASSERT(req->rq_reqbuf_len >= newcipbuf_size);
1794 LASSERT(req->rq_clrbuf_len < newclrbuf_size);
1798 if (req->rq_clrbuf_len < newclrbuf_size) {
1799 newclrbuf_size = size_roundup_power2(newclrbuf_size);
1801 OBD_ALLOC_LARGE(newclrbuf, newclrbuf_size);
1802 if (newclrbuf == NULL)
1805 /* Must lock this, so that otherwise unprotected change of
1806 * rq_reqmsg is not racing with parallel processing of
1807 * imp_replay_list traversing threads. See LU-3333
1808 * This is a bandaid at best, we really need to deal with this
1809 * in request enlarging code before unpacking that's already
1812 spin_lock(&req->rq_import->imp_lock);
1814 memcpy(newclrbuf, req->rq_clrbuf, req->rq_clrbuf_len);
1816 if (req->rq_reqbuf == NULL ||
1817 req->rq_clrbuf < req->rq_reqbuf ||
1818 (char *) req->rq_clrbuf >=
1819 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1820 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1823 req->rq_clrbuf = newclrbuf;
1824 req->rq_clrbuf_len = newclrbuf_size;
1825 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1828 spin_unlock(&req->rq_import->imp_lock);
1831 _sptlrpc_enlarge_msg_inplace(req->rq_clrbuf, 0, newmsg_size);
1832 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1833 req->rq_reqlen = newmsg_size;
1838 int gss_enlarge_reqbuf(struct ptlrpc_sec *sec,
1839 struct ptlrpc_request *req,
1840 int segment, int newsize)
1842 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1844 LASSERT(!req->rq_ctx_init && !req->rq_ctx_fini);
1847 case SPTLRPC_SVC_NULL:
1848 case SPTLRPC_SVC_AUTH:
1849 case SPTLRPC_SVC_INTG:
1850 return gss_enlarge_reqbuf_intg(sec, req, svc, segment, newsize);
1851 case SPTLRPC_SVC_PRIV:
1852 return gss_enlarge_reqbuf_priv(sec, req, segment, newsize);
1854 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1859 int gss_sec_install_rctx(struct obd_import *imp,
1860 struct ptlrpc_sec *sec,
1861 struct ptlrpc_cli_ctx *ctx)
1863 struct gss_sec *gsec;
1864 struct gss_cli_ctx *gctx;
1867 gsec = container_of(sec, struct gss_sec, gs_base);
1868 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
1870 rc = gss_install_rvs_svc_ctx(imp, gsec, gctx);
1874 /********************************************
1876 ********************************************/
1879 int gss_svc_reqctx_is_special(struct gss_svc_reqctx *grctx)
1882 return (grctx->src_init || grctx->src_init_continue ||
1883 grctx->src_err_notify);
1887 void gss_svc_reqctx_free(struct gss_svc_reqctx *grctx)
1890 gss_svc_upcall_put_ctx(grctx->src_ctx);
1892 sptlrpc_policy_put(grctx->src_base.sc_policy);
1893 OBD_FREE_PTR(grctx);
1897 void gss_svc_reqctx_addref(struct gss_svc_reqctx *grctx)
1899 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1900 atomic_inc(&grctx->src_base.sc_refcount);
1904 void gss_svc_reqctx_decref(struct gss_svc_reqctx *grctx)
1906 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1908 if (atomic_dec_and_test(&grctx->src_base.sc_refcount))
1909 gss_svc_reqctx_free(grctx);
1913 int gss_svc_sign(struct ptlrpc_request *req,
1914 struct ptlrpc_reply_state *rs,
1915 struct gss_svc_reqctx *grctx,
1922 LASSERT(rs->rs_msg == lustre_msg_buf(rs->rs_repbuf, 1, 0));
1924 /* embedded lustre_msg might have been shrunk */
1925 if (req->rq_replen != rs->rs_repbuf->lm_buflens[1])
1926 lustre_shrink_msg(rs->rs_repbuf, 1, req->rq_replen, 1);
1928 if (req->rq_pack_bulk)
1929 flags |= LUSTRE_GSS_PACK_BULK;
1931 rc = gss_sign_msg(rs->rs_repbuf, grctx->src_ctx->gsc_mechctx,
1932 LUSTRE_SP_ANY, flags, PTLRPC_GSS_PROC_DATA,
1933 grctx->src_wirectx.gw_seq, svc, NULL);
1937 rs->rs_repdata_len = rc;
1939 if (likely(req->rq_packed_final)) {
1940 if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
1941 req->rq_reply_off = gss_at_reply_off_integ;
1943 req->rq_reply_off = 0;
1945 if (svc == SPTLRPC_SVC_NULL)
1946 rs->rs_repbuf->lm_cksum = crc32_le(!(__u32) 0,
1947 lustre_msg_buf(rs->rs_repbuf, 1, 0),
1948 lustre_msg_buflen(rs->rs_repbuf, 1));
1949 req->rq_reply_off = 0;
1955 int gss_pack_err_notify(struct ptlrpc_request *req, __u32 major, __u32 minor)
1957 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
1958 struct ptlrpc_reply_state *rs;
1959 struct gss_err_header *ghdr;
1960 int replen = sizeof(struct ptlrpc_body);
1964 //if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_SVCGSS_ERR_NOTIFY, OBD_FAIL_ONCE))
1967 grctx->src_err_notify = 1;
1968 grctx->src_reserve_len = 0;
1970 rc = lustre_pack_reply_v2(req, 1, &replen, NULL, 0);
1972 CERROR("could not pack reply, err %d\n", rc);
1977 rs = req->rq_reply_state;
1978 LASSERT(rs->rs_repbuf->lm_buflens[1] >= sizeof(*ghdr));
1979 ghdr = lustre_msg_buf(rs->rs_repbuf, 0, 0);
1980 ghdr->gh_version = PTLRPC_GSS_VERSION;
1982 ghdr->gh_proc = PTLRPC_GSS_PROC_ERR;
1983 ghdr->gh_major = major;
1984 ghdr->gh_minor = minor;
1985 ghdr->gh_handle.len = 0; /* fake context handle */
1987 rs->rs_repdata_len = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
1988 rs->rs_repbuf->lm_buflens);
1990 CDEBUG(D_SEC, "prepare gss error notify(0x%x/0x%x) to %s\n",
1991 major, minor, libcfs_nid2str(req->rq_peer.nid));
1996 int gss_svc_handle_init(struct ptlrpc_request *req,
1997 struct gss_wire_ctx *gw)
1999 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2000 struct lustre_msg *reqbuf = req->rq_reqbuf;
2001 struct obd_uuid *uuid;
2002 struct obd_device *target;
2003 rawobj_t uuid_obj, rvs_hdl, in_token;
2005 __u32 *secdata, seclen;
2009 CDEBUG(D_SEC, "processing gss init(%d) request from %s\n", gw->gw_proc,
2010 libcfs_nid2str(req->rq_peer.nid));
2012 req->rq_ctx_init = 1;
2014 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2015 CERROR("unexpected bulk flag\n");
2016 RETURN(SECSVC_DROP);
2019 if (gw->gw_proc == PTLRPC_GSS_PROC_INIT && gw->gw_handle.len != 0) {
2020 CERROR("proc %u: invalid handle length %u\n",
2021 gw->gw_proc, gw->gw_handle.len);
2022 RETURN(SECSVC_DROP);
2025 if (reqbuf->lm_bufcount < 3 || reqbuf->lm_bufcount > 4){
2026 CERROR("Invalid bufcount %d\n", reqbuf->lm_bufcount);
2027 RETURN(SECSVC_DROP);
2030 swabbed = ptlrpc_req_need_swab(req);
2032 /* ctx initiate payload is in last segment */
2033 secdata = lustre_msg_buf(reqbuf, reqbuf->lm_bufcount - 1, 0);
2034 seclen = reqbuf->lm_buflens[reqbuf->lm_bufcount - 1];
2036 if (seclen < 4 + 4) {
2037 CERROR("sec size %d too small\n", seclen);
2038 RETURN(SECSVC_DROP);
2041 /* lustre svc type */
2042 lustre_svc = le32_to_cpu(*secdata++);
2045 /* extract target uuid, note this code is somewhat fragile
2046 * because touched internal structure of obd_uuid */
2047 if (rawobj_extract(&uuid_obj, &secdata, &seclen)) {
2048 CERROR("failed to extract target uuid\n");
2049 RETURN(SECSVC_DROP);
2051 uuid_obj.data[uuid_obj.len - 1] = '\0';
2053 uuid = (struct obd_uuid *) uuid_obj.data;
2054 target = class_uuid2obd(uuid);
2055 if (!target || target->obd_stopping || !target->obd_set_up) {
2056 CERROR("target '%s' is not available for context init (%s)\n",
2057 uuid->uuid, target == NULL ? "no target" :
2058 (target->obd_stopping ? "stopping" : "not set up"));
2059 RETURN(SECSVC_DROP);
2062 /* extract reverse handle */
2063 if (rawobj_extract(&rvs_hdl, &secdata, &seclen)) {
2064 CERROR("failed extract reverse handle\n");
2065 RETURN(SECSVC_DROP);
2069 if (rawobj_extract(&in_token, &secdata, &seclen)) {
2070 CERROR("can't extract token\n");
2071 RETURN(SECSVC_DROP);
2074 rc = gss_svc_upcall_handle_init(req, grctx, gw, target, lustre_svc,
2075 &rvs_hdl, &in_token);
2076 if (rc != SECSVC_OK)
2079 if (grctx->src_ctx->gsc_usr_mds || grctx->src_ctx->gsc_usr_oss ||
2080 grctx->src_ctx->gsc_usr_root)
2081 CWARN("create svc ctx %p: user from %s authenticated as %s\n",
2082 grctx->src_ctx, libcfs_nid2str(req->rq_peer.nid),
2083 grctx->src_ctx->gsc_usr_mds ? "mds" :
2084 (grctx->src_ctx->gsc_usr_oss ? "oss" : "root"));
2086 CWARN("create svc ctx %p: accept user %u from %s\n",
2087 grctx->src_ctx, grctx->src_ctx->gsc_uid,
2088 libcfs_nid2str(req->rq_peer.nid));
2090 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2091 if (reqbuf->lm_bufcount < 4) {
2092 CERROR("missing user descriptor\n");
2093 RETURN(SECSVC_DROP);
2095 if (sptlrpc_unpack_user_desc(reqbuf, 2, swabbed)) {
2096 CERROR("Mal-formed user descriptor\n");
2097 RETURN(SECSVC_DROP);
2100 req->rq_pack_udesc = 1;
2101 req->rq_user_desc = lustre_msg_buf(reqbuf, 2, 0);
2104 req->rq_reqmsg = lustre_msg_buf(reqbuf, 1, 0);
2105 req->rq_reqlen = lustre_msg_buflen(reqbuf, 1);
2111 * last segment must be the gss signature.
2114 int gss_svc_verify_request(struct ptlrpc_request *req,
2115 struct gss_svc_reqctx *grctx,
2116 struct gss_wire_ctx *gw,
2119 struct gss_svc_ctx *gctx = grctx->src_ctx;
2120 struct lustre_msg *msg = req->rq_reqbuf;
2125 *major = GSS_S_COMPLETE;
2127 if (msg->lm_bufcount < 2) {
2128 CERROR("Too few segments (%u) in request\n", msg->lm_bufcount);
2132 if (gw->gw_svc == SPTLRPC_SVC_NULL)
2135 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2136 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2137 *major = GSS_S_DUPLICATE_TOKEN;
2141 *major = gss_verify_msg(msg, gctx->gsc_mechctx, gw->gw_svc);
2142 if (*major != GSS_S_COMPLETE) {
2143 CERROR("failed to verify request: %x\n", *major);
2147 if (gctx->gsc_reverse == 0 &&
2148 gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2149 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2150 *major = GSS_S_DUPLICATE_TOKEN;
2155 swabbed = ptlrpc_req_need_swab(req);
2157 /* user descriptor */
2158 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2159 if (msg->lm_bufcount < (offset + 1)) {
2160 CERROR("no user desc included\n");
2164 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2165 CERROR("Mal-formed user descriptor\n");
2169 req->rq_pack_udesc = 1;
2170 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2174 /* check bulk_sec_desc data */
2175 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2176 if (msg->lm_bufcount < (offset + 1)) {
2177 CERROR("missing bulk sec descriptor\n");
2181 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2184 req->rq_pack_bulk = 1;
2185 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2186 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2189 req->rq_reqmsg = lustre_msg_buf(msg, 1, 0);
2190 req->rq_reqlen = msg->lm_buflens[1];
2195 int gss_svc_unseal_request(struct ptlrpc_request *req,
2196 struct gss_svc_reqctx *grctx,
2197 struct gss_wire_ctx *gw,
2200 struct gss_svc_ctx *gctx = grctx->src_ctx;
2201 struct lustre_msg *msg = req->rq_reqbuf;
2202 int swabbed, msglen, offset = 1;
2205 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2206 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2207 *major = GSS_S_DUPLICATE_TOKEN;
2211 *major = gss_unseal_msg(gctx->gsc_mechctx, msg,
2212 &msglen, req->rq_reqdata_len);
2213 if (*major != GSS_S_COMPLETE) {
2214 CERROR("failed to unwrap request: %x\n", *major);
2218 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2219 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2220 *major = GSS_S_DUPLICATE_TOKEN;
2224 swabbed = __lustre_unpack_msg(msg, msglen);
2226 CERROR("Failed to unpack after decryption\n");
2229 req->rq_reqdata_len = msglen;
2231 if (msg->lm_bufcount < 1) {
2232 CERROR("Invalid buffer: is empty\n");
2236 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2237 if (msg->lm_bufcount < offset + 1) {
2238 CERROR("no user descriptor included\n");
2242 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2243 CERROR("Mal-formed user descriptor\n");
2247 req->rq_pack_udesc = 1;
2248 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2252 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2253 if (msg->lm_bufcount < offset + 1) {
2254 CERROR("no bulk checksum included\n");
2258 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2261 req->rq_pack_bulk = 1;
2262 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2263 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2266 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 0, 0);
2267 req->rq_reqlen = req->rq_reqbuf->lm_buflens[0];
2272 int gss_svc_handle_data(struct ptlrpc_request *req,
2273 struct gss_wire_ctx *gw)
2275 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2280 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2281 if (!grctx->src_ctx) {
2282 major = GSS_S_NO_CONTEXT;
2286 switch (gw->gw_svc) {
2287 case SPTLRPC_SVC_NULL:
2288 case SPTLRPC_SVC_AUTH:
2289 case SPTLRPC_SVC_INTG:
2290 rc = gss_svc_verify_request(req, grctx, gw, &major);
2292 case SPTLRPC_SVC_PRIV:
2293 rc = gss_svc_unseal_request(req, grctx, gw, &major);
2296 CERROR("unsupported gss service %d\n", gw->gw_svc);
2303 CERROR("svc %u failed: major 0x%08x: req xid "LPU64" ctx %p idx "
2304 LPX64"(%u->%s)\n", gw->gw_svc, major, req->rq_xid,
2305 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2306 grctx->src_ctx->gsc_uid, libcfs_nid2str(req->rq_peer.nid));
2308 /* we only notify client in case of NO_CONTEXT/BAD_SIG, which
2309 * might happen after server reboot, to allow recovery. */
2310 if ((major == GSS_S_NO_CONTEXT || major == GSS_S_BAD_SIG) &&
2311 gss_pack_err_notify(req, major, 0) == 0)
2312 RETURN(SECSVC_COMPLETE);
2314 RETURN(SECSVC_DROP);
2318 int gss_svc_handle_destroy(struct ptlrpc_request *req,
2319 struct gss_wire_ctx *gw)
2321 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2325 req->rq_ctx_fini = 1;
2326 req->rq_no_reply = 1;
2328 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2329 if (!grctx->src_ctx) {
2330 CDEBUG(D_SEC, "invalid gss context handle for destroy.\n");
2331 RETURN(SECSVC_DROP);
2334 if (gw->gw_svc != SPTLRPC_SVC_INTG) {
2335 CERROR("svc %u is not supported in destroy.\n", gw->gw_svc);
2336 RETURN(SECSVC_DROP);
2339 if (gss_svc_verify_request(req, grctx, gw, &major))
2340 RETURN(SECSVC_DROP);
2342 CWARN("destroy svc ctx %p idx "LPX64" (%u->%s)\n",
2343 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2344 grctx->src_ctx->gsc_uid, libcfs_nid2str(req->rq_peer.nid));
2346 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2348 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2349 if (req->rq_reqbuf->lm_bufcount < 4) {
2350 CERROR("missing user descriptor, ignore it\n");
2353 if (sptlrpc_unpack_user_desc(req->rq_reqbuf, 2,
2354 ptlrpc_req_need_swab(req))) {
2355 CERROR("Mal-formed user descriptor, ignore it\n");
2359 req->rq_pack_udesc = 1;
2360 req->rq_user_desc = lustre_msg_buf(req->rq_reqbuf, 2, 0);
2366 int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
2368 struct gss_header *ghdr;
2369 struct gss_svc_reqctx *grctx;
2370 struct gss_wire_ctx *gw;
2374 LASSERT(req->rq_reqbuf);
2375 LASSERT(req->rq_svc_ctx == NULL);
2377 if (req->rq_reqbuf->lm_bufcount < 2) {
2378 CERROR("buf count only %d\n", req->rq_reqbuf->lm_bufcount);
2379 RETURN(SECSVC_DROP);
2382 swabbed = ptlrpc_req_need_swab(req);
2384 ghdr = gss_swab_header(req->rq_reqbuf, 0, swabbed);
2386 CERROR("can't decode gss header\n");
2387 RETURN(SECSVC_DROP);
2391 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
2392 CERROR("gss version %u, expect %u\n", ghdr->gh_version,
2393 PTLRPC_GSS_VERSION);
2394 RETURN(SECSVC_DROP);
2397 req->rq_sp_from = ghdr->gh_sp;
2399 /* alloc grctx data */
2400 OBD_ALLOC_PTR(grctx);
2402 RETURN(SECSVC_DROP);
2404 grctx->src_base.sc_policy = sptlrpc_policy_get(policy);
2405 atomic_set(&grctx->src_base.sc_refcount, 1);
2406 req->rq_svc_ctx = &grctx->src_base;
2407 gw = &grctx->src_wirectx;
2409 /* save wire context */
2410 gw->gw_flags = ghdr->gh_flags;
2411 gw->gw_proc = ghdr->gh_proc;
2412 gw->gw_seq = ghdr->gh_seq;
2413 gw->gw_svc = ghdr->gh_svc;
2414 rawobj_from_netobj(&gw->gw_handle, &ghdr->gh_handle);
2416 /* keep original wire header which subject to checksum verification */
2418 gss_header_swabber(ghdr);
2420 switch(ghdr->gh_proc) {
2421 case PTLRPC_GSS_PROC_INIT:
2422 case PTLRPC_GSS_PROC_CONTINUE_INIT:
2423 rc = gss_svc_handle_init(req, gw);
2425 case PTLRPC_GSS_PROC_DATA:
2426 rc = gss_svc_handle_data(req, gw);
2428 case PTLRPC_GSS_PROC_DESTROY:
2429 rc = gss_svc_handle_destroy(req, gw);
2432 CERROR("unknown proc %u\n", gw->gw_proc);
2439 LASSERT (grctx->src_ctx);
2441 req->rq_auth_gss = 1;
2442 req->rq_auth_remote = grctx->src_ctx->gsc_remote;
2443 req->rq_auth_usr_mdt = grctx->src_ctx->gsc_usr_mds;
2444 req->rq_auth_usr_ost = grctx->src_ctx->gsc_usr_oss;
2445 req->rq_auth_usr_root = grctx->src_ctx->gsc_usr_root;
2446 req->rq_auth_uid = grctx->src_ctx->gsc_uid;
2447 req->rq_auth_mapped_uid = grctx->src_ctx->gsc_mapped_uid;
2449 case SECSVC_COMPLETE:
2452 gss_svc_reqctx_free(grctx);
2453 req->rq_svc_ctx = NULL;
2460 void gss_svc_invalidate_ctx(struct ptlrpc_svc_ctx *svc_ctx)
2462 struct gss_svc_reqctx *grctx;
2465 if (svc_ctx == NULL) {
2470 grctx = gss_svc_ctx2reqctx(svc_ctx);
2472 CWARN("gss svc invalidate ctx %p(%u)\n",
2473 grctx->src_ctx, grctx->src_ctx->gsc_uid);
2474 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2480 int gss_svc_payload(struct gss_svc_reqctx *grctx, int early,
2481 int msgsize, int privacy)
2483 /* we should treat early reply normally, but which is actually sharing
2484 * the same ctx with original request, so in this case we should
2485 * ignore the special ctx's special flags */
2486 if (early == 0 && gss_svc_reqctx_is_special(grctx))
2487 return grctx->src_reserve_len;
2489 return gss_mech_payload(NULL, msgsize, privacy);
2492 static int gss_svc_bulk_payload(struct gss_svc_ctx *gctx,
2493 struct sptlrpc_flavor *flvr,
2496 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
2499 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
2500 case SPTLRPC_BULK_SVC_NULL:
2502 case SPTLRPC_BULK_SVC_INTG:
2503 payload += gss_mech_payload(NULL, 0, 0);
2505 case SPTLRPC_BULK_SVC_PRIV:
2506 payload += gss_mech_payload(NULL, 0, 1);
2508 case SPTLRPC_BULK_SVC_AUTH:
2517 int gss_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
2519 struct gss_svc_reqctx *grctx;
2520 struct ptlrpc_reply_state *rs;
2521 int early, privacy, svc, bsd_off = 0;
2522 __u32 ibuflens[2], buflens[4];
2523 int ibufcnt = 0, bufcnt;
2524 int txtsize, wmsg_size, rs_size;
2527 LASSERT(msglen % 8 == 0);
2529 if (req->rq_pack_bulk && !req->rq_bulk_read && !req->rq_bulk_write) {
2530 CERROR("client request bulk sec on non-bulk rpc\n");
2534 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
2535 early = (req->rq_packed_final == 0);
2537 grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2538 if (!early && gss_svc_reqctx_is_special(grctx))
2541 privacy = (svc == SPTLRPC_SVC_PRIV);
2544 /* inner clear buffers */
2546 ibuflens[0] = msglen;
2548 if (req->rq_pack_bulk) {
2549 LASSERT(grctx->src_reqbsd);
2552 ibuflens[ibufcnt++] = gss_svc_bulk_payload(
2558 txtsize = lustre_msg_size_v2(ibufcnt, ibuflens);
2559 txtsize += GSS_MAX_CIPHER_BLOCK;
2561 /* wrapper buffer */
2563 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2564 buflens[1] = gss_svc_payload(grctx, early, txtsize, 1);
2567 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2568 buflens[1] = msglen;
2570 txtsize = buflens[0];
2571 if (svc == SPTLRPC_SVC_INTG)
2572 txtsize += buflens[1];
2574 if (req->rq_pack_bulk) {
2575 LASSERT(grctx->src_reqbsd);
2578 buflens[bufcnt] = gss_svc_bulk_payload(
2582 if (svc == SPTLRPC_SVC_INTG)
2583 txtsize += buflens[bufcnt];
2587 if ((!early && gss_svc_reqctx_is_special(grctx)) ||
2588 svc != SPTLRPC_SVC_NULL)
2589 buflens[bufcnt++] = gss_svc_payload(grctx, early,
2593 wmsg_size = lustre_msg_size_v2(bufcnt, buflens);
2595 rs_size = sizeof(*rs) + wmsg_size;
2596 rs = req->rq_reply_state;
2600 LASSERT(rs->rs_size >= rs_size);
2602 OBD_ALLOC_LARGE(rs, rs_size);
2606 rs->rs_size = rs_size;
2609 rs->rs_repbuf = (struct lustre_msg *) (rs + 1);
2610 rs->rs_repbuf_len = wmsg_size;
2612 /* initialize the buffer */
2614 lustre_init_msg_v2(rs->rs_repbuf, ibufcnt, ibuflens, NULL);
2615 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 0, msglen);
2617 lustre_init_msg_v2(rs->rs_repbuf, bufcnt, buflens, NULL);
2618 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2620 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 1, 0);
2624 grctx->src_repbsd = lustre_msg_buf(rs->rs_repbuf, bsd_off, 0);
2625 grctx->src_repbsd_size = lustre_msg_buflen(rs->rs_repbuf,
2629 gss_svc_reqctx_addref(grctx);
2630 rs->rs_svc_ctx = req->rq_svc_ctx;
2632 LASSERT(rs->rs_msg);
2633 req->rq_reply_state = rs;
2637 static int gss_svc_seal(struct ptlrpc_request *req,
2638 struct ptlrpc_reply_state *rs,
2639 struct gss_svc_reqctx *grctx)
2641 struct gss_svc_ctx *gctx = grctx->src_ctx;
2642 rawobj_t hdrobj, msgobj, token;
2643 struct gss_header *ghdr;
2646 __u32 buflens[2], major;
2650 /* get clear data length. note embedded lustre_msg might
2651 * have been shrunk */
2652 if (req->rq_replen != lustre_msg_buflen(rs->rs_repbuf, 0))
2653 msglen = lustre_shrink_msg(rs->rs_repbuf, 0, req->rq_replen, 1);
2655 msglen = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
2656 rs->rs_repbuf->lm_buflens);
2658 /* temporarily use tail of buffer to hold gss header data */
2659 LASSERT(msglen + PTLRPC_GSS_HEADER_SIZE <= rs->rs_repbuf_len);
2660 ghdr = (struct gss_header *) ((char *) rs->rs_repbuf +
2661 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE);
2662 ghdr->gh_version = PTLRPC_GSS_VERSION;
2663 ghdr->gh_sp = LUSTRE_SP_ANY;
2665 ghdr->gh_proc = PTLRPC_GSS_PROC_DATA;
2666 ghdr->gh_seq = grctx->src_wirectx.gw_seq;
2667 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
2668 ghdr->gh_handle.len = 0;
2669 if (req->rq_pack_bulk)
2670 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
2672 /* allocate temporary cipher buffer */
2673 token_buflen = gss_mech_payload(gctx->gsc_mechctx, msglen, 1);
2674 OBD_ALLOC_LARGE(token_buf, token_buflen);
2675 if (token_buf == NULL)
2678 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
2679 hdrobj.data = (__u8 *) ghdr;
2680 msgobj.len = msglen;
2681 msgobj.data = (__u8 *) rs->rs_repbuf;
2682 token.len = token_buflen;
2683 token.data = token_buf;
2685 major = lgss_wrap(gctx->gsc_mechctx, &hdrobj, &msgobj,
2686 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE, &token);
2687 if (major != GSS_S_COMPLETE) {
2688 CERROR("wrap message error: %08x\n", major);
2689 GOTO(out_free, rc = -EPERM);
2691 LASSERT(token.len <= token_buflen);
2693 /* we are about to override data at rs->rs_repbuf, nullify pointers
2694 * to which to catch further illegal usage. */
2695 if (req->rq_pack_bulk) {
2696 grctx->src_repbsd = NULL;
2697 grctx->src_repbsd_size = 0;
2700 /* now fill the actual wire data
2704 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2705 buflens[1] = token.len;
2707 rs->rs_repdata_len = lustre_msg_size_v2(2, buflens);
2708 LASSERT(rs->rs_repdata_len <= rs->rs_repbuf_len);
2710 lustre_init_msg_v2(rs->rs_repbuf, 2, buflens, NULL);
2711 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2713 memcpy(lustre_msg_buf(rs->rs_repbuf, 0, 0), ghdr,
2714 PTLRPC_GSS_HEADER_SIZE);
2715 memcpy(lustre_msg_buf(rs->rs_repbuf, 1, 0), token.data, token.len);
2718 if (req->rq_packed_final &&
2719 (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))
2720 req->rq_reply_off = gss_at_reply_off_priv;
2722 req->rq_reply_off = 0;
2724 /* to catch upper layer's further access */
2726 req->rq_repmsg = NULL;
2731 OBD_FREE_LARGE(token_buf, token_buflen);
2735 int gss_svc_authorize(struct ptlrpc_request *req)
2737 struct ptlrpc_reply_state *rs = req->rq_reply_state;
2738 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2739 struct gss_wire_ctx *gw = &grctx->src_wirectx;
2743 early = (req->rq_packed_final == 0);
2745 if (!early && gss_svc_reqctx_is_special(grctx)) {
2746 LASSERT(rs->rs_repdata_len != 0);
2748 req->rq_reply_off = gss_at_reply_off_integ;
2752 /* early reply could happen in many cases */
2754 gw->gw_proc != PTLRPC_GSS_PROC_DATA &&
2755 gw->gw_proc != PTLRPC_GSS_PROC_DESTROY) {
2756 CERROR("proc %d not support\n", gw->gw_proc);
2760 LASSERT(grctx->src_ctx);
2762 switch (gw->gw_svc) {
2763 case SPTLRPC_SVC_NULL:
2764 case SPTLRPC_SVC_AUTH:
2765 case SPTLRPC_SVC_INTG:
2766 rc = gss_svc_sign(req, rs, grctx, gw->gw_svc);
2768 case SPTLRPC_SVC_PRIV:
2769 rc = gss_svc_seal(req, rs, grctx);
2772 CERROR("Unknown service %d\n", gw->gw_svc);
2773 GOTO(out, rc = -EINVAL);
2781 void gss_svc_free_rs(struct ptlrpc_reply_state *rs)
2783 struct gss_svc_reqctx *grctx;
2785 LASSERT(rs->rs_svc_ctx);
2786 grctx = container_of(rs->rs_svc_ctx, struct gss_svc_reqctx, src_base);
2788 gss_svc_reqctx_decref(grctx);
2789 rs->rs_svc_ctx = NULL;
2791 if (!rs->rs_prealloc)
2792 OBD_FREE_LARGE(rs, rs->rs_size);
2795 void gss_svc_free_ctx(struct ptlrpc_svc_ctx *ctx)
2797 LASSERT(atomic_read(&ctx->sc_refcount) == 0);
2798 gss_svc_reqctx_free(gss_svc_ctx2reqctx(ctx));
2801 int gss_copy_rvc_cli_ctx(struct ptlrpc_cli_ctx *cli_ctx,
2802 struct ptlrpc_svc_ctx *svc_ctx)
2804 struct gss_cli_ctx *cli_gctx = ctx2gctx(cli_ctx);
2805 struct gss_svc_ctx *svc_gctx = gss_svc_ctx2gssctx(svc_ctx);
2806 struct gss_ctx *mechctx = NULL;
2809 LASSERT(svc_gctx && svc_gctx->gsc_mechctx);
2811 cli_gctx->gc_proc = PTLRPC_GSS_PROC_DATA;
2812 cli_gctx->gc_win = GSS_SEQ_WIN;
2814 /* The problem is the reverse ctx might get lost in some recovery
2815 * situations, and the same svc_ctx will be used to re-create it.
2816 * if there's callback be sentout before that, new reverse ctx start
2817 * with sequence 0 will lead to future callback rpc be treated as
2820 * each reverse root ctx will record its latest sequence number on its
2821 * buddy svcctx before be destroyed, so here we continue use it.
2823 atomic_set(&cli_gctx->gc_seq, svc_gctx->gsc_rvs_seq);
2825 if (gss_svc_upcall_dup_handle(&cli_gctx->gc_svc_handle, svc_gctx)) {
2826 CERROR("failed to dup svc handle\n");
2830 if (lgss_copy_reverse_context(svc_gctx->gsc_mechctx, &mechctx) !=
2832 CERROR("failed to copy mech context\n");
2833 goto err_svc_handle;
2836 if (rawobj_dup(&cli_gctx->gc_handle, &svc_gctx->gsc_rvs_hdl)) {
2837 CERROR("failed to dup reverse handle\n");
2841 cli_gctx->gc_mechctx = mechctx;
2842 gss_cli_ctx_uptodate(cli_gctx);
2847 lgss_delete_sec_context(&mechctx);
2849 rawobj_free(&cli_gctx->gc_svc_handle);
2854 static void gss_init_at_reply_offset(void)
2859 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2860 buflens[1] = lustre_msg_early_size();
2861 buflens[2] = gss_cli_payload(NULL, buflens[1], 0);
2862 gss_at_reply_off_integ = lustre_msg_size_v2(3, buflens);
2864 buflens[0] = lustre_msg_early_size();
2865 clearsize = lustre_msg_size_v2(1, buflens);
2866 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2867 buflens[1] = gss_cli_payload(NULL, clearsize, 0);
2868 buflens[2] = gss_cli_payload(NULL, clearsize, 1);
2869 gss_at_reply_off_priv = lustre_msg_size_v2(3, buflens);
2872 int __init sptlrpc_gss_init(void)
2876 rc = gss_init_lproc();
2880 rc = gss_init_cli_upcall();
2884 rc = gss_init_svc_upcall();
2886 goto out_cli_upcall;
2888 rc = init_null_module();
2890 goto out_svc_upcall;
2892 rc = init_kerberos_module();
2896 rc = init_sk_module();
2900 /* register policy after all other stuff be initialized, because it
2901 * might be in used immediately after the registration. */
2903 rc = gss_init_keyring();
2907 rc = gss_init_pipefs();
2911 gss_init_at_reply_offset();
2918 cleanup_sk_module();
2920 cleanup_kerberos_module();
2922 cleanup_null_module();
2924 gss_exit_svc_upcall();
2926 gss_exit_cli_upcall();
2932 static void __exit sptlrpc_gss_exit(void)
2936 cleanup_kerberos_module();
2937 gss_exit_svc_upcall();
2938 gss_exit_cli_upcall();
2942 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2943 MODULE_DESCRIPTION("GSS security policy for Lustre");
2944 MODULE_LICENSE("GPL");
2946 module_init(sptlrpc_gss_init);
2947 module_exit(sptlrpc_gss_exit);