2 * Modifications for Lustre
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Copyright (c) 2011, 2015, 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_net.h>
63 #include <lustre_import.h>
64 #include <lustre_sec.h>
67 #include "gss_internal.h"
70 #include <linux/crypto.h>
71 #include <linux/crc32.h>
74 * early reply have fixed size, respectively in privacy and integrity mode.
75 * so we calculate them only once.
77 static int gss_at_reply_off_integ;
78 static int gss_at_reply_off_priv;
81 static inline int msg_last_segidx(struct lustre_msg *msg)
83 LASSERT(msg->lm_bufcount > 0);
84 return msg->lm_bufcount - 1;
86 static inline int msg_last_seglen(struct lustre_msg *msg)
88 return msg->lm_buflens[msg_last_segidx(msg)];
91 /********************************************
93 ********************************************/
96 void gss_header_swabber(struct gss_header *ghdr)
98 __swab32s(&ghdr->gh_flags);
99 __swab32s(&ghdr->gh_proc);
100 __swab32s(&ghdr->gh_seq);
101 __swab32s(&ghdr->gh_svc);
102 __swab32s(&ghdr->gh_pad1);
103 __swab32s(&ghdr->gh_handle.len);
106 struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment,
109 struct gss_header *ghdr;
111 ghdr = lustre_msg_buf(msg, segment, sizeof(*ghdr));
116 gss_header_swabber(ghdr);
118 if (sizeof(*ghdr) + ghdr->gh_handle.len > msg->lm_buflens[segment]) {
119 CERROR("gss header has length %d, now %u received\n",
120 (int) sizeof(*ghdr) + ghdr->gh_handle.len,
121 msg->lm_buflens[segment]);
129 * payload should be obtained from mechanism. but currently since we
130 * only support kerberos, we could simply use fixed value.
133 * - krb5 checksum: 20
135 * for privacy mode, payload also include the cipher text which has the same
136 * size as plain text, plus possible confounder, padding both at maximum cipher
139 #define GSS_KRB5_INTEG_MAX_PAYLOAD (40)
142 int gss_mech_payload(struct gss_ctx *mechctx, int msgsize, int privacy)
145 return GSS_KRB5_INTEG_MAX_PAYLOAD + 16 + 16 + 16 + msgsize;
147 return GSS_KRB5_INTEG_MAX_PAYLOAD;
151 * return signature size, otherwise < 0 to indicate error
153 static int gss_sign_msg(struct lustre_msg *msg,
154 struct gss_ctx *mechctx,
155 enum lustre_sec_part sp,
156 __u32 flags, __u32 proc, __u32 seq, __u32 svc,
159 struct gss_header *ghdr;
160 rawobj_t text[4], mic;
161 int textcnt, max_textcnt, mic_idx;
164 LASSERT(msg->lm_bufcount >= 2);
167 LASSERT(msg->lm_buflens[0] >=
168 sizeof(*ghdr) + (handle ? handle->len : 0));
169 ghdr = lustre_msg_buf(msg, 0, 0);
171 ghdr->gh_version = PTLRPC_GSS_VERSION;
172 ghdr->gh_sp = (__u8) sp;
173 ghdr->gh_flags = flags;
174 ghdr->gh_proc = proc;
178 /* fill in a fake one */
179 ghdr->gh_handle.len = 0;
181 ghdr->gh_handle.len = handle->len;
182 memcpy(ghdr->gh_handle.data, handle->data, handle->len);
185 /* no actual signature for null mode */
186 if (svc == SPTLRPC_SVC_NULL)
187 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
190 mic_idx = msg_last_segidx(msg);
191 max_textcnt = (svc == SPTLRPC_SVC_AUTH) ? 1 : mic_idx;
193 for (textcnt = 0; textcnt < max_textcnt; textcnt++) {
194 text[textcnt].len = msg->lm_buflens[textcnt];
195 text[textcnt].data = lustre_msg_buf(msg, textcnt, 0);
198 mic.len = msg->lm_buflens[mic_idx];
199 mic.data = lustre_msg_buf(msg, mic_idx, 0);
201 major = lgss_get_mic(mechctx, textcnt, text, 0, NULL, &mic);
202 if (major != GSS_S_COMPLETE) {
203 CERROR("fail to generate MIC: %08x\n", major);
206 LASSERT(mic.len <= msg->lm_buflens[mic_idx]);
208 return lustre_shrink_msg(msg, mic_idx, mic.len, 0);
215 __u32 gss_verify_msg(struct lustre_msg *msg,
216 struct gss_ctx *mechctx,
219 rawobj_t text[4], mic;
220 int textcnt, max_textcnt;
224 LASSERT(msg->lm_bufcount >= 2);
226 if (svc == SPTLRPC_SVC_NULL)
227 return GSS_S_COMPLETE;
229 mic_idx = msg_last_segidx(msg);
230 max_textcnt = (svc == SPTLRPC_SVC_AUTH) ? 1 : mic_idx;
232 for (textcnt = 0; textcnt < max_textcnt; textcnt++) {
233 text[textcnt].len = msg->lm_buflens[textcnt];
234 text[textcnt].data = lustre_msg_buf(msg, textcnt, 0);
237 mic.len = msg->lm_buflens[mic_idx];
238 mic.data = lustre_msg_buf(msg, mic_idx, 0);
240 major = lgss_verify_mic(mechctx, textcnt, text, 0, NULL, &mic);
241 if (major != GSS_S_COMPLETE)
242 CERROR("mic verify error: %08x\n", major);
248 * return gss error code
251 __u32 gss_unseal_msg(struct gss_ctx *mechctx,
252 struct lustre_msg *msgbuf,
253 int *msg_len, int msgbuf_len)
255 rawobj_t clear_obj, hdrobj, token;
261 if (msgbuf->lm_bufcount != 2) {
262 CERROR("invalid bufcount %d\n", msgbuf->lm_bufcount);
263 RETURN(GSS_S_FAILURE);
266 /* allocate a temporary clear text buffer, same sized as token,
267 * we assume the final clear text size <= token size */
268 clear_buflen = lustre_msg_buflen(msgbuf, 1);
269 OBD_ALLOC_LARGE(clear_buf, clear_buflen);
271 RETURN(GSS_S_FAILURE);
274 hdrobj.len = lustre_msg_buflen(msgbuf, 0);
275 hdrobj.data = lustre_msg_buf(msgbuf, 0, 0);
276 token.len = lustre_msg_buflen(msgbuf, 1);
277 token.data = lustre_msg_buf(msgbuf, 1, 0);
278 clear_obj.len = clear_buflen;
279 clear_obj.data = clear_buf;
281 major = lgss_unwrap(mechctx, &hdrobj, &token, &clear_obj);
282 if (major != GSS_S_COMPLETE) {
283 CERROR("unwrap message error: %08x\n", major);
284 GOTO(out_free, major = GSS_S_FAILURE);
286 LASSERT(clear_obj.len <= clear_buflen);
287 LASSERT(clear_obj.len <= msgbuf_len);
289 /* now the decrypted message */
290 memcpy(msgbuf, clear_obj.data, clear_obj.len);
291 *msg_len = clear_obj.len;
293 major = GSS_S_COMPLETE;
295 OBD_FREE_LARGE(clear_buf, clear_buflen);
299 /********************************************
300 * gss client context manipulation helpers *
301 ********************************************/
303 int cli_ctx_expire(struct ptlrpc_cli_ctx *ctx)
305 LASSERT(atomic_read(&ctx->cc_refcount));
307 if (!test_and_set_bit(PTLRPC_CTX_DEAD_BIT, &ctx->cc_flags)) {
308 if (!ctx->cc_early_expire)
309 clear_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
311 CDEBUG(D_SEC, "ctx %p(%u->%s) get expired: %lld(%+llds)\n",
312 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
314 ctx->cc_expire == 0 ? 0 :
315 ctx->cc_expire - ktime_get_real_seconds());
317 sptlrpc_cli_ctx_wakeup(ctx);
325 * return 1 if the context is dead.
327 int cli_ctx_check_death(struct ptlrpc_cli_ctx *ctx)
329 if (unlikely(cli_ctx_is_dead(ctx)))
332 /* expire is 0 means never expire. a newly created gss context
333 * which during upcall may has 0 expiration */
334 if (ctx->cc_expire == 0)
337 /* check real expiration */
338 if (ctx->cc_expire > ktime_get_real_seconds())
345 void gss_cli_ctx_uptodate(struct gss_cli_ctx *gctx)
347 struct ptlrpc_cli_ctx *ctx = &gctx->gc_base;
350 if (lgss_inquire_context(gctx->gc_mechctx, &ctx_expiry)) {
351 CERROR("ctx %p(%u): unable to inquire, expire it now\n",
352 gctx, ctx->cc_vcred.vc_uid);
353 ctx_expiry = 1; /* make it expired now */
356 ctx->cc_expire = gss_round_ctx_expiry(ctx_expiry,
357 ctx->cc_sec->ps_flvr.sf_flags);
359 /* At this point this ctx might have been marked as dead by
360 * someone else, in which case nobody will make further use
361 * of it. we don't care, and mark it UPTODATE will help
362 * destroying server side context when it be destroyed. */
363 set_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
365 if (sec_is_reverse(ctx->cc_sec)) {
366 CDEBUG(D_SEC, "server installed reverse ctx %p idx %#llx, expiry %lld(%+llds)\n",
367 ctx, gss_handle_to_u64(&gctx->gc_handle),
369 ctx->cc_expire - ktime_get_real_seconds());
371 CDEBUG(D_SEC, "client refreshed ctx %p idx %#llx (%u->%s), expiry %lld(%+llds)\n",
372 ctx, gss_handle_to_u64(&gctx->gc_handle),
373 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
375 ctx->cc_expire - ktime_get_real_seconds());
377 /* install reverse svc ctx for root context */
378 if (ctx->cc_vcred.vc_uid == 0)
379 gss_sec_install_rctx(ctx->cc_sec->ps_import,
383 sptlrpc_cli_ctx_wakeup(ctx);
386 static void gss_cli_ctx_finalize(struct gss_cli_ctx *gctx)
388 LASSERT(gctx->gc_base.cc_sec);
390 if (gctx->gc_mechctx) {
391 lgss_delete_sec_context(&gctx->gc_mechctx);
392 gctx->gc_mechctx = NULL;
395 if (!rawobj_empty(&gctx->gc_svc_handle)) {
396 /* forward ctx: mark buddy reverse svcctx soon-expire. */
397 if (!sec_is_reverse(gctx->gc_base.cc_sec) &&
398 !rawobj_empty(&gctx->gc_svc_handle))
399 gss_svc_upcall_expire_rvs_ctx(&gctx->gc_svc_handle);
401 rawobj_free(&gctx->gc_svc_handle);
404 rawobj_free(&gctx->gc_handle);
408 * Based on sequence number algorithm as specified in RFC 2203.
410 * Modified for our own problem: arriving request has valid sequence number,
411 * but unwrapping request might cost a long time, after that its sequence
412 * are not valid anymore (fall behind the window). It rarely happen, mostly
413 * under extreme load.
415 * Note we should not check sequence before verifying the integrity of incoming
416 * request, because just one attacking request with high sequence number might
417 * cause all following requests be dropped.
419 * So here we use a multi-phase approach: prepare 2 sequence windows,
420 * "main window" for normal sequence and "back window" for fall behind sequence.
421 * and 3-phase checking mechanism:
422 * 0 - before integrity verification, perform an initial sequence checking in
423 * main window, which only tries and doesn't actually set any bits. if the
424 * sequence is high above the window or fits in the window and the bit
425 * is 0, then accept and proceed to integrity verification. otherwise
426 * reject this sequence.
427 * 1 - after integrity verification, check in main window again. if this
428 * sequence is high above the window or fits in the window and the bit
429 * is 0, then set the bit and accept; if it fits in the window but bit
430 * already set, then reject; if it falls behind the window, then proceed
432 * 2 - check in back window. if it is high above the window or fits in the
433 * window and the bit is 0, then set the bit and accept. otherwise reject.
435 * \return 1: looks like a replay
437 * \return -1: is a replay
439 * Note phase 0 is necessary, because otherwise replay attacking request of
440 * sequence which between the 2 windows can't be detected.
442 * This mechanism can't totally solve the problem, but could help reduce the
443 * number of valid requests be dropped.
446 int gss_do_check_seq(unsigned long *window, __u32 win_size, __u32 *max_seq,
447 __u32 seq_num, int phase)
449 LASSERT(phase >= 0 && phase <= 2);
451 if (seq_num > *max_seq) {
453 * 1. high above the window
458 if (seq_num >= *max_seq + win_size) {
459 memset(window, 0, win_size / 8);
462 while(*max_seq < seq_num) {
464 __clear_bit((*max_seq) % win_size, window);
467 __set_bit(seq_num % win_size, window);
468 } else if (seq_num + win_size <= *max_seq) {
470 * 2. low behind the window
472 if (phase == 0 || phase == 2)
475 CWARN("seq %u is %u behind (size %d), check backup window\n",
476 seq_num, *max_seq - win_size - seq_num, win_size);
480 * 3. fit into the window
484 if (test_bit(seq_num % win_size, window))
489 if (__test_and_set_bit(seq_num % win_size, window))
498 CERROR("seq %u (%s %s window) is a replay: max %u, winsize %d\n",
500 seq_num + win_size > *max_seq ? "in" : "behind",
501 phase == 2 ? "backup " : "main",
507 * Based on sequence number algorithm as specified in RFC 2203.
509 * if @set == 0: initial check, don't set any bit in window
510 * if @sec == 1: final check, set bit in window
512 int gss_check_seq_num(struct gss_svc_seq_data *ssd, __u32 seq_num, int set)
516 spin_lock(&ssd->ssd_lock);
522 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
523 &ssd->ssd_max_main, seq_num, 0);
525 gss_stat_oos_record_svc(0, 1);
528 * phase 1 checking main window
530 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
531 &ssd->ssd_max_main, seq_num, 1);
534 gss_stat_oos_record_svc(1, 1);
540 * phase 2 checking back window
542 rc = gss_do_check_seq(ssd->ssd_win_back, GSS_SEQ_WIN_BACK,
543 &ssd->ssd_max_back, seq_num, 2);
545 gss_stat_oos_record_svc(2, 1);
547 gss_stat_oos_record_svc(2, 0);
550 spin_unlock(&ssd->ssd_lock);
554 /***************************************
556 ***************************************/
558 static inline int gss_cli_payload(struct ptlrpc_cli_ctx *ctx,
559 int msgsize, int privacy)
561 return gss_mech_payload(NULL, msgsize, privacy);
564 static int gss_cli_bulk_payload(struct ptlrpc_cli_ctx *ctx,
565 struct sptlrpc_flavor *flvr,
568 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
570 LASSERT(SPTLRPC_FLVR_BULK_TYPE(flvr->sf_rpc) == SPTLRPC_BULK_DEFAULT);
572 if ((!reply && !read) || (reply && read)) {
573 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
574 case SPTLRPC_BULK_SVC_NULL:
576 case SPTLRPC_BULK_SVC_INTG:
577 payload += gss_cli_payload(ctx, 0, 0);
579 case SPTLRPC_BULK_SVC_PRIV:
580 payload += gss_cli_payload(ctx, 0, 1);
582 case SPTLRPC_BULK_SVC_AUTH:
591 int gss_cli_ctx_match(struct ptlrpc_cli_ctx *ctx, struct vfs_cred *vcred)
593 return (ctx->cc_vcred.vc_uid == vcred->vc_uid);
596 void gss_cli_ctx_flags2str(unsigned long flags, char *buf, int bufsize)
600 if (flags & PTLRPC_CTX_NEW)
601 strlcat(buf, "new,", bufsize);
602 if (flags & PTLRPC_CTX_UPTODATE)
603 strlcat(buf, "uptodate,", bufsize);
604 if (flags & PTLRPC_CTX_DEAD)
605 strlcat(buf, "dead,", bufsize);
606 if (flags & PTLRPC_CTX_ERROR)
607 strlcat(buf, "error,", bufsize);
608 if (flags & PTLRPC_CTX_CACHED)
609 strlcat(buf, "cached,", bufsize);
610 if (flags & PTLRPC_CTX_ETERNAL)
611 strlcat(buf, "eternal,", bufsize);
613 strlcat(buf, "-,", bufsize);
616 int gss_cli_ctx_sign(struct ptlrpc_cli_ctx *ctx,
617 struct ptlrpc_request *req)
619 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
620 __u32 flags = 0, seq, svc;
624 LASSERT(req->rq_reqbuf);
625 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
626 LASSERT(req->rq_cli_ctx == ctx);
628 /* nothing to do for context negotiation RPCs */
629 if (req->rq_ctx_init)
632 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
633 if (req->rq_pack_bulk)
634 flags |= LUSTRE_GSS_PACK_BULK;
635 if (req->rq_pack_udesc)
636 flags |= LUSTRE_GSS_PACK_USER;
639 seq = atomic_inc_return(&gctx->gc_seq);
641 rc = gss_sign_msg(req->rq_reqbuf, gctx->gc_mechctx,
642 ctx->cc_sec->ps_part,
643 flags, gctx->gc_proc, seq, svc,
648 /* gss_sign_msg() msg might take long time to finish, in which period
649 * more rpcs could be wrapped up and sent out. if we found too many
650 * of them we should repack this rpc, because sent it too late might
651 * lead to the sequence number fall behind the window on server and
652 * be dropped. also applies to gss_cli_ctx_seal().
654 * Note: null mode doesn't check sequence number. */
655 if (svc != SPTLRPC_SVC_NULL &&
656 atomic_read(&gctx->gc_seq) - seq > GSS_SEQ_REPACK_THRESHOLD) {
657 int behind = atomic_read(&gctx->gc_seq) - seq;
659 gss_stat_oos_record_cli(behind);
660 CWARN("req %p: %u behind, retry signing\n", req, behind);
664 req->rq_reqdata_len = rc;
669 int gss_cli_ctx_handle_err_notify(struct ptlrpc_cli_ctx *ctx,
670 struct ptlrpc_request *req,
671 struct gss_header *ghdr)
673 struct gss_err_header *errhdr;
676 LASSERT(ghdr->gh_proc == PTLRPC_GSS_PROC_ERR);
678 errhdr = (struct gss_err_header *) ghdr;
680 CWARN("req x%llu/t%llu, ctx %p idx %#llx(%u->%s): "
681 "%sserver respond (%08x/%08x)\n",
682 req->rq_xid, req->rq_transno, ctx,
683 gss_handle_to_u64(&ctx2gctx(ctx)->gc_handle),
684 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
685 sec_is_reverse(ctx->cc_sec) ? "reverse" : "",
686 errhdr->gh_major, errhdr->gh_minor);
688 /* context fini rpc, let it failed */
689 if (req->rq_ctx_fini) {
690 CWARN("context fini rpc failed\n");
694 /* reverse sec, just return error, don't expire this ctx because it's
695 * crucial to callback rpcs. note if the callback rpc failed because
696 * of bit flip during network transfer, the client will be evicted
697 * directly. so more gracefully we probably want let it retry for
698 * number of times. */
699 if (sec_is_reverse(ctx->cc_sec))
702 if (errhdr->gh_major != GSS_S_NO_CONTEXT &&
703 errhdr->gh_major != GSS_S_BAD_SIG)
706 /* server return NO_CONTEXT might be caused by context expire
707 * or server reboot/failover. we try to refresh a new ctx which
708 * be transparent to upper layer.
710 * In some cases, our gss handle is possible to be incidentally
711 * identical to another handle since the handle itself is not
712 * fully random. In krb5 case, the GSS_S_BAD_SIG will be
713 * returned, maybe other gss error for other mechanism.
715 * if we add new mechanism, make sure the correct error are
716 * returned in this case. */
717 CWARN("%s: server might lost the context, retrying\n",
718 errhdr->gh_major == GSS_S_NO_CONTEXT ? "NO_CONTEXT" : "BAD_SIG");
720 sptlrpc_cli_ctx_expire(ctx);
722 /* we need replace the ctx right here, otherwise during
723 * resent we'll hit the logic in sptlrpc_req_refresh_ctx()
724 * which keep the ctx with RESEND flag, thus we'll never
725 * get rid of this ctx. */
726 rc = sptlrpc_req_replace_dead_ctx(req);
733 int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
734 struct ptlrpc_request *req)
736 struct gss_cli_ctx *gctx;
737 struct gss_header *ghdr, *reqhdr;
738 struct lustre_msg *msg = req->rq_repdata;
740 int pack_bulk, swabbed, rc = 0;
743 LASSERT(req->rq_cli_ctx == ctx);
746 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
748 /* special case for context negotiation, rq_repmsg/rq_replen actually
749 * are not used currently. but early reply always be treated normally */
750 if (req->rq_ctx_init && !req->rq_early) {
751 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
752 req->rq_replen = msg->lm_buflens[1];
756 if (msg->lm_bufcount < 2 || msg->lm_bufcount > 4) {
757 CERROR("unexpected bufcount %u\n", msg->lm_bufcount);
761 swabbed = req_capsule_rep_need_swab(&req->rq_pill);
763 ghdr = gss_swab_header(msg, 0, swabbed);
765 CERROR("can't decode gss header\n");
770 reqhdr = lustre_msg_buf(msg, 0, sizeof(*reqhdr));
773 if (ghdr->gh_version != reqhdr->gh_version) {
774 CERROR("gss version %u mismatch, expect %u\n",
775 ghdr->gh_version, reqhdr->gh_version);
779 switch (ghdr->gh_proc) {
780 case PTLRPC_GSS_PROC_DATA:
781 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
783 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
784 CERROR("%s bulk flag in reply\n",
785 req->rq_pack_bulk ? "missing" : "unexpected");
789 if (ghdr->gh_seq != reqhdr->gh_seq) {
790 CERROR("seqnum %u mismatch, expect %u\n",
791 ghdr->gh_seq, reqhdr->gh_seq);
795 if (ghdr->gh_svc != reqhdr->gh_svc) {
796 CERROR("svc %u mismatch, expect %u\n",
797 ghdr->gh_svc, reqhdr->gh_svc);
802 gss_header_swabber(ghdr);
804 major = gss_verify_msg(msg, gctx->gc_mechctx, reqhdr->gh_svc);
805 if (major != GSS_S_COMPLETE) {
806 CERROR("failed to verify reply: %x\n", major);
810 if (req->rq_early && reqhdr->gh_svc == SPTLRPC_SVC_NULL) {
813 cksum = crc32_le(!(__u32) 0,
814 lustre_msg_buf(msg, 1, 0),
815 lustre_msg_buflen(msg, 1));
816 if (cksum != msg->lm_cksum) {
817 CWARN("early reply checksum mismatch: "
818 "%08x != %08x\n", cksum, msg->lm_cksum);
824 /* bulk checksum is right after the lustre msg */
825 if (msg->lm_bufcount < 3) {
826 CERROR("Invalid reply bufcount %u\n",
831 rc = bulk_sec_desc_unpack(msg, 2, swabbed);
833 CERROR("unpack bulk desc: %d\n", rc);
838 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
839 req->rq_replen = msg->lm_buflens[1];
841 case PTLRPC_GSS_PROC_ERR:
843 CERROR("server return error with early reply\n");
846 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
850 CERROR("unknown gss proc %d\n", ghdr->gh_proc);
857 int gss_cli_ctx_seal(struct ptlrpc_cli_ctx *ctx,
858 struct ptlrpc_request *req)
860 struct gss_cli_ctx *gctx;
861 rawobj_t hdrobj, msgobj, token;
862 struct gss_header *ghdr;
863 __u32 buflens[2], major;
867 LASSERT(req->rq_clrbuf);
868 LASSERT(req->rq_cli_ctx == ctx);
869 LASSERT(req->rq_reqlen);
871 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
873 /* final clear data length */
874 req->rq_clrdata_len = lustre_msg_size_v2(req->rq_clrbuf->lm_bufcount,
875 req->rq_clrbuf->lm_buflens);
877 /* calculate wire data length */
878 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
879 buflens[1] = gss_cli_payload(&gctx->gc_base, req->rq_clrdata_len, 1);
880 wiresize = lustre_msg_size_v2(2, buflens);
882 /* allocate wire buffer */
885 LASSERT(req->rq_reqbuf);
886 LASSERT(req->rq_reqbuf != req->rq_clrbuf);
887 LASSERT(req->rq_reqbuf_len >= wiresize);
889 OBD_ALLOC_LARGE(req->rq_reqbuf, wiresize);
892 req->rq_reqbuf_len = wiresize;
895 lustre_init_msg_v2(req->rq_reqbuf, 2, buflens, NULL);
896 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
899 ghdr = lustre_msg_buf(req->rq_reqbuf, 0, 0);
900 ghdr->gh_version = PTLRPC_GSS_VERSION;
901 ghdr->gh_sp = (__u8) ctx->cc_sec->ps_part;
903 ghdr->gh_proc = gctx->gc_proc;
904 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
905 ghdr->gh_handle.len = gctx->gc_handle.len;
906 memcpy(ghdr->gh_handle.data, gctx->gc_handle.data, gctx->gc_handle.len);
907 if (req->rq_pack_bulk)
908 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
909 if (req->rq_pack_udesc)
910 ghdr->gh_flags |= LUSTRE_GSS_PACK_USER;
913 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
916 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
917 hdrobj.data = (__u8 *) ghdr;
918 msgobj.len = req->rq_clrdata_len;
919 msgobj.data = (__u8 *) req->rq_clrbuf;
920 token.len = lustre_msg_buflen(req->rq_reqbuf, 1);
921 token.data = lustre_msg_buf(req->rq_reqbuf, 1, 0);
923 major = lgss_wrap(gctx->gc_mechctx, &hdrobj, &msgobj,
924 req->rq_clrbuf_len, &token);
925 if (major != GSS_S_COMPLETE) {
926 CERROR("priv: wrap message error: %08x\n", major);
927 GOTO(err_free, rc = -EPERM);
929 LASSERT(token.len <= buflens[1]);
931 /* see explain in gss_cli_ctx_sign() */
932 if (unlikely(atomic_read(&gctx->gc_seq) - ghdr->gh_seq >
933 GSS_SEQ_REPACK_THRESHOLD)) {
934 int behind = atomic_read(&gctx->gc_seq) - ghdr->gh_seq;
936 gss_stat_oos_record_cli(behind);
937 CWARN("req %p: %u behind, retry sealing\n", req, behind);
939 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
943 /* now set the final wire data length */
944 req->rq_reqdata_len = lustre_shrink_msg(req->rq_reqbuf, 1, token.len,0);
949 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
950 req->rq_reqbuf = NULL;
951 req->rq_reqbuf_len = 0;
956 int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
957 struct ptlrpc_request *req)
959 struct gss_cli_ctx *gctx;
960 struct gss_header *ghdr;
961 struct lustre_msg *msg = req->rq_repdata;
962 int msglen, pack_bulk, swabbed, rc;
966 LASSERT(req->rq_cli_ctx == ctx);
967 LASSERT(req->rq_ctx_init == 0);
970 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
971 swabbed = req_capsule_rep_need_swab(&req->rq_pill);
973 ghdr = gss_swab_header(msg, 0, swabbed);
975 CERROR("can't decode gss header\n");
980 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
981 CERROR("gss version %u mismatch, expect %u\n",
982 ghdr->gh_version, PTLRPC_GSS_VERSION);
986 switch (ghdr->gh_proc) {
987 case PTLRPC_GSS_PROC_DATA:
988 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
990 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
991 CERROR("%s bulk flag in reply\n",
992 req->rq_pack_bulk ? "missing" : "unexpected");
997 gss_header_swabber(ghdr);
999 /* use rq_repdata_len as buffer size, which assume unseal
1000 * doesn't need extra memory space. for precise control, we'd
1001 * better calculate out actual buffer size as
1002 * (repbuf_len - offset - repdata_len) */
1003 major = gss_unseal_msg(gctx->gc_mechctx, msg,
1004 &msglen, req->rq_repdata_len);
1005 if (major != GSS_S_COMPLETE) {
1006 CERROR("failed to unwrap reply: %x\n", major);
1011 swabbed = __lustre_unpack_msg(msg, msglen);
1013 CERROR("Failed to unpack after decryption\n");
1017 if (msg->lm_bufcount < 1) {
1018 CERROR("Invalid reply buffer: empty\n");
1023 if (msg->lm_bufcount < 2) {
1024 CERROR("bufcount %u: missing bulk sec desc\n",
1029 /* bulk checksum is the last segment */
1030 if (bulk_sec_desc_unpack(msg, msg->lm_bufcount - 1,
1035 req->rq_repmsg = lustre_msg_buf(msg, 0, 0);
1036 req->rq_replen = msg->lm_buflens[0];
1040 case PTLRPC_GSS_PROC_ERR:
1041 if (req->rq_early) {
1042 CERROR("server return error with early reply\n");
1045 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
1049 CERROR("unexpected proc %d\n", ghdr->gh_proc);
1056 /*********************************************
1057 * reverse context installation *
1058 *********************************************/
1061 int gss_install_rvs_svc_ctx(struct obd_import *imp,
1062 struct gss_sec *gsec,
1063 struct gss_cli_ctx *gctx)
1065 return gss_svc_upcall_install_rvs_ctx(imp, gsec, gctx);
1068 /*********************************************
1069 * GSS security APIs *
1070 *********************************************/
1071 int gss_sec_create_common(struct gss_sec *gsec,
1072 struct ptlrpc_sec_policy *policy,
1073 struct obd_import *imp,
1074 struct ptlrpc_svc_ctx *svcctx,
1075 struct sptlrpc_flavor *sf)
1077 struct ptlrpc_sec *sec;
1080 LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_GSS);
1082 gsec->gs_mech = lgss_subflavor_to_mech(
1083 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1084 if (!gsec->gs_mech) {
1085 CERROR("gss backend 0x%x not found\n",
1086 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1090 spin_lock_init(&gsec->gs_lock);
1091 gsec->gs_rvs_hdl = 0ULL;
1093 /* initialize upper ptlrpc_sec */
1094 sec = &gsec->gs_base;
1095 sec->ps_policy = policy;
1096 atomic_set(&sec->ps_refcount, 0);
1097 atomic_set(&sec->ps_nctx, 0);
1098 sec->ps_id = sptlrpc_get_next_secid();
1100 sec->ps_import = class_import_get(imp);
1101 spin_lock_init(&sec->ps_lock);
1102 INIT_LIST_HEAD(&sec->ps_gc_list);
1103 sec->ps_sepol_mtime = ktime_set(0, 0);
1104 sec->ps_sepol_checknext = ktime_set(0, 0);
1105 sec->ps_sepol[0] = '\0';
1108 sec->ps_gc_interval = GSS_GC_INTERVAL;
1110 LASSERT(sec_is_reverse(sec));
1112 /* never do gc on reverse sec */
1113 sec->ps_gc_interval = 0;
1116 if (SPTLRPC_FLVR_BULK_SVC(sec->ps_flvr.sf_rpc) == SPTLRPC_BULK_SVC_PRIV)
1117 sptlrpc_enc_pool_add_user();
1119 CDEBUG(D_SEC, "create %s%s@%p\n", (svcctx ? "reverse " : ""),
1120 policy->sp_name, gsec);
1124 void gss_sec_destroy_common(struct gss_sec *gsec)
1126 struct ptlrpc_sec *sec = &gsec->gs_base;
1129 LASSERT(sec->ps_import);
1130 LASSERT(atomic_read(&sec->ps_refcount) == 0);
1131 LASSERT(atomic_read(&sec->ps_nctx) == 0);
1133 if (gsec->gs_mech) {
1134 lgss_mech_put(gsec->gs_mech);
1135 gsec->gs_mech = NULL;
1138 class_import_put(sec->ps_import);
1142 void gss_sec_kill(struct ptlrpc_sec *sec)
1147 int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
1148 struct ptlrpc_cli_ctx *ctx,
1149 struct ptlrpc_ctx_ops *ctxops,
1150 struct vfs_cred *vcred)
1152 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1155 atomic_set(&gctx->gc_seq, 0);
1157 INIT_HLIST_NODE(&ctx->cc_cache);
1158 atomic_set(&ctx->cc_refcount, 0);
1160 ctx->cc_ops = ctxops;
1162 ctx->cc_flags = PTLRPC_CTX_NEW;
1163 ctx->cc_vcred = *vcred;
1164 spin_lock_init(&ctx->cc_lock);
1165 INIT_LIST_HEAD(&ctx->cc_req_list);
1166 INIT_LIST_HEAD(&ctx->cc_gc_chain);
1168 /* take a ref on belonging sec, balanced in ctx destroying */
1169 atomic_inc(&sec->ps_refcount);
1170 /* statistic only */
1171 atomic_inc(&sec->ps_nctx);
1173 CDEBUG(D_SEC, "%s@%p: create ctx %p(%u->%s)\n",
1174 sec->ps_policy->sp_name, ctx->cc_sec,
1175 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1181 * 1: the context has been taken care of by someone else
1182 * 0: proceed to really destroy the context locally
1184 int gss_cli_ctx_fini_common(struct ptlrpc_sec *sec,
1185 struct ptlrpc_cli_ctx *ctx)
1187 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1189 LASSERT(atomic_read(&sec->ps_nctx) > 0);
1190 LASSERT(atomic_read(&ctx->cc_refcount) == 0);
1191 LASSERT(ctx->cc_sec == sec);
1194 * remove UPTODATE flag of reverse ctx thus we won't send fini rpc,
1195 * this is to avoid potential problems of client side reverse svc ctx
1196 * be mis-destroyed in various recovery senarios. anyway client can
1197 * manage its reverse ctx well by associating it with its buddy ctx.
1199 if (sec_is_reverse(sec))
1200 ctx->cc_flags &= ~PTLRPC_CTX_UPTODATE;
1202 if (gctx->gc_mechctx) {
1203 /* the final context fini rpc will use this ctx too, and it's
1204 * asynchronous which finished by request_out_callback(). so
1205 * we add refcount, whoever drop finally drop the refcount to
1206 * 0 should responsible for the rest of destroy. */
1207 atomic_inc(&ctx->cc_refcount);
1209 gss_do_ctx_fini_rpc(gctx);
1210 gss_cli_ctx_finalize(gctx);
1212 if (!atomic_dec_and_test(&ctx->cc_refcount))
1216 if (sec_is_reverse(sec))
1217 CDEBUG(D_SEC, "reverse sec %p: destroy ctx %p\n",
1220 CDEBUG(D_SEC, "%s@%p: destroy ctx %p(%u->%s)\n",
1221 sec->ps_policy->sp_name, ctx->cc_sec,
1222 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1228 int gss_alloc_reqbuf_intg(struct ptlrpc_sec *sec,
1229 struct ptlrpc_request *req,
1230 int svc, int msgsize)
1232 int bufsize, txtsize;
1238 * on-wire data layout:
1241 * - user descriptor (optional)
1242 * - bulk sec descriptor (optional)
1243 * - signature (optional)
1244 * - svc == NULL: NULL
1245 * - svc == AUTH: signature of gss header
1246 * - svc == INTG: signature of all above
1248 * if this is context negotiation, reserver fixed space
1249 * at the last (signature) segment regardless of svc mode.
1252 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1253 txtsize = buflens[0];
1255 buflens[1] = msgsize;
1256 if (svc == SPTLRPC_SVC_INTG)
1257 txtsize += buflens[1];
1259 if (req->rq_pack_udesc) {
1260 buflens[bufcnt] = sptlrpc_current_user_desc_size();
1261 if (svc == SPTLRPC_SVC_INTG)
1262 txtsize += buflens[bufcnt];
1266 if (req->rq_pack_bulk) {
1267 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1269 0, req->rq_bulk_read);
1270 if (svc == SPTLRPC_SVC_INTG)
1271 txtsize += buflens[bufcnt];
1275 if (req->rq_ctx_init)
1276 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1277 else if (svc != SPTLRPC_SVC_NULL)
1278 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1280 bufsize = lustre_msg_size_v2(bufcnt, buflens);
1282 if (!req->rq_reqbuf) {
1283 bufsize = size_roundup_power2(bufsize);
1285 OBD_ALLOC_LARGE(req->rq_reqbuf, bufsize);
1286 if (!req->rq_reqbuf)
1289 req->rq_reqbuf_len = bufsize;
1291 LASSERT(req->rq_pool);
1292 LASSERT(req->rq_reqbuf_len >= bufsize);
1293 memset(req->rq_reqbuf, 0, bufsize);
1296 lustre_init_msg_v2(req->rq_reqbuf, bufcnt, buflens, NULL);
1297 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
1299 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, msgsize);
1300 LASSERT(req->rq_reqmsg);
1302 /* pack user desc here, later we might leave current user's process */
1303 if (req->rq_pack_udesc)
1304 sptlrpc_pack_user_desc(req->rq_reqbuf, 2);
1310 int gss_alloc_reqbuf_priv(struct ptlrpc_sec *sec,
1311 struct ptlrpc_request *req,
1314 __u32 ibuflens[3], wbuflens[2];
1316 int clearsize, wiresize;
1319 LASSERT(req->rq_clrbuf == NULL);
1320 LASSERT(req->rq_clrbuf_len == 0);
1322 /* Inner (clear) buffers
1324 * - user descriptor (optional)
1325 * - bulk checksum (optional)
1328 ibuflens[0] = msgsize;
1330 if (req->rq_pack_udesc)
1331 ibuflens[ibufcnt++] = sptlrpc_current_user_desc_size();
1332 if (req->rq_pack_bulk)
1333 ibuflens[ibufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1337 clearsize = lustre_msg_size_v2(ibufcnt, ibuflens);
1338 /* to allow append padding during encryption */
1339 clearsize += GSS_MAX_CIPHER_BLOCK;
1341 /* Wrapper (wire) buffers
1345 wbuflens[0] = PTLRPC_GSS_HEADER_SIZE;
1346 wbuflens[1] = gss_cli_payload(req->rq_cli_ctx, clearsize, 1);
1347 wiresize = lustre_msg_size_v2(2, wbuflens);
1350 /* rq_reqbuf is preallocated */
1351 LASSERT(req->rq_reqbuf);
1352 LASSERT(req->rq_reqbuf_len >= wiresize);
1354 memset(req->rq_reqbuf, 0, req->rq_reqbuf_len);
1356 /* if the pre-allocated buffer is big enough, we just pack
1357 * both clear buf & request buf in it, to avoid more alloc. */
1358 if (clearsize + wiresize <= req->rq_reqbuf_len) {
1360 (void *) (((char *) req->rq_reqbuf) + wiresize);
1362 CWARN("pre-allocated buf size %d is not enough for "
1363 "both clear (%d) and cipher (%d) text, proceed "
1364 "with extra allocation\n", req->rq_reqbuf_len,
1365 clearsize, wiresize);
1369 if (!req->rq_clrbuf) {
1370 clearsize = size_roundup_power2(clearsize);
1372 OBD_ALLOC_LARGE(req->rq_clrbuf, clearsize);
1373 if (!req->rq_clrbuf)
1376 req->rq_clrbuf_len = clearsize;
1378 lustre_init_msg_v2(req->rq_clrbuf, ibufcnt, ibuflens, NULL);
1379 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, msgsize);
1381 if (req->rq_pack_udesc)
1382 sptlrpc_pack_user_desc(req->rq_clrbuf, 1);
1388 * NOTE: any change of request buffer allocation should also consider
1389 * changing enlarge_reqbuf() series functions.
1391 int gss_alloc_reqbuf(struct ptlrpc_sec *sec,
1392 struct ptlrpc_request *req,
1395 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1397 LASSERT(!req->rq_pack_bulk ||
1398 (req->rq_bulk_read || req->rq_bulk_write));
1401 case SPTLRPC_SVC_NULL:
1402 case SPTLRPC_SVC_AUTH:
1403 case SPTLRPC_SVC_INTG:
1404 return gss_alloc_reqbuf_intg(sec, req, svc, msgsize);
1405 case SPTLRPC_SVC_PRIV:
1406 return gss_alloc_reqbuf_priv(sec, req, msgsize);
1408 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1413 void gss_free_reqbuf(struct ptlrpc_sec *sec,
1414 struct ptlrpc_request *req)
1419 LASSERT(!req->rq_pool || req->rq_reqbuf);
1420 privacy = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc) == SPTLRPC_SVC_PRIV;
1422 if (!req->rq_clrbuf)
1423 goto release_reqbuf;
1425 /* release clear buffer */
1427 LASSERT(req->rq_clrbuf_len);
1429 if (req->rq_pool == NULL ||
1430 req->rq_clrbuf < req->rq_reqbuf ||
1431 (char *) req->rq_clrbuf >=
1432 (char *) req->rq_reqbuf + req->rq_reqbuf_len)
1433 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1435 req->rq_clrbuf = NULL;
1436 req->rq_clrbuf_len = 0;
1439 if (!req->rq_pool && req->rq_reqbuf) {
1440 LASSERT(req->rq_reqbuf_len);
1442 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1443 req->rq_reqbuf = NULL;
1444 req->rq_reqbuf_len = 0;
1450 static int do_alloc_repbuf(struct ptlrpc_request *req, int bufsize)
1452 bufsize = size_roundup_power2(bufsize);
1454 OBD_ALLOC_LARGE(req->rq_repbuf, bufsize);
1455 if (!req->rq_repbuf)
1458 req->rq_repbuf_len = bufsize;
1463 int gss_alloc_repbuf_intg(struct ptlrpc_sec *sec,
1464 struct ptlrpc_request *req,
1465 int svc, int msgsize)
1473 * on-wire data layout:
1476 * - bulk sec descriptor (optional)
1477 * - signature (optional)
1478 * - svc == NULL: NULL
1479 * - svc == AUTH: signature of gss header
1480 * - svc == INTG: signature of all above
1482 * if this is context negotiation, reserver fixed space
1483 * at the last (signature) segment regardless of svc mode.
1486 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1487 txtsize = buflens[0];
1489 buflens[1] = msgsize;
1490 if (svc == SPTLRPC_SVC_INTG)
1491 txtsize += buflens[1];
1493 if (req->rq_pack_bulk) {
1494 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1496 1, req->rq_bulk_read);
1497 if (svc == SPTLRPC_SVC_INTG)
1498 txtsize += buflens[bufcnt];
1502 if (req->rq_ctx_init)
1503 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1504 else if (svc != SPTLRPC_SVC_NULL)
1505 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1507 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1509 /* add space for early reply */
1510 alloc_size += gss_at_reply_off_integ;
1512 return do_alloc_repbuf(req, alloc_size);
1516 int gss_alloc_repbuf_priv(struct ptlrpc_sec *sec,
1517 struct ptlrpc_request *req,
1527 buflens[0] = msgsize;
1529 if (req->rq_pack_bulk)
1530 buflens[bufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1532 1, req->rq_bulk_read);
1533 txtsize = lustre_msg_size_v2(bufcnt, buflens);
1534 txtsize += GSS_MAX_CIPHER_BLOCK;
1536 /* wrapper buffers */
1538 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1539 buflens[1] = gss_cli_payload(req->rq_cli_ctx, txtsize, 1);
1541 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1542 /* add space for early reply */
1543 alloc_size += gss_at_reply_off_priv;
1545 return do_alloc_repbuf(req, alloc_size);
1548 int gss_alloc_repbuf(struct ptlrpc_sec *sec,
1549 struct ptlrpc_request *req,
1552 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1555 LASSERT(!req->rq_pack_bulk ||
1556 (req->rq_bulk_read || req->rq_bulk_write));
1559 case SPTLRPC_SVC_NULL:
1560 case SPTLRPC_SVC_AUTH:
1561 case SPTLRPC_SVC_INTG:
1562 return gss_alloc_repbuf_intg(sec, req, svc, msgsize);
1563 case SPTLRPC_SVC_PRIV:
1564 return gss_alloc_repbuf_priv(sec, req, msgsize);
1566 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1571 void gss_free_repbuf(struct ptlrpc_sec *sec,
1572 struct ptlrpc_request *req)
1574 OBD_FREE_LARGE(req->rq_repbuf, req->rq_repbuf_len);
1575 req->rq_repbuf = NULL;
1576 req->rq_repbuf_len = 0;
1577 req->rq_repdata = NULL;
1578 req->rq_repdata_len = 0;
1581 static int get_enlarged_msgsize(struct lustre_msg *msg,
1582 int segment, int newsize)
1584 int save, newmsg_size;
1586 LASSERT(newsize >= msg->lm_buflens[segment]);
1588 save = msg->lm_buflens[segment];
1589 msg->lm_buflens[segment] = newsize;
1590 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1591 msg->lm_buflens[segment] = save;
1596 static int get_enlarged_msgsize2(struct lustre_msg *msg,
1597 int segment1, int newsize1,
1598 int segment2, int newsize2)
1600 int save1, save2, newmsg_size;
1602 LASSERT(newsize1 >= msg->lm_buflens[segment1]);
1603 LASSERT(newsize2 >= msg->lm_buflens[segment2]);
1605 save1 = msg->lm_buflens[segment1];
1606 save2 = msg->lm_buflens[segment2];
1607 msg->lm_buflens[segment1] = newsize1;
1608 msg->lm_buflens[segment2] = newsize2;
1609 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1610 msg->lm_buflens[segment1] = save1;
1611 msg->lm_buflens[segment2] = save2;
1617 int gss_enlarge_reqbuf_intg(struct ptlrpc_sec *sec,
1618 struct ptlrpc_request *req,
1620 int segment, int newsize)
1622 struct lustre_msg *newbuf;
1623 int txtsize, sigsize = 0, i;
1624 int newmsg_size, newbuf_size;
1627 * gss header is at seg 0;
1628 * embedded msg is at seg 1;
1629 * signature (if any) is at the last seg
1631 LASSERT(req->rq_reqbuf);
1632 LASSERT(req->rq_reqbuf_len > req->rq_reqlen);
1633 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
1634 LASSERT(lustre_msg_buf(req->rq_reqbuf, 1, 0) == req->rq_reqmsg);
1636 /* 1. compute new embedded msg size */
1637 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1638 LASSERT(newmsg_size >= req->rq_reqbuf->lm_buflens[1]);
1640 /* 2. compute new wrapper msg size */
1641 if (svc == SPTLRPC_SVC_NULL) {
1642 /* no signature, get size directly */
1643 newbuf_size = get_enlarged_msgsize(req->rq_reqbuf,
1646 txtsize = req->rq_reqbuf->lm_buflens[0];
1648 if (svc == SPTLRPC_SVC_INTG) {
1649 for (i = 1; i < req->rq_reqbuf->lm_bufcount; i++)
1650 txtsize += req->rq_reqbuf->lm_buflens[i];
1651 txtsize += newmsg_size - req->rq_reqbuf->lm_buflens[1];
1654 sigsize = gss_cli_payload(req->rq_cli_ctx, txtsize, 0);
1655 LASSERT(sigsize >= msg_last_seglen(req->rq_reqbuf));
1657 newbuf_size = get_enlarged_msgsize2(
1660 msg_last_segidx(req->rq_reqbuf),
1664 /* request from pool should always have enough buffer */
1665 LASSERT(!req->rq_pool || req->rq_reqbuf_len >= newbuf_size);
1667 if (req->rq_reqbuf_len < newbuf_size) {
1668 newbuf_size = size_roundup_power2(newbuf_size);
1670 OBD_ALLOC_LARGE(newbuf, newbuf_size);
1674 /* Must lock this, so that otherwise unprotected change of
1675 * rq_reqmsg is not racing with parallel processing of
1676 * imp_replay_list traversing threads. See LU-3333
1677 * This is a bandaid at best, we really need to deal with this
1678 * in request enlarging code before unpacking that's already
1681 spin_lock(&req->rq_import->imp_lock);
1683 memcpy(newbuf, req->rq_reqbuf, req->rq_reqbuf_len);
1685 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1686 req->rq_reqbuf = newbuf;
1687 req->rq_reqbuf_len = newbuf_size;
1688 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, 0);
1691 spin_unlock(&req->rq_import->imp_lock);
1694 /* do enlargement, from wrapper to embedded, from end to begin */
1695 if (svc != SPTLRPC_SVC_NULL)
1696 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf,
1697 msg_last_segidx(req->rq_reqbuf),
1700 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf, 1, newmsg_size);
1701 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1703 req->rq_reqlen = newmsg_size;
1708 int gss_enlarge_reqbuf_priv(struct ptlrpc_sec *sec,
1709 struct ptlrpc_request *req,
1710 int segment, int newsize)
1712 struct lustre_msg *newclrbuf;
1713 int newmsg_size, newclrbuf_size, newcipbuf_size;
1717 * embedded msg is at seg 0 of clear buffer;
1718 * cipher text is at seg 2 of cipher buffer;
1720 LASSERT(req->rq_pool ||
1721 (req->rq_reqbuf == NULL && req->rq_reqbuf_len == 0));
1722 LASSERT(req->rq_reqbuf == NULL ||
1723 (req->rq_pool && req->rq_reqbuf->lm_bufcount == 3));
1724 LASSERT(req->rq_clrbuf);
1725 LASSERT(req->rq_clrbuf_len > req->rq_reqlen);
1726 LASSERT(lustre_msg_buf(req->rq_clrbuf, 0, 0) == req->rq_reqmsg);
1728 /* compute new embedded msg size */
1729 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1731 /* compute new clear buffer size */
1732 newclrbuf_size = get_enlarged_msgsize(req->rq_clrbuf, 0, newmsg_size);
1733 newclrbuf_size += GSS_MAX_CIPHER_BLOCK;
1735 /* compute new cipher buffer size */
1736 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1737 buflens[1] = gss_cli_payload(req->rq_cli_ctx, buflens[0], 0);
1738 buflens[2] = gss_cli_payload(req->rq_cli_ctx, newclrbuf_size, 1);
1739 newcipbuf_size = lustre_msg_size_v2(3, buflens);
1741 /* handle the case that we put both clear buf and cipher buf into
1742 * pre-allocated single buffer. */
1743 if (unlikely(req->rq_pool) &&
1744 req->rq_clrbuf >= req->rq_reqbuf &&
1745 (char *) req->rq_clrbuf <
1746 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1747 /* it couldn't be better we still fit into the
1748 * pre-allocated buffer. */
1749 if (newclrbuf_size + newcipbuf_size <= req->rq_reqbuf_len) {
1753 spin_lock(&req->rq_import->imp_lock);
1754 /* move clear text backward. */
1755 src = req->rq_clrbuf;
1756 dst = (char *) req->rq_reqbuf + newcipbuf_size;
1758 memmove(dst, src, req->rq_clrbuf_len);
1760 req->rq_clrbuf = (struct lustre_msg *) dst;
1761 req->rq_clrbuf_len = newclrbuf_size;
1762 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1765 spin_unlock(&req->rq_import->imp_lock);
1767 /* sadly we have to split out the clear buffer */
1768 LASSERT(req->rq_reqbuf_len >= newcipbuf_size);
1769 LASSERT(req->rq_clrbuf_len < newclrbuf_size);
1773 if (req->rq_clrbuf_len < newclrbuf_size) {
1774 newclrbuf_size = size_roundup_power2(newclrbuf_size);
1776 OBD_ALLOC_LARGE(newclrbuf, newclrbuf_size);
1777 if (newclrbuf == NULL)
1780 /* Must lock this, so that otherwise unprotected change of
1781 * rq_reqmsg is not racing with parallel processing of
1782 * imp_replay_list traversing threads. See LU-3333
1783 * This is a bandaid at best, we really need to deal with this
1784 * in request enlarging code before unpacking that's already
1787 spin_lock(&req->rq_import->imp_lock);
1789 memcpy(newclrbuf, req->rq_clrbuf, req->rq_clrbuf_len);
1791 if (req->rq_reqbuf == NULL ||
1792 req->rq_clrbuf < req->rq_reqbuf ||
1793 (char *) req->rq_clrbuf >=
1794 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1795 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1798 req->rq_clrbuf = newclrbuf;
1799 req->rq_clrbuf_len = newclrbuf_size;
1800 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1803 spin_unlock(&req->rq_import->imp_lock);
1806 _sptlrpc_enlarge_msg_inplace(req->rq_clrbuf, 0, newmsg_size);
1807 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1808 req->rq_reqlen = newmsg_size;
1813 int gss_enlarge_reqbuf(struct ptlrpc_sec *sec,
1814 struct ptlrpc_request *req,
1815 int segment, int newsize)
1817 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1819 LASSERT(!req->rq_ctx_init && !req->rq_ctx_fini);
1822 case SPTLRPC_SVC_NULL:
1823 case SPTLRPC_SVC_AUTH:
1824 case SPTLRPC_SVC_INTG:
1825 return gss_enlarge_reqbuf_intg(sec, req, svc, segment, newsize);
1826 case SPTLRPC_SVC_PRIV:
1827 return gss_enlarge_reqbuf_priv(sec, req, segment, newsize);
1829 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1834 int gss_sec_install_rctx(struct obd_import *imp,
1835 struct ptlrpc_sec *sec,
1836 struct ptlrpc_cli_ctx *ctx)
1838 struct gss_sec *gsec;
1839 struct gss_cli_ctx *gctx;
1842 gsec = container_of(sec, struct gss_sec, gs_base);
1843 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
1845 rc = gss_install_rvs_svc_ctx(imp, gsec, gctx);
1849 /********************************************
1851 ********************************************/
1854 int gss_svc_reqctx_is_special(struct gss_svc_reqctx *grctx)
1857 return (grctx->src_init || grctx->src_init_continue ||
1858 grctx->src_err_notify);
1862 void gss_svc_reqctx_free(struct gss_svc_reqctx *grctx)
1865 gss_svc_upcall_put_ctx(grctx->src_ctx);
1867 sptlrpc_policy_put(grctx->src_base.sc_policy);
1868 OBD_FREE_PTR(grctx);
1872 void gss_svc_reqctx_addref(struct gss_svc_reqctx *grctx)
1874 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1875 atomic_inc(&grctx->src_base.sc_refcount);
1879 void gss_svc_reqctx_decref(struct gss_svc_reqctx *grctx)
1881 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1883 if (atomic_dec_and_test(&grctx->src_base.sc_refcount))
1884 gss_svc_reqctx_free(grctx);
1888 int gss_svc_sign(struct ptlrpc_request *req,
1889 struct ptlrpc_reply_state *rs,
1890 struct gss_svc_reqctx *grctx,
1897 LASSERT(rs->rs_msg == lustre_msg_buf(rs->rs_repbuf, 1, 0));
1899 /* embedded lustre_msg might have been shrunk */
1900 if (req->rq_replen != rs->rs_repbuf->lm_buflens[1])
1901 lustre_shrink_msg(rs->rs_repbuf, 1, req->rq_replen, 1);
1903 if (req->rq_pack_bulk)
1904 flags |= LUSTRE_GSS_PACK_BULK;
1906 rc = gss_sign_msg(rs->rs_repbuf, grctx->src_ctx->gsc_mechctx,
1907 LUSTRE_SP_ANY, flags, PTLRPC_GSS_PROC_DATA,
1908 grctx->src_wirectx.gw_seq, svc, NULL);
1912 rs->rs_repdata_len = rc;
1914 if (likely(req->rq_packed_final)) {
1915 if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
1916 req->rq_reply_off = gss_at_reply_off_integ;
1918 req->rq_reply_off = 0;
1920 if (svc == SPTLRPC_SVC_NULL)
1921 rs->rs_repbuf->lm_cksum = crc32_le(!(__u32) 0,
1922 lustre_msg_buf(rs->rs_repbuf, 1, 0),
1923 lustre_msg_buflen(rs->rs_repbuf, 1));
1924 req->rq_reply_off = 0;
1930 int gss_pack_err_notify(struct ptlrpc_request *req, __u32 major, __u32 minor)
1932 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
1933 struct ptlrpc_reply_state *rs;
1934 struct gss_err_header *ghdr;
1935 int replen = sizeof(struct ptlrpc_body);
1939 grctx->src_err_notify = 1;
1940 grctx->src_reserve_len = 0;
1942 rc = lustre_pack_reply_v2(req, 1, &replen, NULL, 0);
1944 CERROR("could not pack reply, err %d\n", rc);
1949 rs = req->rq_reply_state;
1950 LASSERT(rs->rs_repbuf->lm_buflens[1] >= sizeof(*ghdr));
1951 ghdr = lustre_msg_buf(rs->rs_repbuf, 0, 0);
1952 ghdr->gh_version = PTLRPC_GSS_VERSION;
1954 ghdr->gh_proc = PTLRPC_GSS_PROC_ERR;
1955 ghdr->gh_major = major;
1956 ghdr->gh_minor = minor;
1957 ghdr->gh_handle.len = 0; /* fake context handle */
1959 rs->rs_repdata_len = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
1960 rs->rs_repbuf->lm_buflens);
1962 CDEBUG(D_SEC, "prepare gss error notify(0x%x/0x%x) to %s\n",
1963 major, minor, libcfs_nidstr(&req->rq_peer.nid));
1968 int gss_svc_handle_init(struct ptlrpc_request *req,
1969 struct gss_wire_ctx *gw)
1971 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
1972 struct lustre_msg *reqbuf = req->rq_reqbuf;
1973 struct obd_uuid *uuid;
1974 struct obd_device *target;
1975 rawobj_t uuid_obj, rvs_hdl, in_token;
1977 __u32 *secdata, seclen;
1981 CDEBUG(D_SEC, "processing gss init(%d) request from %s\n", gw->gw_proc,
1982 libcfs_nidstr(&req->rq_peer.nid));
1984 req->rq_ctx_init = 1;
1986 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
1987 CERROR("unexpected bulk flag\n");
1988 RETURN(SECSVC_DROP);
1991 if (gw->gw_proc == PTLRPC_GSS_PROC_INIT && gw->gw_handle.len != 0) {
1992 CERROR("proc %u: invalid handle length %u\n",
1993 gw->gw_proc, gw->gw_handle.len);
1994 RETURN(SECSVC_DROP);
1997 if (reqbuf->lm_bufcount < 3 || reqbuf->lm_bufcount > 4){
1998 CERROR("Invalid bufcount %d\n", reqbuf->lm_bufcount);
1999 RETURN(SECSVC_DROP);
2002 swabbed = req_capsule_req_need_swab(&req->rq_pill);
2004 /* ctx initiate payload is in last segment */
2005 secdata = lustre_msg_buf(reqbuf, reqbuf->lm_bufcount - 1, 0);
2006 seclen = reqbuf->lm_buflens[reqbuf->lm_bufcount - 1];
2008 if (seclen < 4 + 4) {
2009 CERROR("sec size %d too small\n", seclen);
2010 RETURN(SECSVC_DROP);
2013 /* lustre svc type */
2014 lustre_svc = le32_to_cpu(*secdata++);
2017 /* extract target uuid, note this code is somewhat fragile
2018 * because touched internal structure of obd_uuid */
2019 if (rawobj_extract(&uuid_obj, &secdata, &seclen)) {
2020 CERROR("failed to extract target uuid\n");
2021 RETURN(SECSVC_DROP);
2023 uuid_obj.data[uuid_obj.len - 1] = '\0';
2025 uuid = (struct obd_uuid *) uuid_obj.data;
2026 target = class_uuid2obd(uuid);
2027 if (!target || target->obd_stopping || !target->obd_set_up) {
2028 CERROR("target '%s' is not available for context init (%s)\n",
2029 uuid->uuid, target == NULL ? "no target" :
2030 (target->obd_stopping ? "stopping" : "not set up"));
2031 RETURN(SECSVC_DROP);
2034 /* extract reverse handle */
2035 if (rawobj_extract(&rvs_hdl, &secdata, &seclen)) {
2036 CERROR("failed extract reverse handle\n");
2037 RETURN(SECSVC_DROP);
2041 if (rawobj_extract(&in_token, &secdata, &seclen)) {
2042 CERROR("can't extract token\n");
2043 RETURN(SECSVC_DROP);
2046 rc = gss_svc_upcall_handle_init(req, grctx, gw, target, lustre_svc,
2047 &rvs_hdl, &in_token);
2048 if (rc != SECSVC_OK)
2051 if (grctx->src_ctx->gsc_usr_mds || grctx->src_ctx->gsc_usr_oss ||
2052 grctx->src_ctx->gsc_usr_root)
2053 CDEBUG(D_SEC, "create svc ctx %p: user from %s authenticated as %s\n",
2054 grctx->src_ctx, libcfs_nidstr(&req->rq_peer.nid),
2055 grctx->src_ctx->gsc_usr_root ? "root" :
2056 (grctx->src_ctx->gsc_usr_mds ? "mds" :
2057 (grctx->src_ctx->gsc_usr_oss ? "oss" : "null")));
2059 CDEBUG(D_SEC, "create svc ctx %p: accept user %u from %s\n",
2060 grctx->src_ctx, grctx->src_ctx->gsc_uid,
2061 libcfs_nidstr(&req->rq_peer.nid));
2063 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2064 if (reqbuf->lm_bufcount < 4) {
2065 CERROR("missing user descriptor\n");
2066 RETURN(SECSVC_DROP);
2068 if (sptlrpc_unpack_user_desc(reqbuf, 2, swabbed)) {
2069 CERROR("Mal-formed user descriptor\n");
2070 RETURN(SECSVC_DROP);
2073 req->rq_pack_udesc = 1;
2074 req->rq_user_desc = lustre_msg_buf(reqbuf, 2, 0);
2077 req->rq_reqmsg = lustre_msg_buf(reqbuf, 1, 0);
2078 req->rq_reqlen = lustre_msg_buflen(reqbuf, 1);
2084 * last segment must be the gss signature.
2087 int gss_svc_verify_request(struct ptlrpc_request *req,
2088 struct gss_svc_reqctx *grctx,
2089 struct gss_wire_ctx *gw,
2092 struct gss_svc_ctx *gctx = grctx->src_ctx;
2093 struct lustre_msg *msg = req->rq_reqbuf;
2098 *major = GSS_S_COMPLETE;
2100 if (msg->lm_bufcount < 2) {
2101 CERROR("Too few segments (%u) in request\n", msg->lm_bufcount);
2105 if (gw->gw_svc == SPTLRPC_SVC_NULL)
2108 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2109 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2110 *major = GSS_S_DUPLICATE_TOKEN;
2114 *major = gss_verify_msg(msg, gctx->gsc_mechctx, gw->gw_svc);
2115 if (*major != GSS_S_COMPLETE) {
2116 CERROR("failed to verify request: %x\n", *major);
2120 if (gctx->gsc_reverse == 0 &&
2121 gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2122 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2123 *major = GSS_S_DUPLICATE_TOKEN;
2128 swabbed = req_capsule_req_need_swab(&req->rq_pill);
2130 /* user descriptor */
2131 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2132 if (msg->lm_bufcount < (offset + 1)) {
2133 CERROR("no user desc included\n");
2137 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2138 CERROR("Mal-formed user descriptor\n");
2142 req->rq_pack_udesc = 1;
2143 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2147 /* check bulk_sec_desc data */
2148 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2149 if (msg->lm_bufcount < (offset + 1)) {
2150 CERROR("missing bulk sec descriptor\n");
2154 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2157 req->rq_pack_bulk = 1;
2158 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2159 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2162 req->rq_reqmsg = lustre_msg_buf(msg, 1, 0);
2163 req->rq_reqlen = msg->lm_buflens[1];
2168 int gss_svc_unseal_request(struct ptlrpc_request *req,
2169 struct gss_svc_reqctx *grctx,
2170 struct gss_wire_ctx *gw,
2173 struct gss_svc_ctx *gctx = grctx->src_ctx;
2174 struct lustre_msg *msg = req->rq_reqbuf;
2175 int swabbed, msglen, offset = 1;
2178 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2179 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2180 *major = GSS_S_DUPLICATE_TOKEN;
2184 *major = gss_unseal_msg(gctx->gsc_mechctx, msg,
2185 &msglen, req->rq_reqdata_len);
2186 if (*major != GSS_S_COMPLETE) {
2187 CERROR("failed to unwrap request: %x\n", *major);
2191 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2192 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2193 *major = GSS_S_DUPLICATE_TOKEN;
2197 swabbed = __lustre_unpack_msg(msg, msglen);
2199 CERROR("Failed to unpack after decryption\n");
2202 req->rq_reqdata_len = msglen;
2204 if (msg->lm_bufcount < 1) {
2205 CERROR("Invalid buffer: is empty\n");
2209 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2210 if (msg->lm_bufcount < offset + 1) {
2211 CERROR("no user descriptor included\n");
2215 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2216 CERROR("Mal-formed user descriptor\n");
2220 req->rq_pack_udesc = 1;
2221 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2225 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2226 if (msg->lm_bufcount < offset + 1) {
2227 CERROR("no bulk checksum included\n");
2231 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2234 req->rq_pack_bulk = 1;
2235 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2236 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2239 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 0, 0);
2240 req->rq_reqlen = req->rq_reqbuf->lm_buflens[0];
2245 int gss_svc_handle_data(struct ptlrpc_request *req,
2246 struct gss_wire_ctx *gw)
2248 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2253 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2254 if (!grctx->src_ctx) {
2255 major = GSS_S_NO_CONTEXT;
2259 switch (gw->gw_svc) {
2260 case SPTLRPC_SVC_NULL:
2261 case SPTLRPC_SVC_AUTH:
2262 case SPTLRPC_SVC_INTG:
2263 rc = gss_svc_verify_request(req, grctx, gw, &major);
2265 case SPTLRPC_SVC_PRIV:
2266 rc = gss_svc_unseal_request(req, grctx, gw, &major);
2269 CERROR("unsupported gss service %d\n", gw->gw_svc);
2276 CERROR("svc %u failed: major 0x%08x: req xid %llu ctx %p idx %#llx(%u->%s)\n",
2277 gw->gw_svc, major, req->rq_xid,
2278 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2279 grctx->src_ctx->gsc_uid, libcfs_nidstr(&req->rq_peer.nid));
2281 /* we only notify client in case of NO_CONTEXT/BAD_SIG, which
2282 * might happen after server reboot, to allow recovery. */
2283 if ((major == GSS_S_NO_CONTEXT || major == GSS_S_BAD_SIG) &&
2284 gss_pack_err_notify(req, major, 0) == 0)
2285 RETURN(SECSVC_COMPLETE);
2287 RETURN(SECSVC_DROP);
2291 int gss_svc_handle_destroy(struct ptlrpc_request *req,
2292 struct gss_wire_ctx *gw)
2294 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2298 req->rq_ctx_fini = 1;
2299 req->rq_no_reply = 1;
2301 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2302 if (!grctx->src_ctx) {
2303 CDEBUG(D_SEC, "invalid gss context handle for destroy.\n");
2304 RETURN(SECSVC_DROP);
2307 if (gw->gw_svc != SPTLRPC_SVC_INTG) {
2308 CERROR("svc %u is not supported in destroy.\n", gw->gw_svc);
2309 RETURN(SECSVC_DROP);
2312 if (gss_svc_verify_request(req, grctx, gw, &major))
2313 RETURN(SECSVC_DROP);
2315 CDEBUG(D_SEC, "destroy svc ctx %p idx %#llx (%u->%s)\n",
2316 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2317 grctx->src_ctx->gsc_uid, libcfs_nidstr(&req->rq_peer.nid));
2319 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2321 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2322 if (req->rq_reqbuf->lm_bufcount < 4) {
2323 CERROR("missing user descriptor, ignore it\n");
2326 if (sptlrpc_unpack_user_desc(req->rq_reqbuf, 2,
2327 req_capsule_req_need_swab(&req->rq_pill))) {
2328 CERROR("Mal-formed user descriptor, ignore it\n");
2332 req->rq_pack_udesc = 1;
2333 req->rq_user_desc = lustre_msg_buf(req->rq_reqbuf, 2, 0);
2339 int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
2341 struct gss_header *ghdr;
2342 struct gss_svc_reqctx *grctx;
2343 struct gss_wire_ctx *gw;
2347 LASSERT(req->rq_reqbuf);
2348 LASSERT(req->rq_svc_ctx == NULL);
2350 if (req->rq_reqbuf->lm_bufcount < 2) {
2351 CERROR("buf count only %d\n", req->rq_reqbuf->lm_bufcount);
2352 RETURN(SECSVC_DROP);
2355 swabbed = req_capsule_req_need_swab(&req->rq_pill);
2357 ghdr = gss_swab_header(req->rq_reqbuf, 0, swabbed);
2359 CERROR("can't decode gss header\n");
2360 RETURN(SECSVC_DROP);
2364 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
2365 CERROR("gss version %u, expect %u\n", ghdr->gh_version,
2366 PTLRPC_GSS_VERSION);
2367 RETURN(SECSVC_DROP);
2370 req->rq_sp_from = ghdr->gh_sp;
2372 /* alloc grctx data */
2373 OBD_ALLOC_PTR(grctx);
2375 RETURN(SECSVC_DROP);
2377 grctx->src_base.sc_policy = sptlrpc_policy_get(policy);
2378 atomic_set(&grctx->src_base.sc_refcount, 1);
2379 req->rq_svc_ctx = &grctx->src_base;
2380 gw = &grctx->src_wirectx;
2382 /* save wire context */
2383 gw->gw_flags = ghdr->gh_flags;
2384 gw->gw_proc = ghdr->gh_proc;
2385 gw->gw_seq = ghdr->gh_seq;
2386 gw->gw_svc = ghdr->gh_svc;
2387 rawobj_from_netobj(&gw->gw_handle, &ghdr->gh_handle);
2389 /* keep original wire header which subject to checksum verification */
2391 gss_header_swabber(ghdr);
2393 switch(ghdr->gh_proc) {
2394 case PTLRPC_GSS_PROC_INIT:
2395 case PTLRPC_GSS_PROC_CONTINUE_INIT:
2396 rc = gss_svc_handle_init(req, gw);
2398 case PTLRPC_GSS_PROC_DATA:
2399 rc = gss_svc_handle_data(req, gw);
2401 case PTLRPC_GSS_PROC_DESTROY:
2402 rc = gss_svc_handle_destroy(req, gw);
2405 CERROR("unknown proc %u\n", gw->gw_proc);
2412 LASSERT (grctx->src_ctx);
2414 req->rq_auth_gss = 1;
2415 req->rq_auth_usr_mdt = grctx->src_ctx->gsc_usr_mds;
2416 req->rq_auth_usr_ost = grctx->src_ctx->gsc_usr_oss;
2417 req->rq_auth_usr_root = grctx->src_ctx->gsc_usr_root;
2418 req->rq_auth_uid = grctx->src_ctx->gsc_uid;
2419 req->rq_auth_mapped_uid = grctx->src_ctx->gsc_mapped_uid;
2421 case SECSVC_COMPLETE:
2424 gss_svc_reqctx_free(grctx);
2425 req->rq_svc_ctx = NULL;
2432 void gss_svc_invalidate_ctx(struct ptlrpc_svc_ctx *svc_ctx)
2434 struct gss_svc_reqctx *grctx;
2437 if (svc_ctx == NULL) {
2442 grctx = gss_svc_ctx2reqctx(svc_ctx);
2444 CWARN("gss svc invalidate ctx %p(%u)\n",
2445 grctx->src_ctx, grctx->src_ctx->gsc_uid);
2446 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2452 int gss_svc_payload(struct gss_svc_reqctx *grctx, int early,
2453 int msgsize, int privacy)
2455 /* we should treat early reply normally, but which is actually sharing
2456 * the same ctx with original request, so in this case we should
2457 * ignore the special ctx's special flags */
2458 if (early == 0 && gss_svc_reqctx_is_special(grctx))
2459 return grctx->src_reserve_len;
2461 return gss_mech_payload(NULL, msgsize, privacy);
2464 static int gss_svc_bulk_payload(struct gss_svc_ctx *gctx,
2465 struct sptlrpc_flavor *flvr,
2468 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
2471 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
2472 case SPTLRPC_BULK_SVC_NULL:
2474 case SPTLRPC_BULK_SVC_INTG:
2475 payload += gss_mech_payload(NULL, 0, 0);
2477 case SPTLRPC_BULK_SVC_PRIV:
2478 payload += gss_mech_payload(NULL, 0, 1);
2480 case SPTLRPC_BULK_SVC_AUTH:
2489 int gss_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
2491 struct gss_svc_reqctx *grctx;
2492 struct ptlrpc_reply_state *rs;
2493 int early, privacy, svc, bsd_off = 0;
2494 __u32 ibuflens[2], buflens[4];
2495 int ibufcnt = 0, bufcnt;
2496 int txtsize, wmsg_size, rs_size;
2499 LASSERT(msglen % 8 == 0);
2501 if (req->rq_pack_bulk && !req->rq_bulk_read && !req->rq_bulk_write) {
2502 CERROR("client request bulk sec on non-bulk rpc\n");
2506 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
2507 early = (req->rq_packed_final == 0);
2509 grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2510 if (!early && gss_svc_reqctx_is_special(grctx))
2513 privacy = (svc == SPTLRPC_SVC_PRIV);
2516 /* inner clear buffers */
2518 ibuflens[0] = msglen;
2520 if (req->rq_pack_bulk) {
2521 LASSERT(grctx->src_reqbsd);
2524 ibuflens[ibufcnt++] = gss_svc_bulk_payload(
2530 txtsize = lustre_msg_size_v2(ibufcnt, ibuflens);
2531 txtsize += GSS_MAX_CIPHER_BLOCK;
2533 /* wrapper buffer */
2535 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2536 buflens[1] = gss_svc_payload(grctx, early, txtsize, 1);
2539 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2540 buflens[1] = msglen;
2542 txtsize = buflens[0];
2543 if (svc == SPTLRPC_SVC_INTG)
2544 txtsize += buflens[1];
2546 if (req->rq_pack_bulk) {
2547 LASSERT(grctx->src_reqbsd);
2550 buflens[bufcnt] = gss_svc_bulk_payload(
2554 if (svc == SPTLRPC_SVC_INTG)
2555 txtsize += buflens[bufcnt];
2559 if ((!early && gss_svc_reqctx_is_special(grctx)) ||
2560 svc != SPTLRPC_SVC_NULL)
2561 buflens[bufcnt++] = gss_svc_payload(grctx, early,
2565 wmsg_size = lustre_msg_size_v2(bufcnt, buflens);
2567 rs_size = sizeof(*rs) + wmsg_size;
2568 rs = req->rq_reply_state;
2572 LASSERT(rs->rs_size >= rs_size);
2574 OBD_ALLOC_LARGE(rs, rs_size);
2578 rs->rs_size = rs_size;
2581 rs->rs_repbuf = (struct lustre_msg *) (rs + 1);
2582 rs->rs_repbuf_len = wmsg_size;
2584 /* initialize the buffer */
2586 lustre_init_msg_v2(rs->rs_repbuf, ibufcnt, ibuflens, NULL);
2587 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 0, msglen);
2589 lustre_init_msg_v2(rs->rs_repbuf, bufcnt, buflens, NULL);
2590 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2592 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 1, 0);
2596 grctx->src_repbsd = lustre_msg_buf(rs->rs_repbuf, bsd_off, 0);
2597 grctx->src_repbsd_size = lustre_msg_buflen(rs->rs_repbuf,
2601 gss_svc_reqctx_addref(grctx);
2602 rs->rs_svc_ctx = req->rq_svc_ctx;
2604 LASSERT(rs->rs_msg);
2605 req->rq_reply_state = rs;
2609 static int gss_svc_seal(struct ptlrpc_request *req,
2610 struct ptlrpc_reply_state *rs,
2611 struct gss_svc_reqctx *grctx)
2613 struct gss_svc_ctx *gctx = grctx->src_ctx;
2614 rawobj_t hdrobj, msgobj, token;
2615 struct gss_header *ghdr;
2618 __u32 buflens[2], major;
2622 /* get clear data length. note embedded lustre_msg might
2623 * have been shrunk */
2624 if (req->rq_replen != lustre_msg_buflen(rs->rs_repbuf, 0))
2625 msglen = lustre_shrink_msg(rs->rs_repbuf, 0, req->rq_replen, 1);
2627 msglen = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
2628 rs->rs_repbuf->lm_buflens);
2630 /* temporarily use tail of buffer to hold gss header data */
2631 LASSERT(msglen + PTLRPC_GSS_HEADER_SIZE <= rs->rs_repbuf_len);
2632 ghdr = (struct gss_header *) ((char *) rs->rs_repbuf +
2633 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE);
2634 ghdr->gh_version = PTLRPC_GSS_VERSION;
2635 ghdr->gh_sp = LUSTRE_SP_ANY;
2637 ghdr->gh_proc = PTLRPC_GSS_PROC_DATA;
2638 ghdr->gh_seq = grctx->src_wirectx.gw_seq;
2639 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
2640 ghdr->gh_handle.len = 0;
2641 if (req->rq_pack_bulk)
2642 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
2644 /* allocate temporary cipher buffer */
2645 token_buflen = gss_mech_payload(gctx->gsc_mechctx, msglen, 1);
2646 OBD_ALLOC_LARGE(token_buf, token_buflen);
2647 if (token_buf == NULL)
2650 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
2651 hdrobj.data = (__u8 *) ghdr;
2652 msgobj.len = msglen;
2653 msgobj.data = (__u8 *) rs->rs_repbuf;
2654 token.len = token_buflen;
2655 token.data = token_buf;
2657 major = lgss_wrap(gctx->gsc_mechctx, &hdrobj, &msgobj,
2658 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE, &token);
2659 if (major != GSS_S_COMPLETE) {
2660 CERROR("wrap message error: %08x\n", major);
2661 GOTO(out_free, rc = -EPERM);
2663 LASSERT(token.len <= token_buflen);
2665 /* we are about to override data at rs->rs_repbuf, nullify pointers
2666 * to which to catch further illegal usage. */
2667 if (req->rq_pack_bulk) {
2668 grctx->src_repbsd = NULL;
2669 grctx->src_repbsd_size = 0;
2672 /* now fill the actual wire data
2676 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2677 buflens[1] = token.len;
2679 rs->rs_repdata_len = lustre_msg_size_v2(2, buflens);
2680 LASSERT(rs->rs_repdata_len <= rs->rs_repbuf_len);
2682 lustre_init_msg_v2(rs->rs_repbuf, 2, buflens, NULL);
2683 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2685 memcpy(lustre_msg_buf(rs->rs_repbuf, 0, 0), ghdr,
2686 PTLRPC_GSS_HEADER_SIZE);
2687 memcpy(lustre_msg_buf(rs->rs_repbuf, 1, 0), token.data, token.len);
2690 if (req->rq_packed_final &&
2691 (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))
2692 req->rq_reply_off = gss_at_reply_off_priv;
2694 req->rq_reply_off = 0;
2696 /* to catch upper layer's further access */
2698 req->rq_repmsg = NULL;
2703 OBD_FREE_LARGE(token_buf, token_buflen);
2707 int gss_svc_authorize(struct ptlrpc_request *req)
2709 struct ptlrpc_reply_state *rs = req->rq_reply_state;
2710 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2711 struct gss_wire_ctx *gw = &grctx->src_wirectx;
2715 early = (req->rq_packed_final == 0);
2717 if (!early && gss_svc_reqctx_is_special(grctx)) {
2718 LASSERT(rs->rs_repdata_len != 0);
2720 req->rq_reply_off = gss_at_reply_off_integ;
2724 /* early reply could happen in many cases */
2726 gw->gw_proc != PTLRPC_GSS_PROC_DATA &&
2727 gw->gw_proc != PTLRPC_GSS_PROC_DESTROY) {
2728 CERROR("proc %d not support\n", gw->gw_proc);
2732 LASSERT(grctx->src_ctx);
2734 switch (gw->gw_svc) {
2735 case SPTLRPC_SVC_NULL:
2736 case SPTLRPC_SVC_AUTH:
2737 case SPTLRPC_SVC_INTG:
2738 rc = gss_svc_sign(req, rs, grctx, gw->gw_svc);
2740 case SPTLRPC_SVC_PRIV:
2741 rc = gss_svc_seal(req, rs, grctx);
2744 CERROR("Unknown service %d\n", gw->gw_svc);
2745 GOTO(out, rc = -EINVAL);
2753 void gss_svc_free_rs(struct ptlrpc_reply_state *rs)
2755 struct gss_svc_reqctx *grctx;
2757 LASSERT(rs->rs_svc_ctx);
2758 grctx = container_of(rs->rs_svc_ctx, struct gss_svc_reqctx, src_base);
2760 gss_svc_reqctx_decref(grctx);
2761 rs->rs_svc_ctx = NULL;
2763 if (!rs->rs_prealloc)
2764 OBD_FREE_LARGE(rs, rs->rs_size);
2767 void gss_svc_free_ctx(struct ptlrpc_svc_ctx *ctx)
2769 LASSERT(atomic_read(&ctx->sc_refcount) == 0);
2770 gss_svc_reqctx_free(gss_svc_ctx2reqctx(ctx));
2773 int gss_copy_rvc_cli_ctx(struct ptlrpc_cli_ctx *cli_ctx,
2774 struct ptlrpc_svc_ctx *svc_ctx)
2776 struct gss_cli_ctx *cli_gctx = ctx2gctx(cli_ctx);
2777 struct gss_svc_ctx *svc_gctx = gss_svc_ctx2gssctx(svc_ctx);
2778 struct gss_ctx *mechctx = NULL;
2781 LASSERT(svc_gctx && svc_gctx->gsc_mechctx);
2783 cli_gctx->gc_proc = PTLRPC_GSS_PROC_DATA;
2784 cli_gctx->gc_win = GSS_SEQ_WIN;
2786 /* The problem is the reverse ctx might get lost in some recovery
2787 * situations, and the same svc_ctx will be used to re-create it.
2788 * if there's callback be sentout before that, new reverse ctx start
2789 * with sequence 0 will lead to future callback rpc be treated as
2792 * each reverse root ctx will record its latest sequence number on its
2793 * buddy svcctx before be destroyed, so here we continue use it.
2795 atomic_set(&cli_gctx->gc_seq, svc_gctx->gsc_rvs_seq);
2797 if (gss_svc_upcall_dup_handle(&cli_gctx->gc_svc_handle, svc_gctx)) {
2798 CERROR("failed to dup svc handle\n");
2802 if (lgss_copy_reverse_context(svc_gctx->gsc_mechctx, &mechctx) !=
2804 CERROR("failed to copy mech context\n");
2805 goto err_svc_handle;
2808 if (rawobj_dup(&cli_gctx->gc_handle, &svc_gctx->gsc_rvs_hdl)) {
2809 CERROR("failed to dup reverse handle\n");
2813 cli_gctx->gc_mechctx = mechctx;
2814 gss_cli_ctx_uptodate(cli_gctx);
2819 lgss_delete_sec_context(&mechctx);
2821 rawobj_free(&cli_gctx->gc_svc_handle);
2826 static void gss_init_at_reply_offset(void)
2831 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2832 buflens[1] = lustre_msg_early_size;
2833 buflens[2] = gss_cli_payload(NULL, buflens[1], 0);
2834 gss_at_reply_off_integ = lustre_msg_size_v2(3, buflens);
2836 buflens[0] = lustre_msg_early_size;
2837 clearsize = lustre_msg_size_v2(1, buflens);
2838 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2839 buflens[1] = gss_cli_payload(NULL, clearsize, 0);
2840 buflens[2] = gss_cli_payload(NULL, clearsize, 1);
2841 gss_at_reply_off_priv = lustre_msg_size_v2(3, buflens);
2844 static int __init sptlrpc_gss_init(void)
2848 rc = gss_init_tunables();
2852 rc = gss_init_cli_upcall();
2856 rc = gss_init_svc_upcall();
2858 goto out_cli_upcall;
2860 rc = init_null_module();
2862 goto out_svc_upcall;
2864 rc = init_kerberos_module();
2868 rc = init_sk_module();
2872 /* register policy after all other stuff be initialized, because it
2873 * might be in used immediately after the registration. */
2875 rc = gss_init_keyring();
2879 gss_init_at_reply_offset();
2884 cleanup_sk_module();
2886 cleanup_kerberos_module();
2888 cleanup_null_module();
2890 gss_exit_svc_upcall();
2892 gss_exit_cli_upcall();
2894 gss_exit_tunables();
2898 static void __exit sptlrpc_gss_exit(void)
2901 cleanup_kerberos_module();
2902 gss_exit_svc_upcall();
2903 gss_exit_cli_upcall();
2904 gss_exit_tunables();
2907 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2908 MODULE_DESCRIPTION("Lustre GSS security policy");
2909 MODULE_VERSION(LUSTRE_VERSION_STRING);
2910 MODULE_LICENSE("GPL");
2912 module_init(sptlrpc_gss_init);
2913 module_exit(sptlrpc_gss_exit);