2 * Modifications for Lustre
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Copyright (c) 2011, 2016, 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]);
130 * payload should be obtained from mechanism. but currently since we
131 * only support kerberos, we could simply use fixed value.
134 * - krb5 checksum: 20
136 * for privacy mode, payload also include the cipher text which has the same
137 * size as plain text, plus possible confounder, padding both at maximum cipher
140 #define GSS_KRB5_INTEG_MAX_PAYLOAD (40)
143 int gss_mech_payload(struct gss_ctx *mechctx, int msgsize, int privacy)
146 return GSS_KRB5_INTEG_MAX_PAYLOAD + 16 + 16 + 16 + msgsize;
148 return GSS_KRB5_INTEG_MAX_PAYLOAD;
152 * return signature size, otherwise < 0 to indicate error
154 static int gss_sign_msg(struct lustre_msg *msg,
155 struct gss_ctx *mechctx,
156 enum lustre_sec_part sp,
157 __u32 flags, __u32 proc, __u32 seq, __u32 svc,
160 struct gss_header *ghdr;
161 rawobj_t text[4], mic;
162 int textcnt, max_textcnt, mic_idx;
165 LASSERT(msg->lm_bufcount >= 2);
168 LASSERT(msg->lm_buflens[0] >=
169 sizeof(*ghdr) + (handle ? handle->len : 0));
170 ghdr = lustre_msg_buf(msg, 0, 0);
172 ghdr->gh_version = PTLRPC_GSS_VERSION;
173 ghdr->gh_sp = (__u8) sp;
174 ghdr->gh_flags = flags;
175 ghdr->gh_proc = proc;
179 /* fill in a fake one */
180 ghdr->gh_handle.len = 0;
182 ghdr->gh_handle.len = handle->len;
183 memcpy(ghdr->gh_handle.data, handle->data, handle->len);
186 /* no actual signature for null mode */
187 if (svc == SPTLRPC_SVC_NULL)
188 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
191 mic_idx = msg_last_segidx(msg);
192 max_textcnt = (svc == SPTLRPC_SVC_AUTH) ? 1 : mic_idx;
194 for (textcnt = 0; textcnt < max_textcnt; textcnt++) {
195 text[textcnt].len = msg->lm_buflens[textcnt];
196 text[textcnt].data = lustre_msg_buf(msg, textcnt, 0);
199 mic.len = msg->lm_buflens[mic_idx];
200 mic.data = lustre_msg_buf(msg, mic_idx, 0);
202 major = lgss_get_mic(mechctx, textcnt, text, 0, NULL, &mic);
203 if (major != GSS_S_COMPLETE) {
204 CERROR("fail to generate MIC: %08x\n", major);
207 LASSERT(mic.len <= msg->lm_buflens[mic_idx]);
209 return lustre_shrink_msg(msg, mic_idx, mic.len, 0);
216 __u32 gss_verify_msg(struct lustre_msg *msg,
217 struct gss_ctx *mechctx,
220 rawobj_t text[4], mic;
221 int textcnt, max_textcnt;
225 LASSERT(msg->lm_bufcount >= 2);
227 if (svc == SPTLRPC_SVC_NULL)
228 return GSS_S_COMPLETE;
230 mic_idx = msg_last_segidx(msg);
231 max_textcnt = (svc == SPTLRPC_SVC_AUTH) ? 1 : mic_idx;
233 for (textcnt = 0; textcnt < max_textcnt; textcnt++) {
234 text[textcnt].len = msg->lm_buflens[textcnt];
235 text[textcnt].data = lustre_msg_buf(msg, textcnt, 0);
238 mic.len = msg->lm_buflens[mic_idx];
239 mic.data = lustre_msg_buf(msg, mic_idx, 0);
241 major = lgss_verify_mic(mechctx, textcnt, text, 0, NULL, &mic);
242 if (major != GSS_S_COMPLETE)
243 CERROR("mic verify error: %08x\n", major);
249 * return gss error code
252 __u32 gss_unseal_msg(struct gss_ctx *mechctx,
253 struct lustre_msg *msgbuf,
254 int *msg_len, int msgbuf_len)
256 rawobj_t clear_obj, hdrobj, token;
262 if (msgbuf->lm_bufcount != 2) {
263 CERROR("invalid bufcount %d\n", msgbuf->lm_bufcount);
264 RETURN(GSS_S_FAILURE);
267 /* allocate a temporary clear text buffer, same sized as token,
268 * we assume the final clear text size <= token size */
269 clear_buflen = lustre_msg_buflen(msgbuf, 1);
270 OBD_ALLOC_LARGE(clear_buf, clear_buflen);
272 RETURN(GSS_S_FAILURE);
275 hdrobj.len = lustre_msg_buflen(msgbuf, 0);
276 hdrobj.data = lustre_msg_buf(msgbuf, 0, 0);
277 token.len = lustre_msg_buflen(msgbuf, 1);
278 token.data = lustre_msg_buf(msgbuf, 1, 0);
279 clear_obj.len = clear_buflen;
280 clear_obj.data = clear_buf;
282 major = lgss_unwrap(mechctx, &hdrobj, &token, &clear_obj);
283 if (major != GSS_S_COMPLETE) {
284 CERROR("unwrap message error: %08x\n", major);
285 GOTO(out_free, major = GSS_S_FAILURE);
287 LASSERT(clear_obj.len <= clear_buflen);
288 LASSERT(clear_obj.len <= msgbuf_len);
290 /* now the decrypted message */
291 memcpy(msgbuf, clear_obj.data, clear_obj.len);
292 *msg_len = clear_obj.len;
294 major = GSS_S_COMPLETE;
296 OBD_FREE_LARGE(clear_buf, clear_buflen);
300 /********************************************
301 * gss client context manipulation helpers *
302 ********************************************/
304 int cli_ctx_expire(struct ptlrpc_cli_ctx *ctx)
306 LASSERT(atomic_read(&ctx->cc_refcount));
308 if (!test_and_set_bit(PTLRPC_CTX_DEAD_BIT, &ctx->cc_flags)) {
309 if (!ctx->cc_early_expire)
310 clear_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
312 CWARN("ctx %p(%u->%s) get expired: %lu(%+lds)\n",
313 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
315 ctx->cc_expire == 0 ? 0 :
316 cfs_time_sub(ctx->cc_expire, cfs_time_current_sec()));
318 sptlrpc_cli_ctx_wakeup(ctx);
326 * return 1 if the context is dead.
328 int cli_ctx_check_death(struct ptlrpc_cli_ctx *ctx)
330 if (unlikely(cli_ctx_is_dead(ctx)))
333 /* expire is 0 means never expire. a newly created gss context
334 * which during upcall may has 0 expiration */
335 if (ctx->cc_expire == 0)
338 /* check real expiration */
339 if (cfs_time_after(ctx->cc_expire, cfs_time_current_sec()))
346 void gss_cli_ctx_uptodate(struct gss_cli_ctx *gctx)
348 struct ptlrpc_cli_ctx *ctx = &gctx->gc_base;
349 unsigned long ctx_expiry;
351 if (lgss_inquire_context(gctx->gc_mechctx, &ctx_expiry)) {
352 CERROR("ctx %p(%u): unable to inquire, expire it now\n",
353 gctx, ctx->cc_vcred.vc_uid);
354 ctx_expiry = 1; /* make it expired now */
357 ctx->cc_expire = gss_round_ctx_expiry(ctx_expiry,
358 ctx->cc_sec->ps_flvr.sf_flags);
360 /* At this point this ctx might have been marked as dead by
361 * someone else, in which case nobody will make further use
362 * of it. we don't care, and mark it UPTODATE will help
363 * destroying server side context when it be destroyed. */
364 set_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags);
366 if (sec_is_reverse(ctx->cc_sec)) {
367 CWARN("server installed reverse ctx %p idx %#llx, "
368 "expiry %lu(%+lds)\n", ctx,
369 gss_handle_to_u64(&gctx->gc_handle),
371 cfs_time_sub(ctx->cc_expire, cfs_time_current_sec()));
373 CWARN("client refreshed ctx %p idx %#llx (%u->%s), "
374 "expiry %lu(%+lds)\n", ctx,
375 gss_handle_to_u64(&gctx->gc_handle),
376 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
378 cfs_time_sub(ctx->cc_expire, cfs_time_current_sec()));
380 /* install reverse svc ctx for root context */
381 if (ctx->cc_vcred.vc_uid == 0)
382 gss_sec_install_rctx(ctx->cc_sec->ps_import,
386 sptlrpc_cli_ctx_wakeup(ctx);
389 static void gss_cli_ctx_finalize(struct gss_cli_ctx *gctx)
391 LASSERT(gctx->gc_base.cc_sec);
393 if (gctx->gc_mechctx) {
394 lgss_delete_sec_context(&gctx->gc_mechctx);
395 gctx->gc_mechctx = NULL;
398 if (!rawobj_empty(&gctx->gc_svc_handle)) {
399 /* forward ctx: mark buddy reverse svcctx soon-expire. */
400 if (!sec_is_reverse(gctx->gc_base.cc_sec) &&
401 !rawobj_empty(&gctx->gc_svc_handle))
402 gss_svc_upcall_expire_rvs_ctx(&gctx->gc_svc_handle);
404 rawobj_free(&gctx->gc_svc_handle);
407 rawobj_free(&gctx->gc_handle);
411 * Based on sequence number algorithm as specified in RFC 2203.
413 * Modified for our own problem: arriving request has valid sequence number,
414 * but unwrapping request might cost a long time, after that its sequence
415 * are not valid anymore (fall behind the window). It rarely happen, mostly
416 * under extreme load.
418 * Note we should not check sequence before verifying the integrity of incoming
419 * request, because just one attacking request with high sequence number might
420 * cause all following requests be dropped.
422 * So here we use a multi-phase approach: prepare 2 sequence windows,
423 * "main window" for normal sequence and "back window" for fall behind sequence.
424 * and 3-phase checking mechanism:
425 * 0 - before integrity verification, perform an initial sequence checking in
426 * main window, which only tries and doesn't actually set any bits. if the
427 * sequence is high above the window or fits in the window and the bit
428 * is 0, then accept and proceed to integrity verification. otherwise
429 * reject this sequence.
430 * 1 - after integrity verification, check in main window again. if this
431 * sequence is high above the window or fits in the window and the bit
432 * is 0, then set the bit and accept; if it fits in the window but bit
433 * already set, then reject; if it falls behind the window, then proceed
435 * 2 - check in back window. if it is high above the window or fits in the
436 * window and the bit is 0, then set the bit and accept. otherwise reject.
438 * \return 1: looks like a replay
440 * \return -1: is a replay
442 * Note phase 0 is necessary, because otherwise replay attacking request of
443 * sequence which between the 2 windows can't be detected.
445 * This mechanism can't totally solve the problem, but could help reduce the
446 * number of valid requests be dropped.
449 int gss_do_check_seq(unsigned long *window, __u32 win_size, __u32 *max_seq,
450 __u32 seq_num, int phase)
452 LASSERT(phase >= 0 && phase <= 2);
454 if (seq_num > *max_seq) {
456 * 1. high above the window
461 if (seq_num >= *max_seq + win_size) {
462 memset(window, 0, win_size / 8);
465 while(*max_seq < seq_num) {
467 __clear_bit((*max_seq) % win_size, window);
470 __set_bit(seq_num % win_size, window);
471 } else if (seq_num + win_size <= *max_seq) {
473 * 2. low behind the window
475 if (phase == 0 || phase == 2)
478 CWARN("seq %u is %u behind (size %d), check backup window\n",
479 seq_num, *max_seq - win_size - seq_num, win_size);
483 * 3. fit into the window
487 if (test_bit(seq_num % win_size, window))
492 if (__test_and_set_bit(seq_num % win_size, window))
501 CERROR("seq %u (%s %s window) is a replay: max %u, winsize %d\n",
503 seq_num + win_size > *max_seq ? "in" : "behind",
504 phase == 2 ? "backup " : "main",
510 * Based on sequence number algorithm as specified in RFC 2203.
512 * if @set == 0: initial check, don't set any bit in window
513 * if @sec == 1: final check, set bit in window
515 int gss_check_seq_num(struct gss_svc_seq_data *ssd, __u32 seq_num, int set)
519 spin_lock(&ssd->ssd_lock);
525 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
526 &ssd->ssd_max_main, seq_num, 0);
528 gss_stat_oos_record_svc(0, 1);
531 * phase 1 checking main window
533 rc = gss_do_check_seq(ssd->ssd_win_main, GSS_SEQ_WIN_MAIN,
534 &ssd->ssd_max_main, seq_num, 1);
537 gss_stat_oos_record_svc(1, 1);
543 * phase 2 checking back window
545 rc = gss_do_check_seq(ssd->ssd_win_back, GSS_SEQ_WIN_BACK,
546 &ssd->ssd_max_back, seq_num, 2);
548 gss_stat_oos_record_svc(2, 1);
550 gss_stat_oos_record_svc(2, 0);
553 spin_unlock(&ssd->ssd_lock);
557 /***************************************
559 ***************************************/
561 static inline int gss_cli_payload(struct ptlrpc_cli_ctx *ctx,
562 int msgsize, int privacy)
564 return gss_mech_payload(NULL, msgsize, privacy);
567 static int gss_cli_bulk_payload(struct ptlrpc_cli_ctx *ctx,
568 struct sptlrpc_flavor *flvr,
571 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
573 LASSERT(SPTLRPC_FLVR_BULK_TYPE(flvr->sf_rpc) == SPTLRPC_BULK_DEFAULT);
575 if ((!reply && !read) || (reply && read)) {
576 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
577 case SPTLRPC_BULK_SVC_NULL:
579 case SPTLRPC_BULK_SVC_INTG:
580 payload += gss_cli_payload(ctx, 0, 0);
582 case SPTLRPC_BULK_SVC_PRIV:
583 payload += gss_cli_payload(ctx, 0, 1);
585 case SPTLRPC_BULK_SVC_AUTH:
594 int gss_cli_ctx_match(struct ptlrpc_cli_ctx *ctx, struct vfs_cred *vcred)
596 return (ctx->cc_vcred.vc_uid == vcred->vc_uid);
599 void gss_cli_ctx_flags2str(unsigned long flags, char *buf, int bufsize)
603 if (flags & PTLRPC_CTX_NEW)
604 strlcat(buf, "new,", bufsize);
605 if (flags & PTLRPC_CTX_UPTODATE)
606 strlcat(buf, "uptodate,", bufsize);
607 if (flags & PTLRPC_CTX_DEAD)
608 strlcat(buf, "dead,", bufsize);
609 if (flags & PTLRPC_CTX_ERROR)
610 strlcat(buf, "error,", bufsize);
611 if (flags & PTLRPC_CTX_CACHED)
612 strlcat(buf, "cached,", bufsize);
613 if (flags & PTLRPC_CTX_ETERNAL)
614 strlcat(buf, "eternal,", bufsize);
616 strlcat(buf, "-,", bufsize);
619 int gss_cli_ctx_sign(struct ptlrpc_cli_ctx *ctx,
620 struct ptlrpc_request *req)
622 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
623 __u32 flags = 0, seq, svc;
627 LASSERT(req->rq_reqbuf);
628 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
629 LASSERT(req->rq_cli_ctx == ctx);
631 /* nothing to do for context negotiation RPCs */
632 if (req->rq_ctx_init)
635 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
636 if (req->rq_pack_bulk)
637 flags |= LUSTRE_GSS_PACK_BULK;
638 if (req->rq_pack_udesc)
639 flags |= LUSTRE_GSS_PACK_USER;
642 seq = atomic_inc_return(&gctx->gc_seq);
644 rc = gss_sign_msg(req->rq_reqbuf, gctx->gc_mechctx,
645 ctx->cc_sec->ps_part,
646 flags, gctx->gc_proc, seq, svc,
651 /* gss_sign_msg() msg might take long time to finish, in which period
652 * more rpcs could be wrapped up and sent out. if we found too many
653 * of them we should repack this rpc, because sent it too late might
654 * lead to the sequence number fall behind the window on server and
655 * be dropped. also applies to gss_cli_ctx_seal().
657 * Note: null mode doesn't check sequence number. */
658 if (svc != SPTLRPC_SVC_NULL &&
659 atomic_read(&gctx->gc_seq) - seq > GSS_SEQ_REPACK_THRESHOLD) {
660 int behind = atomic_read(&gctx->gc_seq) - seq;
662 gss_stat_oos_record_cli(behind);
663 CWARN("req %p: %u behind, retry signing\n", req, behind);
667 req->rq_reqdata_len = rc;
672 int gss_cli_ctx_handle_err_notify(struct ptlrpc_cli_ctx *ctx,
673 struct ptlrpc_request *req,
674 struct gss_header *ghdr)
676 struct gss_err_header *errhdr;
679 LASSERT(ghdr->gh_proc == PTLRPC_GSS_PROC_ERR);
681 errhdr = (struct gss_err_header *) ghdr;
683 CWARN("req x%llu/t%llu, ctx %p idx %#llx(%u->%s): "
684 "%sserver respond (%08x/%08x)\n",
685 req->rq_xid, req->rq_transno, ctx,
686 gss_handle_to_u64(&ctx2gctx(ctx)->gc_handle),
687 ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec),
688 sec_is_reverse(ctx->cc_sec) ? "reverse" : "",
689 errhdr->gh_major, errhdr->gh_minor);
691 /* context fini rpc, let it failed */
692 if (req->rq_ctx_fini) {
693 CWARN("context fini rpc failed\n");
697 /* reverse sec, just return error, don't expire this ctx because it's
698 * crucial to callback rpcs. note if the callback rpc failed because
699 * of bit flip during network transfer, the client will be evicted
700 * directly. so more gracefully we probably want let it retry for
701 * number of times. */
702 if (sec_is_reverse(ctx->cc_sec))
705 if (errhdr->gh_major != GSS_S_NO_CONTEXT &&
706 errhdr->gh_major != GSS_S_BAD_SIG)
709 /* server return NO_CONTEXT might be caused by context expire
710 * or server reboot/failover. we try to refresh a new ctx which
711 * be transparent to upper layer.
713 * In some cases, our gss handle is possible to be incidentally
714 * identical to another handle since the handle itself is not
715 * fully random. In krb5 case, the GSS_S_BAD_SIG will be
716 * returned, maybe other gss error for other mechanism.
718 * if we add new mechanism, make sure the correct error are
719 * returned in this case. */
720 CWARN("%s: server might lost the context, retrying\n",
721 errhdr->gh_major == GSS_S_NO_CONTEXT ? "NO_CONTEXT" : "BAD_SIG");
723 sptlrpc_cli_ctx_expire(ctx);
725 /* we need replace the ctx right here, otherwise during
726 * resent we'll hit the logic in sptlrpc_req_refresh_ctx()
727 * which keep the ctx with RESEND flag, thus we'll never
728 * get rid of this ctx. */
729 rc = sptlrpc_req_replace_dead_ctx(req);
736 int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
737 struct ptlrpc_request *req)
739 struct gss_cli_ctx *gctx;
740 struct gss_header *ghdr, *reqhdr;
741 struct lustre_msg *msg = req->rq_repdata;
743 int pack_bulk, swabbed, rc = 0;
746 LASSERT(req->rq_cli_ctx == ctx);
749 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
751 /* special case for context negotiation, rq_repmsg/rq_replen actually
752 * are not used currently. but early reply always be treated normally */
753 if (req->rq_ctx_init && !req->rq_early) {
754 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
755 req->rq_replen = msg->lm_buflens[1];
759 if (msg->lm_bufcount < 2 || msg->lm_bufcount > 4) {
760 CERROR("unexpected bufcount %u\n", msg->lm_bufcount);
764 swabbed = ptlrpc_rep_need_swab(req);
766 ghdr = gss_swab_header(msg, 0, swabbed);
768 CERROR("can't decode gss header\n");
773 reqhdr = lustre_msg_buf(msg, 0, sizeof(*reqhdr));
776 if (ghdr->gh_version != reqhdr->gh_version) {
777 CERROR("gss version %u mismatch, expect %u\n",
778 ghdr->gh_version, reqhdr->gh_version);
782 switch (ghdr->gh_proc) {
783 case PTLRPC_GSS_PROC_DATA:
784 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
786 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
787 CERROR("%s bulk flag in reply\n",
788 req->rq_pack_bulk ? "missing" : "unexpected");
792 if (ghdr->gh_seq != reqhdr->gh_seq) {
793 CERROR("seqnum %u mismatch, expect %u\n",
794 ghdr->gh_seq, reqhdr->gh_seq);
798 if (ghdr->gh_svc != reqhdr->gh_svc) {
799 CERROR("svc %u mismatch, expect %u\n",
800 ghdr->gh_svc, reqhdr->gh_svc);
805 gss_header_swabber(ghdr);
807 major = gss_verify_msg(msg, gctx->gc_mechctx, reqhdr->gh_svc);
808 if (major != GSS_S_COMPLETE) {
809 CERROR("failed to verify reply: %x\n", major);
813 if (req->rq_early && reqhdr->gh_svc == SPTLRPC_SVC_NULL) {
816 cksum = crc32_le(!(__u32) 0,
817 lustre_msg_buf(msg, 1, 0),
818 lustre_msg_buflen(msg, 1));
819 if (cksum != msg->lm_cksum) {
820 CWARN("early reply checksum mismatch: "
821 "%08x != %08x\n", cksum, msg->lm_cksum);
827 /* bulk checksum is right after the lustre msg */
828 if (msg->lm_bufcount < 3) {
829 CERROR("Invalid reply bufcount %u\n",
834 rc = bulk_sec_desc_unpack(msg, 2, swabbed);
836 CERROR("unpack bulk desc: %d\n", rc);
841 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
842 req->rq_replen = msg->lm_buflens[1];
844 case PTLRPC_GSS_PROC_ERR:
846 CERROR("server return error with early reply\n");
849 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
853 CERROR("unknown gss proc %d\n", ghdr->gh_proc);
860 int gss_cli_ctx_seal(struct ptlrpc_cli_ctx *ctx,
861 struct ptlrpc_request *req)
863 struct gss_cli_ctx *gctx;
864 rawobj_t hdrobj, msgobj, token;
865 struct gss_header *ghdr;
866 __u32 buflens[2], major;
870 LASSERT(req->rq_clrbuf);
871 LASSERT(req->rq_cli_ctx == ctx);
872 LASSERT(req->rq_reqlen);
874 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
876 /* final clear data length */
877 req->rq_clrdata_len = lustre_msg_size_v2(req->rq_clrbuf->lm_bufcount,
878 req->rq_clrbuf->lm_buflens);
880 /* calculate wire data length */
881 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
882 buflens[1] = gss_cli_payload(&gctx->gc_base, req->rq_clrdata_len, 1);
883 wiresize = lustre_msg_size_v2(2, buflens);
885 /* allocate wire buffer */
888 LASSERT(req->rq_reqbuf);
889 LASSERT(req->rq_reqbuf != req->rq_clrbuf);
890 LASSERT(req->rq_reqbuf_len >= wiresize);
892 OBD_ALLOC_LARGE(req->rq_reqbuf, wiresize);
895 req->rq_reqbuf_len = wiresize;
898 lustre_init_msg_v2(req->rq_reqbuf, 2, buflens, NULL);
899 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
902 ghdr = lustre_msg_buf(req->rq_reqbuf, 0, 0);
903 ghdr->gh_version = PTLRPC_GSS_VERSION;
904 ghdr->gh_sp = (__u8) ctx->cc_sec->ps_part;
906 ghdr->gh_proc = gctx->gc_proc;
907 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
908 ghdr->gh_handle.len = gctx->gc_handle.len;
909 memcpy(ghdr->gh_handle.data, gctx->gc_handle.data, gctx->gc_handle.len);
910 if (req->rq_pack_bulk)
911 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
912 if (req->rq_pack_udesc)
913 ghdr->gh_flags |= LUSTRE_GSS_PACK_USER;
916 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
919 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
920 hdrobj.data = (__u8 *) ghdr;
921 msgobj.len = req->rq_clrdata_len;
922 msgobj.data = (__u8 *) req->rq_clrbuf;
923 token.len = lustre_msg_buflen(req->rq_reqbuf, 1);
924 token.data = lustre_msg_buf(req->rq_reqbuf, 1, 0);
926 major = lgss_wrap(gctx->gc_mechctx, &hdrobj, &msgobj,
927 req->rq_clrbuf_len, &token);
928 if (major != GSS_S_COMPLETE) {
929 CERROR("priv: wrap message error: %08x\n", major);
930 GOTO(err_free, rc = -EPERM);
932 LASSERT(token.len <= buflens[1]);
934 /* see explain in gss_cli_ctx_sign() */
935 if (unlikely(atomic_read(&gctx->gc_seq) - ghdr->gh_seq >
936 GSS_SEQ_REPACK_THRESHOLD)) {
937 int behind = atomic_read(&gctx->gc_seq) - ghdr->gh_seq;
939 gss_stat_oos_record_cli(behind);
940 CWARN("req %p: %u behind, retry sealing\n", req, behind);
942 ghdr->gh_seq = atomic_inc_return(&gctx->gc_seq);
946 /* now set the final wire data length */
947 req->rq_reqdata_len = lustre_shrink_msg(req->rq_reqbuf, 1, token.len,0);
952 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
953 req->rq_reqbuf = NULL;
954 req->rq_reqbuf_len = 0;
959 int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
960 struct ptlrpc_request *req)
962 struct gss_cli_ctx *gctx;
963 struct gss_header *ghdr;
964 struct lustre_msg *msg = req->rq_repdata;
965 int msglen, pack_bulk, swabbed, rc;
969 LASSERT(req->rq_cli_ctx == ctx);
970 LASSERT(req->rq_ctx_init == 0);
973 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
974 swabbed = ptlrpc_rep_need_swab(req);
976 ghdr = gss_swab_header(msg, 0, swabbed);
978 CERROR("can't decode gss header\n");
983 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
984 CERROR("gss version %u mismatch, expect %u\n",
985 ghdr->gh_version, PTLRPC_GSS_VERSION);
989 switch (ghdr->gh_proc) {
990 case PTLRPC_GSS_PROC_DATA:
991 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
993 if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
994 CERROR("%s bulk flag in reply\n",
995 req->rq_pack_bulk ? "missing" : "unexpected");
1000 gss_header_swabber(ghdr);
1002 /* use rq_repdata_len as buffer size, which assume unseal
1003 * doesn't need extra memory space. for precise control, we'd
1004 * better calculate out actual buffer size as
1005 * (repbuf_len - offset - repdata_len) */
1006 major = gss_unseal_msg(gctx->gc_mechctx, msg,
1007 &msglen, req->rq_repdata_len);
1008 if (major != GSS_S_COMPLETE) {
1009 CERROR("failed to unwrap reply: %x\n", major);
1014 swabbed = __lustre_unpack_msg(msg, msglen);
1016 CERROR("Failed to unpack after decryption\n");
1020 if (msg->lm_bufcount < 1) {
1021 CERROR("Invalid reply buffer: empty\n");
1026 if (msg->lm_bufcount < 2) {
1027 CERROR("bufcount %u: missing bulk sec desc\n",
1032 /* bulk checksum is the last segment */
1033 if (bulk_sec_desc_unpack(msg, msg->lm_bufcount - 1,
1038 req->rq_repmsg = lustre_msg_buf(msg, 0, 0);
1039 req->rq_replen = msg->lm_buflens[0];
1043 case PTLRPC_GSS_PROC_ERR:
1044 if (req->rq_early) {
1045 CERROR("server return error with early reply\n");
1048 rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
1052 CERROR("unexpected proc %d\n", ghdr->gh_proc);
1059 /*********************************************
1060 * reverse context installation *
1061 *********************************************/
1064 int gss_install_rvs_svc_ctx(struct obd_import *imp,
1065 struct gss_sec *gsec,
1066 struct gss_cli_ctx *gctx)
1068 return gss_svc_upcall_install_rvs_ctx(imp, gsec, gctx);
1071 /*********************************************
1072 * GSS security APIs *
1073 *********************************************/
1074 int gss_sec_create_common(struct gss_sec *gsec,
1075 struct ptlrpc_sec_policy *policy,
1076 struct obd_import *imp,
1077 struct ptlrpc_svc_ctx *svcctx,
1078 struct sptlrpc_flavor *sf)
1080 struct ptlrpc_sec *sec;
1083 LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_GSS);
1085 gsec->gs_mech = lgss_subflavor_to_mech(
1086 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1087 if (!gsec->gs_mech) {
1088 CERROR("gss backend 0x%x not found\n",
1089 SPTLRPC_FLVR_BASE_SUB(sf->sf_rpc));
1093 spin_lock_init(&gsec->gs_lock);
1094 gsec->gs_rvs_hdl = 0ULL;
1096 /* initialize upper ptlrpc_sec */
1097 sec = &gsec->gs_base;
1098 sec->ps_policy = policy;
1099 atomic_set(&sec->ps_refcount, 0);
1100 atomic_set(&sec->ps_nctx, 0);
1101 sec->ps_id = sptlrpc_get_next_secid();
1103 sec->ps_import = class_import_get(imp);
1104 spin_lock_init(&sec->ps_lock);
1105 INIT_LIST_HEAD(&sec->ps_gc_list);
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);
1140 if (SPTLRPC_FLVR_BULK_SVC(sec->ps_flvr.sf_rpc) == SPTLRPC_BULK_SVC_PRIV)
1141 sptlrpc_enc_pool_del_user();
1146 void gss_sec_kill(struct ptlrpc_sec *sec)
1151 int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
1152 struct ptlrpc_cli_ctx *ctx,
1153 struct ptlrpc_ctx_ops *ctxops,
1154 struct vfs_cred *vcred)
1156 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1159 atomic_set(&gctx->gc_seq, 0);
1161 INIT_HLIST_NODE(&ctx->cc_cache);
1162 atomic_set(&ctx->cc_refcount, 0);
1164 ctx->cc_ops = ctxops;
1166 ctx->cc_flags = PTLRPC_CTX_NEW;
1167 ctx->cc_vcred = *vcred;
1168 spin_lock_init(&ctx->cc_lock);
1169 INIT_LIST_HEAD(&ctx->cc_req_list);
1170 INIT_LIST_HEAD(&ctx->cc_gc_chain);
1172 /* take a ref on belonging sec, balanced in ctx destroying */
1173 atomic_inc(&sec->ps_refcount);
1174 /* statistic only */
1175 atomic_inc(&sec->ps_nctx);
1177 CDEBUG(D_SEC, "%s@%p: create ctx %p(%u->%s)\n",
1178 sec->ps_policy->sp_name, ctx->cc_sec,
1179 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1185 * 1: the context has been taken care of by someone else
1186 * 0: proceed to really destroy the context locally
1188 int gss_cli_ctx_fini_common(struct ptlrpc_sec *sec,
1189 struct ptlrpc_cli_ctx *ctx)
1191 struct gss_cli_ctx *gctx = ctx2gctx(ctx);
1193 LASSERT(atomic_read(&sec->ps_nctx) > 0);
1194 LASSERT(atomic_read(&ctx->cc_refcount) == 0);
1195 LASSERT(ctx->cc_sec == sec);
1198 * remove UPTODATE flag of reverse ctx thus we won't send fini rpc,
1199 * this is to avoid potential problems of client side reverse svc ctx
1200 * be mis-destroyed in various recovery senarios. anyway client can
1201 * manage its reverse ctx well by associating it with its buddy ctx.
1203 if (sec_is_reverse(sec))
1204 ctx->cc_flags &= ~PTLRPC_CTX_UPTODATE;
1206 if (gctx->gc_mechctx) {
1207 /* the final context fini rpc will use this ctx too, and it's
1208 * asynchronous which finished by request_out_callback(). so
1209 * we add refcount, whoever drop finally drop the refcount to
1210 * 0 should responsible for the rest of destroy. */
1211 atomic_inc(&ctx->cc_refcount);
1213 gss_do_ctx_fini_rpc(gctx);
1214 gss_cli_ctx_finalize(gctx);
1216 if (!atomic_dec_and_test(&ctx->cc_refcount))
1220 if (sec_is_reverse(sec))
1221 CWARN("reverse sec %p: destroy ctx %p\n",
1224 CWARN("%s@%p: destroy ctx %p(%u->%s)\n",
1225 sec->ps_policy->sp_name, ctx->cc_sec,
1226 ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
1232 int gss_alloc_reqbuf_intg(struct ptlrpc_sec *sec,
1233 struct ptlrpc_request *req,
1234 int svc, int msgsize)
1236 int bufsize, txtsize;
1242 * on-wire data layout:
1245 * - user descriptor (optional)
1246 * - bulk sec descriptor (optional)
1247 * - signature (optional)
1248 * - svc == NULL: NULL
1249 * - svc == AUTH: signature of gss header
1250 * - svc == INTG: signature of all above
1252 * if this is context negotiation, reserver fixed space
1253 * at the last (signature) segment regardless of svc mode.
1256 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1257 txtsize = buflens[0];
1259 buflens[1] = msgsize;
1260 if (svc == SPTLRPC_SVC_INTG)
1261 txtsize += buflens[1];
1263 if (req->rq_pack_udesc) {
1264 buflens[bufcnt] = sptlrpc_current_user_desc_size();
1265 if (svc == SPTLRPC_SVC_INTG)
1266 txtsize += buflens[bufcnt];
1270 if (req->rq_pack_bulk) {
1271 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1273 0, req->rq_bulk_read);
1274 if (svc == SPTLRPC_SVC_INTG)
1275 txtsize += buflens[bufcnt];
1279 if (req->rq_ctx_init)
1280 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1281 else if (svc != SPTLRPC_SVC_NULL)
1282 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1284 bufsize = lustre_msg_size_v2(bufcnt, buflens);
1286 if (!req->rq_reqbuf) {
1287 bufsize = size_roundup_power2(bufsize);
1289 OBD_ALLOC_LARGE(req->rq_reqbuf, bufsize);
1290 if (!req->rq_reqbuf)
1293 req->rq_reqbuf_len = bufsize;
1295 LASSERT(req->rq_pool);
1296 LASSERT(req->rq_reqbuf_len >= bufsize);
1297 memset(req->rq_reqbuf, 0, bufsize);
1300 lustre_init_msg_v2(req->rq_reqbuf, bufcnt, buflens, NULL);
1301 req->rq_reqbuf->lm_secflvr = req->rq_flvr.sf_rpc;
1303 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, msgsize);
1304 LASSERT(req->rq_reqmsg);
1306 /* pack user desc here, later we might leave current user's process */
1307 if (req->rq_pack_udesc)
1308 sptlrpc_pack_user_desc(req->rq_reqbuf, 2);
1314 int gss_alloc_reqbuf_priv(struct ptlrpc_sec *sec,
1315 struct ptlrpc_request *req,
1318 __u32 ibuflens[3], wbuflens[2];
1320 int clearsize, wiresize;
1323 LASSERT(req->rq_clrbuf == NULL);
1324 LASSERT(req->rq_clrbuf_len == 0);
1326 /* Inner (clear) buffers
1328 * - user descriptor (optional)
1329 * - bulk checksum (optional)
1332 ibuflens[0] = msgsize;
1334 if (req->rq_pack_udesc)
1335 ibuflens[ibufcnt++] = sptlrpc_current_user_desc_size();
1336 if (req->rq_pack_bulk)
1337 ibuflens[ibufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1341 clearsize = lustre_msg_size_v2(ibufcnt, ibuflens);
1342 /* to allow append padding during encryption */
1343 clearsize += GSS_MAX_CIPHER_BLOCK;
1345 /* Wrapper (wire) buffers
1349 wbuflens[0] = PTLRPC_GSS_HEADER_SIZE;
1350 wbuflens[1] = gss_cli_payload(req->rq_cli_ctx, clearsize, 1);
1351 wiresize = lustre_msg_size_v2(2, wbuflens);
1354 /* rq_reqbuf is preallocated */
1355 LASSERT(req->rq_reqbuf);
1356 LASSERT(req->rq_reqbuf_len >= wiresize);
1358 memset(req->rq_reqbuf, 0, req->rq_reqbuf_len);
1360 /* if the pre-allocated buffer is big enough, we just pack
1361 * both clear buf & request buf in it, to avoid more alloc. */
1362 if (clearsize + wiresize <= req->rq_reqbuf_len) {
1364 (void *) (((char *) req->rq_reqbuf) + wiresize);
1366 CWARN("pre-allocated buf size %d is not enough for "
1367 "both clear (%d) and cipher (%d) text, proceed "
1368 "with extra allocation\n", req->rq_reqbuf_len,
1369 clearsize, wiresize);
1373 if (!req->rq_clrbuf) {
1374 clearsize = size_roundup_power2(clearsize);
1376 OBD_ALLOC_LARGE(req->rq_clrbuf, clearsize);
1377 if (!req->rq_clrbuf)
1380 req->rq_clrbuf_len = clearsize;
1382 lustre_init_msg_v2(req->rq_clrbuf, ibufcnt, ibuflens, NULL);
1383 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, msgsize);
1385 if (req->rq_pack_udesc)
1386 sptlrpc_pack_user_desc(req->rq_clrbuf, 1);
1392 * NOTE: any change of request buffer allocation should also consider
1393 * changing enlarge_reqbuf() series functions.
1395 int gss_alloc_reqbuf(struct ptlrpc_sec *sec,
1396 struct ptlrpc_request *req,
1399 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1401 LASSERT(!req->rq_pack_bulk ||
1402 (req->rq_bulk_read || req->rq_bulk_write));
1405 case SPTLRPC_SVC_NULL:
1406 case SPTLRPC_SVC_AUTH:
1407 case SPTLRPC_SVC_INTG:
1408 return gss_alloc_reqbuf_intg(sec, req, svc, msgsize);
1409 case SPTLRPC_SVC_PRIV:
1410 return gss_alloc_reqbuf_priv(sec, req, msgsize);
1412 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1417 void gss_free_reqbuf(struct ptlrpc_sec *sec,
1418 struct ptlrpc_request *req)
1423 LASSERT(!req->rq_pool || req->rq_reqbuf);
1424 privacy = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc) == SPTLRPC_SVC_PRIV;
1426 if (!req->rq_clrbuf)
1427 goto release_reqbuf;
1429 /* release clear buffer */
1431 LASSERT(req->rq_clrbuf_len);
1433 if (req->rq_pool == NULL ||
1434 req->rq_clrbuf < req->rq_reqbuf ||
1435 (char *) req->rq_clrbuf >=
1436 (char *) req->rq_reqbuf + req->rq_reqbuf_len)
1437 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1439 req->rq_clrbuf = NULL;
1440 req->rq_clrbuf_len = 0;
1443 if (!req->rq_pool && req->rq_reqbuf) {
1444 LASSERT(req->rq_reqbuf_len);
1446 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1447 req->rq_reqbuf = NULL;
1448 req->rq_reqbuf_len = 0;
1454 static int do_alloc_repbuf(struct ptlrpc_request *req, int bufsize)
1456 bufsize = size_roundup_power2(bufsize);
1458 OBD_ALLOC_LARGE(req->rq_repbuf, bufsize);
1459 if (!req->rq_repbuf)
1462 req->rq_repbuf_len = bufsize;
1467 int gss_alloc_repbuf_intg(struct ptlrpc_sec *sec,
1468 struct ptlrpc_request *req,
1469 int svc, int msgsize)
1477 * on-wire data layout:
1480 * - bulk sec descriptor (optional)
1481 * - signature (optional)
1482 * - svc == NULL: NULL
1483 * - svc == AUTH: signature of gss header
1484 * - svc == INTG: signature of all above
1486 * if this is context negotiation, reserver fixed space
1487 * at the last (signature) segment regardless of svc mode.
1490 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1491 txtsize = buflens[0];
1493 buflens[1] = msgsize;
1494 if (svc == SPTLRPC_SVC_INTG)
1495 txtsize += buflens[1];
1497 if (req->rq_pack_bulk) {
1498 buflens[bufcnt] = gss_cli_bulk_payload(req->rq_cli_ctx,
1500 1, req->rq_bulk_read);
1501 if (svc == SPTLRPC_SVC_INTG)
1502 txtsize += buflens[bufcnt];
1506 if (req->rq_ctx_init)
1507 buflens[bufcnt++] = GSS_CTX_INIT_MAX_LEN;
1508 else if (svc != SPTLRPC_SVC_NULL)
1509 buflens[bufcnt++] = gss_cli_payload(req->rq_cli_ctx, txtsize,0);
1511 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1513 /* add space for early reply */
1514 alloc_size += gss_at_reply_off_integ;
1516 return do_alloc_repbuf(req, alloc_size);
1520 int gss_alloc_repbuf_priv(struct ptlrpc_sec *sec,
1521 struct ptlrpc_request *req,
1531 buflens[0] = msgsize;
1533 if (req->rq_pack_bulk)
1534 buflens[bufcnt++] = gss_cli_bulk_payload(req->rq_cli_ctx,
1536 1, req->rq_bulk_read);
1537 txtsize = lustre_msg_size_v2(bufcnt, buflens);
1538 txtsize += GSS_MAX_CIPHER_BLOCK;
1540 /* wrapper buffers */
1542 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1543 buflens[1] = gss_cli_payload(req->rq_cli_ctx, txtsize, 1);
1545 alloc_size = lustre_msg_size_v2(bufcnt, buflens);
1546 /* add space for early reply */
1547 alloc_size += gss_at_reply_off_priv;
1549 return do_alloc_repbuf(req, alloc_size);
1552 int gss_alloc_repbuf(struct ptlrpc_sec *sec,
1553 struct ptlrpc_request *req,
1556 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1559 LASSERT(!req->rq_pack_bulk ||
1560 (req->rq_bulk_read || req->rq_bulk_write));
1563 case SPTLRPC_SVC_NULL:
1564 case SPTLRPC_SVC_AUTH:
1565 case SPTLRPC_SVC_INTG:
1566 return gss_alloc_repbuf_intg(sec, req, svc, msgsize);
1567 case SPTLRPC_SVC_PRIV:
1568 return gss_alloc_repbuf_priv(sec, req, msgsize);
1570 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1575 void gss_free_repbuf(struct ptlrpc_sec *sec,
1576 struct ptlrpc_request *req)
1578 OBD_FREE_LARGE(req->rq_repbuf, req->rq_repbuf_len);
1579 req->rq_repbuf = NULL;
1580 req->rq_repbuf_len = 0;
1581 req->rq_repdata = NULL;
1582 req->rq_repdata_len = 0;
1585 static int get_enlarged_msgsize(struct lustre_msg *msg,
1586 int segment, int newsize)
1588 int save, newmsg_size;
1590 LASSERT(newsize >= msg->lm_buflens[segment]);
1592 save = msg->lm_buflens[segment];
1593 msg->lm_buflens[segment] = newsize;
1594 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1595 msg->lm_buflens[segment] = save;
1600 static int get_enlarged_msgsize2(struct lustre_msg *msg,
1601 int segment1, int newsize1,
1602 int segment2, int newsize2)
1604 int save1, save2, newmsg_size;
1606 LASSERT(newsize1 >= msg->lm_buflens[segment1]);
1607 LASSERT(newsize2 >= msg->lm_buflens[segment2]);
1609 save1 = msg->lm_buflens[segment1];
1610 save2 = msg->lm_buflens[segment2];
1611 msg->lm_buflens[segment1] = newsize1;
1612 msg->lm_buflens[segment2] = newsize2;
1613 newmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1614 msg->lm_buflens[segment1] = save1;
1615 msg->lm_buflens[segment2] = save2;
1621 int gss_enlarge_reqbuf_intg(struct ptlrpc_sec *sec,
1622 struct ptlrpc_request *req,
1624 int segment, int newsize)
1626 struct lustre_msg *newbuf;
1627 int txtsize, sigsize = 0, i;
1628 int newmsg_size, newbuf_size;
1631 * gss header is at seg 0;
1632 * embedded msg is at seg 1;
1633 * signature (if any) is at the last seg
1635 LASSERT(req->rq_reqbuf);
1636 LASSERT(req->rq_reqbuf_len > req->rq_reqlen);
1637 LASSERT(req->rq_reqbuf->lm_bufcount >= 2);
1638 LASSERT(lustre_msg_buf(req->rq_reqbuf, 1, 0) == req->rq_reqmsg);
1640 /* 1. compute new embedded msg size */
1641 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1642 LASSERT(newmsg_size >= req->rq_reqbuf->lm_buflens[1]);
1644 /* 2. compute new wrapper msg size */
1645 if (svc == SPTLRPC_SVC_NULL) {
1646 /* no signature, get size directly */
1647 newbuf_size = get_enlarged_msgsize(req->rq_reqbuf,
1650 txtsize = req->rq_reqbuf->lm_buflens[0];
1652 if (svc == SPTLRPC_SVC_INTG) {
1653 for (i = 1; i < req->rq_reqbuf->lm_bufcount; i++)
1654 txtsize += req->rq_reqbuf->lm_buflens[i];
1655 txtsize += newmsg_size - req->rq_reqbuf->lm_buflens[1];
1658 sigsize = gss_cli_payload(req->rq_cli_ctx, txtsize, 0);
1659 LASSERT(sigsize >= msg_last_seglen(req->rq_reqbuf));
1661 newbuf_size = get_enlarged_msgsize2(
1664 msg_last_segidx(req->rq_reqbuf),
1668 /* request from pool should always have enough buffer */
1669 LASSERT(!req->rq_pool || req->rq_reqbuf_len >= newbuf_size);
1671 if (req->rq_reqbuf_len < newbuf_size) {
1672 newbuf_size = size_roundup_power2(newbuf_size);
1674 OBD_ALLOC_LARGE(newbuf, newbuf_size);
1678 /* Must lock this, so that otherwise unprotected change of
1679 * rq_reqmsg is not racing with parallel processing of
1680 * imp_replay_list traversing threads. See LU-3333
1681 * This is a bandaid at best, we really need to deal with this
1682 * in request enlarging code before unpacking that's already
1685 spin_lock(&req->rq_import->imp_lock);
1687 memcpy(newbuf, req->rq_reqbuf, req->rq_reqbuf_len);
1689 OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len);
1690 req->rq_reqbuf = newbuf;
1691 req->rq_reqbuf_len = newbuf_size;
1692 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 1, 0);
1695 spin_unlock(&req->rq_import->imp_lock);
1698 /* do enlargement, from wrapper to embedded, from end to begin */
1699 if (svc != SPTLRPC_SVC_NULL)
1700 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf,
1701 msg_last_segidx(req->rq_reqbuf),
1704 _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf, 1, newmsg_size);
1705 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1707 req->rq_reqlen = newmsg_size;
1712 int gss_enlarge_reqbuf_priv(struct ptlrpc_sec *sec,
1713 struct ptlrpc_request *req,
1714 int segment, int newsize)
1716 struct lustre_msg *newclrbuf;
1717 int newmsg_size, newclrbuf_size, newcipbuf_size;
1721 * embedded msg is at seg 0 of clear buffer;
1722 * cipher text is at seg 2 of cipher buffer;
1724 LASSERT(req->rq_pool ||
1725 (req->rq_reqbuf == NULL && req->rq_reqbuf_len == 0));
1726 LASSERT(req->rq_reqbuf == NULL ||
1727 (req->rq_pool && req->rq_reqbuf->lm_bufcount == 3));
1728 LASSERT(req->rq_clrbuf);
1729 LASSERT(req->rq_clrbuf_len > req->rq_reqlen);
1730 LASSERT(lustre_msg_buf(req->rq_clrbuf, 0, 0) == req->rq_reqmsg);
1732 /* compute new embedded msg size */
1733 newmsg_size = get_enlarged_msgsize(req->rq_reqmsg, segment, newsize);
1735 /* compute new clear buffer size */
1736 newclrbuf_size = get_enlarged_msgsize(req->rq_clrbuf, 0, newmsg_size);
1737 newclrbuf_size += GSS_MAX_CIPHER_BLOCK;
1739 /* compute new cipher buffer size */
1740 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
1741 buflens[1] = gss_cli_payload(req->rq_cli_ctx, buflens[0], 0);
1742 buflens[2] = gss_cli_payload(req->rq_cli_ctx, newclrbuf_size, 1);
1743 newcipbuf_size = lustre_msg_size_v2(3, buflens);
1745 /* handle the case that we put both clear buf and cipher buf into
1746 * pre-allocated single buffer. */
1747 if (unlikely(req->rq_pool) &&
1748 req->rq_clrbuf >= req->rq_reqbuf &&
1749 (char *) req->rq_clrbuf <
1750 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1751 /* it couldn't be better we still fit into the
1752 * pre-allocated buffer. */
1753 if (newclrbuf_size + newcipbuf_size <= req->rq_reqbuf_len) {
1757 spin_lock(&req->rq_import->imp_lock);
1758 /* move clear text backward. */
1759 src = req->rq_clrbuf;
1760 dst = (char *) req->rq_reqbuf + newcipbuf_size;
1762 memmove(dst, src, req->rq_clrbuf_len);
1764 req->rq_clrbuf = (struct lustre_msg *) dst;
1765 req->rq_clrbuf_len = newclrbuf_size;
1766 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1769 spin_unlock(&req->rq_import->imp_lock);
1771 /* sadly we have to split out the clear buffer */
1772 LASSERT(req->rq_reqbuf_len >= newcipbuf_size);
1773 LASSERT(req->rq_clrbuf_len < newclrbuf_size);
1777 if (req->rq_clrbuf_len < newclrbuf_size) {
1778 newclrbuf_size = size_roundup_power2(newclrbuf_size);
1780 OBD_ALLOC_LARGE(newclrbuf, newclrbuf_size);
1781 if (newclrbuf == NULL)
1784 /* Must lock this, so that otherwise unprotected change of
1785 * rq_reqmsg is not racing with parallel processing of
1786 * imp_replay_list traversing threads. See LU-3333
1787 * This is a bandaid at best, we really need to deal with this
1788 * in request enlarging code before unpacking that's already
1791 spin_lock(&req->rq_import->imp_lock);
1793 memcpy(newclrbuf, req->rq_clrbuf, req->rq_clrbuf_len);
1795 if (req->rq_reqbuf == NULL ||
1796 req->rq_clrbuf < req->rq_reqbuf ||
1797 (char *) req->rq_clrbuf >=
1798 (char *) req->rq_reqbuf + req->rq_reqbuf_len) {
1799 OBD_FREE_LARGE(req->rq_clrbuf, req->rq_clrbuf_len);
1802 req->rq_clrbuf = newclrbuf;
1803 req->rq_clrbuf_len = newclrbuf_size;
1804 req->rq_reqmsg = lustre_msg_buf(req->rq_clrbuf, 0, 0);
1807 spin_unlock(&req->rq_import->imp_lock);
1810 _sptlrpc_enlarge_msg_inplace(req->rq_clrbuf, 0, newmsg_size);
1811 _sptlrpc_enlarge_msg_inplace(req->rq_reqmsg, segment, newsize);
1812 req->rq_reqlen = newmsg_size;
1817 int gss_enlarge_reqbuf(struct ptlrpc_sec *sec,
1818 struct ptlrpc_request *req,
1819 int segment, int newsize)
1821 int svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
1823 LASSERT(!req->rq_ctx_init && !req->rq_ctx_fini);
1826 case SPTLRPC_SVC_NULL:
1827 case SPTLRPC_SVC_AUTH:
1828 case SPTLRPC_SVC_INTG:
1829 return gss_enlarge_reqbuf_intg(sec, req, svc, segment, newsize);
1830 case SPTLRPC_SVC_PRIV:
1831 return gss_enlarge_reqbuf_priv(sec, req, segment, newsize);
1833 LASSERTF(0, "bad rpc flavor %x\n", req->rq_flvr.sf_rpc);
1838 int gss_sec_install_rctx(struct obd_import *imp,
1839 struct ptlrpc_sec *sec,
1840 struct ptlrpc_cli_ctx *ctx)
1842 struct gss_sec *gsec;
1843 struct gss_cli_ctx *gctx;
1846 gsec = container_of(sec, struct gss_sec, gs_base);
1847 gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
1849 rc = gss_install_rvs_svc_ctx(imp, gsec, gctx);
1853 /********************************************
1855 ********************************************/
1858 int gss_svc_reqctx_is_special(struct gss_svc_reqctx *grctx)
1861 return (grctx->src_init || grctx->src_init_continue ||
1862 grctx->src_err_notify);
1866 void gss_svc_reqctx_free(struct gss_svc_reqctx *grctx)
1869 gss_svc_upcall_put_ctx(grctx->src_ctx);
1871 sptlrpc_policy_put(grctx->src_base.sc_policy);
1872 OBD_FREE_PTR(grctx);
1876 void gss_svc_reqctx_addref(struct gss_svc_reqctx *grctx)
1878 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1879 atomic_inc(&grctx->src_base.sc_refcount);
1883 void gss_svc_reqctx_decref(struct gss_svc_reqctx *grctx)
1885 LASSERT(atomic_read(&grctx->src_base.sc_refcount) > 0);
1887 if (atomic_dec_and_test(&grctx->src_base.sc_refcount))
1888 gss_svc_reqctx_free(grctx);
1892 int gss_svc_sign(struct ptlrpc_request *req,
1893 struct ptlrpc_reply_state *rs,
1894 struct gss_svc_reqctx *grctx,
1901 LASSERT(rs->rs_msg == lustre_msg_buf(rs->rs_repbuf, 1, 0));
1903 /* embedded lustre_msg might have been shrunk */
1904 if (req->rq_replen != rs->rs_repbuf->lm_buflens[1])
1905 lustre_shrink_msg(rs->rs_repbuf, 1, req->rq_replen, 1);
1907 if (req->rq_pack_bulk)
1908 flags |= LUSTRE_GSS_PACK_BULK;
1910 rc = gss_sign_msg(rs->rs_repbuf, grctx->src_ctx->gsc_mechctx,
1911 LUSTRE_SP_ANY, flags, PTLRPC_GSS_PROC_DATA,
1912 grctx->src_wirectx.gw_seq, svc, NULL);
1916 rs->rs_repdata_len = rc;
1918 if (likely(req->rq_packed_final)) {
1919 if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
1920 req->rq_reply_off = gss_at_reply_off_integ;
1922 req->rq_reply_off = 0;
1924 if (svc == SPTLRPC_SVC_NULL)
1925 rs->rs_repbuf->lm_cksum = crc32_le(!(__u32) 0,
1926 lustre_msg_buf(rs->rs_repbuf, 1, 0),
1927 lustre_msg_buflen(rs->rs_repbuf, 1));
1928 req->rq_reply_off = 0;
1934 int gss_pack_err_notify(struct ptlrpc_request *req, __u32 major, __u32 minor)
1936 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
1937 struct ptlrpc_reply_state *rs;
1938 struct gss_err_header *ghdr;
1939 int replen = sizeof(struct ptlrpc_body);
1943 //if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_SVCGSS_ERR_NOTIFY, OBD_FAIL_ONCE))
1946 grctx->src_err_notify = 1;
1947 grctx->src_reserve_len = 0;
1949 rc = lustre_pack_reply_v2(req, 1, &replen, NULL, 0);
1951 CERROR("could not pack reply, err %d\n", rc);
1956 rs = req->rq_reply_state;
1957 LASSERT(rs->rs_repbuf->lm_buflens[1] >= sizeof(*ghdr));
1958 ghdr = lustre_msg_buf(rs->rs_repbuf, 0, 0);
1959 ghdr->gh_version = PTLRPC_GSS_VERSION;
1961 ghdr->gh_proc = PTLRPC_GSS_PROC_ERR;
1962 ghdr->gh_major = major;
1963 ghdr->gh_minor = minor;
1964 ghdr->gh_handle.len = 0; /* fake context handle */
1966 rs->rs_repdata_len = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
1967 rs->rs_repbuf->lm_buflens);
1969 CDEBUG(D_SEC, "prepare gss error notify(0x%x/0x%x) to %s\n",
1970 major, minor, libcfs_nid2str(req->rq_peer.nid));
1975 int gss_svc_handle_init(struct ptlrpc_request *req,
1976 struct gss_wire_ctx *gw)
1978 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
1979 struct lustre_msg *reqbuf = req->rq_reqbuf;
1980 struct obd_uuid *uuid;
1981 struct obd_device *target;
1982 rawobj_t uuid_obj, rvs_hdl, in_token;
1984 __u32 *secdata, seclen;
1988 CDEBUG(D_SEC, "processing gss init(%d) request from %s\n", gw->gw_proc,
1989 libcfs_nid2str(req->rq_peer.nid));
1991 req->rq_ctx_init = 1;
1993 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
1994 CERROR("unexpected bulk flag\n");
1995 RETURN(SECSVC_DROP);
1998 if (gw->gw_proc == PTLRPC_GSS_PROC_INIT && gw->gw_handle.len != 0) {
1999 CERROR("proc %u: invalid handle length %u\n",
2000 gw->gw_proc, gw->gw_handle.len);
2001 RETURN(SECSVC_DROP);
2004 if (reqbuf->lm_bufcount < 3 || reqbuf->lm_bufcount > 4){
2005 CERROR("Invalid bufcount %d\n", reqbuf->lm_bufcount);
2006 RETURN(SECSVC_DROP);
2009 swabbed = ptlrpc_req_need_swab(req);
2011 /* ctx initiate payload is in last segment */
2012 secdata = lustre_msg_buf(reqbuf, reqbuf->lm_bufcount - 1, 0);
2013 seclen = reqbuf->lm_buflens[reqbuf->lm_bufcount - 1];
2015 if (seclen < 4 + 4) {
2016 CERROR("sec size %d too small\n", seclen);
2017 RETURN(SECSVC_DROP);
2020 /* lustre svc type */
2021 lustre_svc = le32_to_cpu(*secdata++);
2024 /* extract target uuid, note this code is somewhat fragile
2025 * because touched internal structure of obd_uuid */
2026 if (rawobj_extract(&uuid_obj, &secdata, &seclen)) {
2027 CERROR("failed to extract target uuid\n");
2028 RETURN(SECSVC_DROP);
2030 uuid_obj.data[uuid_obj.len - 1] = '\0';
2032 uuid = (struct obd_uuid *) uuid_obj.data;
2033 target = class_uuid2obd(uuid);
2034 if (!target || target->obd_stopping || !target->obd_set_up) {
2035 CERROR("target '%s' is not available for context init (%s)\n",
2036 uuid->uuid, target == NULL ? "no target" :
2037 (target->obd_stopping ? "stopping" : "not set up"));
2038 RETURN(SECSVC_DROP);
2041 /* extract reverse handle */
2042 if (rawobj_extract(&rvs_hdl, &secdata, &seclen)) {
2043 CERROR("failed extract reverse handle\n");
2044 RETURN(SECSVC_DROP);
2048 if (rawobj_extract(&in_token, &secdata, &seclen)) {
2049 CERROR("can't extract token\n");
2050 RETURN(SECSVC_DROP);
2053 rc = gss_svc_upcall_handle_init(req, grctx, gw, target, lustre_svc,
2054 &rvs_hdl, &in_token);
2055 if (rc != SECSVC_OK)
2058 if (grctx->src_ctx->gsc_usr_mds || grctx->src_ctx->gsc_usr_oss ||
2059 grctx->src_ctx->gsc_usr_root)
2060 CWARN("create svc ctx %p: user from %s authenticated as %s\n",
2061 grctx->src_ctx, libcfs_nid2str(req->rq_peer.nid),
2062 grctx->src_ctx->gsc_usr_mds ? "mds" :
2063 (grctx->src_ctx->gsc_usr_oss ? "oss" : "root"));
2065 CWARN("create svc ctx %p: accept user %u from %s\n",
2066 grctx->src_ctx, grctx->src_ctx->gsc_uid,
2067 libcfs_nid2str(req->rq_peer.nid));
2069 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2070 if (reqbuf->lm_bufcount < 4) {
2071 CERROR("missing user descriptor\n");
2072 RETURN(SECSVC_DROP);
2074 if (sptlrpc_unpack_user_desc(reqbuf, 2, swabbed)) {
2075 CERROR("Mal-formed user descriptor\n");
2076 RETURN(SECSVC_DROP);
2079 req->rq_pack_udesc = 1;
2080 req->rq_user_desc = lustre_msg_buf(reqbuf, 2, 0);
2083 req->rq_reqmsg = lustre_msg_buf(reqbuf, 1, 0);
2084 req->rq_reqlen = lustre_msg_buflen(reqbuf, 1);
2090 * last segment must be the gss signature.
2093 int gss_svc_verify_request(struct ptlrpc_request *req,
2094 struct gss_svc_reqctx *grctx,
2095 struct gss_wire_ctx *gw,
2098 struct gss_svc_ctx *gctx = grctx->src_ctx;
2099 struct lustre_msg *msg = req->rq_reqbuf;
2104 *major = GSS_S_COMPLETE;
2106 if (msg->lm_bufcount < 2) {
2107 CERROR("Too few segments (%u) in request\n", msg->lm_bufcount);
2111 if (gw->gw_svc == SPTLRPC_SVC_NULL)
2114 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2115 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2116 *major = GSS_S_DUPLICATE_TOKEN;
2120 *major = gss_verify_msg(msg, gctx->gsc_mechctx, gw->gw_svc);
2121 if (*major != GSS_S_COMPLETE) {
2122 CERROR("failed to verify request: %x\n", *major);
2126 if (gctx->gsc_reverse == 0 &&
2127 gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2128 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2129 *major = GSS_S_DUPLICATE_TOKEN;
2134 swabbed = ptlrpc_req_need_swab(req);
2136 /* user descriptor */
2137 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2138 if (msg->lm_bufcount < (offset + 1)) {
2139 CERROR("no user desc included\n");
2143 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2144 CERROR("Mal-formed user descriptor\n");
2148 req->rq_pack_udesc = 1;
2149 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2153 /* check bulk_sec_desc data */
2154 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2155 if (msg->lm_bufcount < (offset + 1)) {
2156 CERROR("missing bulk sec descriptor\n");
2160 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2163 req->rq_pack_bulk = 1;
2164 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2165 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2168 req->rq_reqmsg = lustre_msg_buf(msg, 1, 0);
2169 req->rq_reqlen = msg->lm_buflens[1];
2174 int gss_svc_unseal_request(struct ptlrpc_request *req,
2175 struct gss_svc_reqctx *grctx,
2176 struct gss_wire_ctx *gw,
2179 struct gss_svc_ctx *gctx = grctx->src_ctx;
2180 struct lustre_msg *msg = req->rq_reqbuf;
2181 int swabbed, msglen, offset = 1;
2184 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
2185 CERROR("phase 0: discard replayed req: seq %u\n", gw->gw_seq);
2186 *major = GSS_S_DUPLICATE_TOKEN;
2190 *major = gss_unseal_msg(gctx->gsc_mechctx, msg,
2191 &msglen, req->rq_reqdata_len);
2192 if (*major != GSS_S_COMPLETE) {
2193 CERROR("failed to unwrap request: %x\n", *major);
2197 if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 1)) {
2198 CERROR("phase 1+: discard replayed req: seq %u\n", gw->gw_seq);
2199 *major = GSS_S_DUPLICATE_TOKEN;
2203 swabbed = __lustre_unpack_msg(msg, msglen);
2205 CERROR("Failed to unpack after decryption\n");
2208 req->rq_reqdata_len = msglen;
2210 if (msg->lm_bufcount < 1) {
2211 CERROR("Invalid buffer: is empty\n");
2215 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2216 if (msg->lm_bufcount < offset + 1) {
2217 CERROR("no user descriptor included\n");
2221 if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
2222 CERROR("Mal-formed user descriptor\n");
2226 req->rq_pack_udesc = 1;
2227 req->rq_user_desc = lustre_msg_buf(msg, offset, 0);
2231 if (gw->gw_flags & LUSTRE_GSS_PACK_BULK) {
2232 if (msg->lm_bufcount < offset + 1) {
2233 CERROR("no bulk checksum included\n");
2237 if (bulk_sec_desc_unpack(msg, offset, swabbed))
2240 req->rq_pack_bulk = 1;
2241 grctx->src_reqbsd = lustre_msg_buf(msg, offset, 0);
2242 grctx->src_reqbsd_size = lustre_msg_buflen(msg, offset);
2245 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, 0, 0);
2246 req->rq_reqlen = req->rq_reqbuf->lm_buflens[0];
2251 int gss_svc_handle_data(struct ptlrpc_request *req,
2252 struct gss_wire_ctx *gw)
2254 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2259 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2260 if (!grctx->src_ctx) {
2261 major = GSS_S_NO_CONTEXT;
2265 switch (gw->gw_svc) {
2266 case SPTLRPC_SVC_NULL:
2267 case SPTLRPC_SVC_AUTH:
2268 case SPTLRPC_SVC_INTG:
2269 rc = gss_svc_verify_request(req, grctx, gw, &major);
2271 case SPTLRPC_SVC_PRIV:
2272 rc = gss_svc_unseal_request(req, grctx, gw, &major);
2275 CERROR("unsupported gss service %d\n", gw->gw_svc);
2282 CERROR("svc %u failed: major 0x%08x: req xid %llu ctx %p idx "
2283 "%#llx(%u->%s)\n", gw->gw_svc, major, req->rq_xid,
2284 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2285 grctx->src_ctx->gsc_uid, libcfs_nid2str(req->rq_peer.nid));
2287 /* we only notify client in case of NO_CONTEXT/BAD_SIG, which
2288 * might happen after server reboot, to allow recovery. */
2289 if ((major == GSS_S_NO_CONTEXT || major == GSS_S_BAD_SIG) &&
2290 gss_pack_err_notify(req, major, 0) == 0)
2291 RETURN(SECSVC_COMPLETE);
2293 RETURN(SECSVC_DROP);
2297 int gss_svc_handle_destroy(struct ptlrpc_request *req,
2298 struct gss_wire_ctx *gw)
2300 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2304 req->rq_ctx_fini = 1;
2305 req->rq_no_reply = 1;
2307 grctx->src_ctx = gss_svc_upcall_get_ctx(req, gw);
2308 if (!grctx->src_ctx) {
2309 CDEBUG(D_SEC, "invalid gss context handle for destroy.\n");
2310 RETURN(SECSVC_DROP);
2313 if (gw->gw_svc != SPTLRPC_SVC_INTG) {
2314 CERROR("svc %u is not supported in destroy.\n", gw->gw_svc);
2315 RETURN(SECSVC_DROP);
2318 if (gss_svc_verify_request(req, grctx, gw, &major))
2319 RETURN(SECSVC_DROP);
2321 CWARN("destroy svc ctx %p idx %#llx (%u->%s)\n",
2322 grctx->src_ctx, gss_handle_to_u64(&gw->gw_handle),
2323 grctx->src_ctx->gsc_uid, libcfs_nid2str(req->rq_peer.nid));
2325 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2327 if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
2328 if (req->rq_reqbuf->lm_bufcount < 4) {
2329 CERROR("missing user descriptor, ignore it\n");
2332 if (sptlrpc_unpack_user_desc(req->rq_reqbuf, 2,
2333 ptlrpc_req_need_swab(req))) {
2334 CERROR("Mal-formed user descriptor, ignore it\n");
2338 req->rq_pack_udesc = 1;
2339 req->rq_user_desc = lustre_msg_buf(req->rq_reqbuf, 2, 0);
2345 int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
2347 struct gss_header *ghdr;
2348 struct gss_svc_reqctx *grctx;
2349 struct gss_wire_ctx *gw;
2353 LASSERT(req->rq_reqbuf);
2354 LASSERT(req->rq_svc_ctx == NULL);
2356 if (req->rq_reqbuf->lm_bufcount < 2) {
2357 CERROR("buf count only %d\n", req->rq_reqbuf->lm_bufcount);
2358 RETURN(SECSVC_DROP);
2361 swabbed = ptlrpc_req_need_swab(req);
2363 ghdr = gss_swab_header(req->rq_reqbuf, 0, swabbed);
2365 CERROR("can't decode gss header\n");
2366 RETURN(SECSVC_DROP);
2370 if (ghdr->gh_version != PTLRPC_GSS_VERSION) {
2371 CERROR("gss version %u, expect %u\n", ghdr->gh_version,
2372 PTLRPC_GSS_VERSION);
2373 RETURN(SECSVC_DROP);
2376 req->rq_sp_from = ghdr->gh_sp;
2378 /* alloc grctx data */
2379 OBD_ALLOC_PTR(grctx);
2381 RETURN(SECSVC_DROP);
2383 grctx->src_base.sc_policy = sptlrpc_policy_get(policy);
2384 atomic_set(&grctx->src_base.sc_refcount, 1);
2385 req->rq_svc_ctx = &grctx->src_base;
2386 gw = &grctx->src_wirectx;
2388 /* save wire context */
2389 gw->gw_flags = ghdr->gh_flags;
2390 gw->gw_proc = ghdr->gh_proc;
2391 gw->gw_seq = ghdr->gh_seq;
2392 gw->gw_svc = ghdr->gh_svc;
2393 rawobj_from_netobj(&gw->gw_handle, &ghdr->gh_handle);
2395 /* keep original wire header which subject to checksum verification */
2397 gss_header_swabber(ghdr);
2399 switch(ghdr->gh_proc) {
2400 case PTLRPC_GSS_PROC_INIT:
2401 case PTLRPC_GSS_PROC_CONTINUE_INIT:
2402 rc = gss_svc_handle_init(req, gw);
2404 case PTLRPC_GSS_PROC_DATA:
2405 rc = gss_svc_handle_data(req, gw);
2407 case PTLRPC_GSS_PROC_DESTROY:
2408 rc = gss_svc_handle_destroy(req, gw);
2411 CERROR("unknown proc %u\n", gw->gw_proc);
2418 LASSERT (grctx->src_ctx);
2420 req->rq_auth_gss = 1;
2421 req->rq_auth_usr_mdt = grctx->src_ctx->gsc_usr_mds;
2422 req->rq_auth_usr_ost = grctx->src_ctx->gsc_usr_oss;
2423 req->rq_auth_usr_root = grctx->src_ctx->gsc_usr_root;
2424 req->rq_auth_uid = grctx->src_ctx->gsc_uid;
2425 req->rq_auth_mapped_uid = grctx->src_ctx->gsc_mapped_uid;
2427 case SECSVC_COMPLETE:
2430 gss_svc_reqctx_free(grctx);
2431 req->rq_svc_ctx = NULL;
2438 void gss_svc_invalidate_ctx(struct ptlrpc_svc_ctx *svc_ctx)
2440 struct gss_svc_reqctx *grctx;
2443 if (svc_ctx == NULL) {
2448 grctx = gss_svc_ctx2reqctx(svc_ctx);
2450 CWARN("gss svc invalidate ctx %p(%u)\n",
2451 grctx->src_ctx, grctx->src_ctx->gsc_uid);
2452 gss_svc_upcall_destroy_ctx(grctx->src_ctx);
2458 int gss_svc_payload(struct gss_svc_reqctx *grctx, int early,
2459 int msgsize, int privacy)
2461 /* we should treat early reply normally, but which is actually sharing
2462 * the same ctx with original request, so in this case we should
2463 * ignore the special ctx's special flags */
2464 if (early == 0 && gss_svc_reqctx_is_special(grctx))
2465 return grctx->src_reserve_len;
2467 return gss_mech_payload(NULL, msgsize, privacy);
2470 static int gss_svc_bulk_payload(struct gss_svc_ctx *gctx,
2471 struct sptlrpc_flavor *flvr,
2474 int payload = sizeof(struct ptlrpc_bulk_sec_desc);
2477 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
2478 case SPTLRPC_BULK_SVC_NULL:
2480 case SPTLRPC_BULK_SVC_INTG:
2481 payload += gss_mech_payload(NULL, 0, 0);
2483 case SPTLRPC_BULK_SVC_PRIV:
2484 payload += gss_mech_payload(NULL, 0, 1);
2486 case SPTLRPC_BULK_SVC_AUTH:
2495 int gss_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
2497 struct gss_svc_reqctx *grctx;
2498 struct ptlrpc_reply_state *rs;
2499 int early, privacy, svc, bsd_off = 0;
2500 __u32 ibuflens[2], buflens[4];
2501 int ibufcnt = 0, bufcnt;
2502 int txtsize, wmsg_size, rs_size;
2505 LASSERT(msglen % 8 == 0);
2507 if (req->rq_pack_bulk && !req->rq_bulk_read && !req->rq_bulk_write) {
2508 CERROR("client request bulk sec on non-bulk rpc\n");
2512 svc = SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc);
2513 early = (req->rq_packed_final == 0);
2515 grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2516 if (!early && gss_svc_reqctx_is_special(grctx))
2519 privacy = (svc == SPTLRPC_SVC_PRIV);
2522 /* inner clear buffers */
2524 ibuflens[0] = msglen;
2526 if (req->rq_pack_bulk) {
2527 LASSERT(grctx->src_reqbsd);
2530 ibuflens[ibufcnt++] = gss_svc_bulk_payload(
2536 txtsize = lustre_msg_size_v2(ibufcnt, ibuflens);
2537 txtsize += GSS_MAX_CIPHER_BLOCK;
2539 /* wrapper buffer */
2541 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2542 buflens[1] = gss_svc_payload(grctx, early, txtsize, 1);
2545 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2546 buflens[1] = msglen;
2548 txtsize = buflens[0];
2549 if (svc == SPTLRPC_SVC_INTG)
2550 txtsize += buflens[1];
2552 if (req->rq_pack_bulk) {
2553 LASSERT(grctx->src_reqbsd);
2556 buflens[bufcnt] = gss_svc_bulk_payload(
2560 if (svc == SPTLRPC_SVC_INTG)
2561 txtsize += buflens[bufcnt];
2565 if ((!early && gss_svc_reqctx_is_special(grctx)) ||
2566 svc != SPTLRPC_SVC_NULL)
2567 buflens[bufcnt++] = gss_svc_payload(grctx, early,
2571 wmsg_size = lustre_msg_size_v2(bufcnt, buflens);
2573 rs_size = sizeof(*rs) + wmsg_size;
2574 rs = req->rq_reply_state;
2578 LASSERT(rs->rs_size >= rs_size);
2580 OBD_ALLOC_LARGE(rs, rs_size);
2584 rs->rs_size = rs_size;
2587 rs->rs_repbuf = (struct lustre_msg *) (rs + 1);
2588 rs->rs_repbuf_len = wmsg_size;
2590 /* initialize the buffer */
2592 lustre_init_msg_v2(rs->rs_repbuf, ibufcnt, ibuflens, NULL);
2593 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 0, msglen);
2595 lustre_init_msg_v2(rs->rs_repbuf, bufcnt, buflens, NULL);
2596 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2598 rs->rs_msg = lustre_msg_buf(rs->rs_repbuf, 1, 0);
2602 grctx->src_repbsd = lustre_msg_buf(rs->rs_repbuf, bsd_off, 0);
2603 grctx->src_repbsd_size = lustre_msg_buflen(rs->rs_repbuf,
2607 gss_svc_reqctx_addref(grctx);
2608 rs->rs_svc_ctx = req->rq_svc_ctx;
2610 LASSERT(rs->rs_msg);
2611 req->rq_reply_state = rs;
2615 static int gss_svc_seal(struct ptlrpc_request *req,
2616 struct ptlrpc_reply_state *rs,
2617 struct gss_svc_reqctx *grctx)
2619 struct gss_svc_ctx *gctx = grctx->src_ctx;
2620 rawobj_t hdrobj, msgobj, token;
2621 struct gss_header *ghdr;
2624 __u32 buflens[2], major;
2628 /* get clear data length. note embedded lustre_msg might
2629 * have been shrunk */
2630 if (req->rq_replen != lustre_msg_buflen(rs->rs_repbuf, 0))
2631 msglen = lustre_shrink_msg(rs->rs_repbuf, 0, req->rq_replen, 1);
2633 msglen = lustre_msg_size_v2(rs->rs_repbuf->lm_bufcount,
2634 rs->rs_repbuf->lm_buflens);
2636 /* temporarily use tail of buffer to hold gss header data */
2637 LASSERT(msglen + PTLRPC_GSS_HEADER_SIZE <= rs->rs_repbuf_len);
2638 ghdr = (struct gss_header *) ((char *) rs->rs_repbuf +
2639 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE);
2640 ghdr->gh_version = PTLRPC_GSS_VERSION;
2641 ghdr->gh_sp = LUSTRE_SP_ANY;
2643 ghdr->gh_proc = PTLRPC_GSS_PROC_DATA;
2644 ghdr->gh_seq = grctx->src_wirectx.gw_seq;
2645 ghdr->gh_svc = SPTLRPC_SVC_PRIV;
2646 ghdr->gh_handle.len = 0;
2647 if (req->rq_pack_bulk)
2648 ghdr->gh_flags |= LUSTRE_GSS_PACK_BULK;
2650 /* allocate temporary cipher buffer */
2651 token_buflen = gss_mech_payload(gctx->gsc_mechctx, msglen, 1);
2652 OBD_ALLOC_LARGE(token_buf, token_buflen);
2653 if (token_buf == NULL)
2656 hdrobj.len = PTLRPC_GSS_HEADER_SIZE;
2657 hdrobj.data = (__u8 *) ghdr;
2658 msgobj.len = msglen;
2659 msgobj.data = (__u8 *) rs->rs_repbuf;
2660 token.len = token_buflen;
2661 token.data = token_buf;
2663 major = lgss_wrap(gctx->gsc_mechctx, &hdrobj, &msgobj,
2664 rs->rs_repbuf_len - PTLRPC_GSS_HEADER_SIZE, &token);
2665 if (major != GSS_S_COMPLETE) {
2666 CERROR("wrap message error: %08x\n", major);
2667 GOTO(out_free, rc = -EPERM);
2669 LASSERT(token.len <= token_buflen);
2671 /* we are about to override data at rs->rs_repbuf, nullify pointers
2672 * to which to catch further illegal usage. */
2673 if (req->rq_pack_bulk) {
2674 grctx->src_repbsd = NULL;
2675 grctx->src_repbsd_size = 0;
2678 /* now fill the actual wire data
2682 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2683 buflens[1] = token.len;
2685 rs->rs_repdata_len = lustre_msg_size_v2(2, buflens);
2686 LASSERT(rs->rs_repdata_len <= rs->rs_repbuf_len);
2688 lustre_init_msg_v2(rs->rs_repbuf, 2, buflens, NULL);
2689 rs->rs_repbuf->lm_secflvr = req->rq_flvr.sf_rpc;
2691 memcpy(lustre_msg_buf(rs->rs_repbuf, 0, 0), ghdr,
2692 PTLRPC_GSS_HEADER_SIZE);
2693 memcpy(lustre_msg_buf(rs->rs_repbuf, 1, 0), token.data, token.len);
2696 if (req->rq_packed_final &&
2697 (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))
2698 req->rq_reply_off = gss_at_reply_off_priv;
2700 req->rq_reply_off = 0;
2702 /* to catch upper layer's further access */
2704 req->rq_repmsg = NULL;
2709 OBD_FREE_LARGE(token_buf, token_buflen);
2713 int gss_svc_authorize(struct ptlrpc_request *req)
2715 struct ptlrpc_reply_state *rs = req->rq_reply_state;
2716 struct gss_svc_reqctx *grctx = gss_svc_ctx2reqctx(req->rq_svc_ctx);
2717 struct gss_wire_ctx *gw = &grctx->src_wirectx;
2721 early = (req->rq_packed_final == 0);
2723 if (!early && gss_svc_reqctx_is_special(grctx)) {
2724 LASSERT(rs->rs_repdata_len != 0);
2726 req->rq_reply_off = gss_at_reply_off_integ;
2730 /* early reply could happen in many cases */
2732 gw->gw_proc != PTLRPC_GSS_PROC_DATA &&
2733 gw->gw_proc != PTLRPC_GSS_PROC_DESTROY) {
2734 CERROR("proc %d not support\n", gw->gw_proc);
2738 LASSERT(grctx->src_ctx);
2740 switch (gw->gw_svc) {
2741 case SPTLRPC_SVC_NULL:
2742 case SPTLRPC_SVC_AUTH:
2743 case SPTLRPC_SVC_INTG:
2744 rc = gss_svc_sign(req, rs, grctx, gw->gw_svc);
2746 case SPTLRPC_SVC_PRIV:
2747 rc = gss_svc_seal(req, rs, grctx);
2750 CERROR("Unknown service %d\n", gw->gw_svc);
2751 GOTO(out, rc = -EINVAL);
2759 void gss_svc_free_rs(struct ptlrpc_reply_state *rs)
2761 struct gss_svc_reqctx *grctx;
2763 LASSERT(rs->rs_svc_ctx);
2764 grctx = container_of(rs->rs_svc_ctx, struct gss_svc_reqctx, src_base);
2766 gss_svc_reqctx_decref(grctx);
2767 rs->rs_svc_ctx = NULL;
2769 if (!rs->rs_prealloc)
2770 OBD_FREE_LARGE(rs, rs->rs_size);
2773 void gss_svc_free_ctx(struct ptlrpc_svc_ctx *ctx)
2775 LASSERT(atomic_read(&ctx->sc_refcount) == 0);
2776 gss_svc_reqctx_free(gss_svc_ctx2reqctx(ctx));
2779 int gss_copy_rvc_cli_ctx(struct ptlrpc_cli_ctx *cli_ctx,
2780 struct ptlrpc_svc_ctx *svc_ctx)
2782 struct gss_cli_ctx *cli_gctx = ctx2gctx(cli_ctx);
2783 struct gss_svc_ctx *svc_gctx = gss_svc_ctx2gssctx(svc_ctx);
2784 struct gss_ctx *mechctx = NULL;
2787 LASSERT(svc_gctx && svc_gctx->gsc_mechctx);
2789 cli_gctx->gc_proc = PTLRPC_GSS_PROC_DATA;
2790 cli_gctx->gc_win = GSS_SEQ_WIN;
2792 /* The problem is the reverse ctx might get lost in some recovery
2793 * situations, and the same svc_ctx will be used to re-create it.
2794 * if there's callback be sentout before that, new reverse ctx start
2795 * with sequence 0 will lead to future callback rpc be treated as
2798 * each reverse root ctx will record its latest sequence number on its
2799 * buddy svcctx before be destroyed, so here we continue use it.
2801 atomic_set(&cli_gctx->gc_seq, svc_gctx->gsc_rvs_seq);
2803 if (gss_svc_upcall_dup_handle(&cli_gctx->gc_svc_handle, svc_gctx)) {
2804 CERROR("failed to dup svc handle\n");
2808 if (lgss_copy_reverse_context(svc_gctx->gsc_mechctx, &mechctx) !=
2810 CERROR("failed to copy mech context\n");
2811 goto err_svc_handle;
2814 if (rawobj_dup(&cli_gctx->gc_handle, &svc_gctx->gsc_rvs_hdl)) {
2815 CERROR("failed to dup reverse handle\n");
2819 cli_gctx->gc_mechctx = mechctx;
2820 gss_cli_ctx_uptodate(cli_gctx);
2825 lgss_delete_sec_context(&mechctx);
2827 rawobj_free(&cli_gctx->gc_svc_handle);
2832 static void gss_init_at_reply_offset(void)
2837 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2838 buflens[1] = lustre_msg_early_size();
2839 buflens[2] = gss_cli_payload(NULL, buflens[1], 0);
2840 gss_at_reply_off_integ = lustre_msg_size_v2(3, buflens);
2842 buflens[0] = lustre_msg_early_size();
2843 clearsize = lustre_msg_size_v2(1, buflens);
2844 buflens[0] = PTLRPC_GSS_HEADER_SIZE;
2845 buflens[1] = gss_cli_payload(NULL, clearsize, 0);
2846 buflens[2] = gss_cli_payload(NULL, clearsize, 1);
2847 gss_at_reply_off_priv = lustre_msg_size_v2(3, buflens);
2850 static int __init sptlrpc_gss_init(void)
2854 rc = gss_init_lproc();
2858 rc = gss_init_cli_upcall();
2862 rc = gss_init_svc_upcall();
2864 goto out_cli_upcall;
2866 rc = init_null_module();
2868 goto out_svc_upcall;
2870 rc = init_kerberos_module();
2874 rc = init_sk_module();
2878 /* register policy after all other stuff be initialized, because it
2879 * might be in used immediately after the registration. */
2881 rc = gss_init_keyring();
2885 rc = gss_init_pipefs();
2889 gss_init_at_reply_offset();
2896 cleanup_sk_module();
2898 cleanup_kerberos_module();
2900 cleanup_null_module();
2902 gss_exit_svc_upcall();
2904 gss_exit_cli_upcall();
2910 static void __exit sptlrpc_gss_exit(void)
2914 cleanup_kerberos_module();
2915 gss_exit_svc_upcall();
2916 gss_exit_cli_upcall();
2920 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2921 MODULE_DESCRIPTION("Lustre GSS security policy");
2922 MODULE_VERSION(LUSTRE_VERSION_STRING);
2923 MODULE_LICENSE("GPL");
2925 module_init(sptlrpc_gss_init);
2926 module_exit(sptlrpc_gss_exit);