4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _LUSTRE_SEC_H_
38 #define _LUSTRE_SEC_H_
40 /** \defgroup sptlrpc sptlrpc
50 struct ptlrpc_request;
51 struct ptlrpc_reply_state;
52 struct ptlrpc_bulk_desc;
62 struct ptlrpc_sec_policy;
63 struct ptlrpc_sec_cops;
64 struct ptlrpc_sec_sops;
66 struct ptlrpc_svc_ctx;
67 struct ptlrpc_cli_ctx;
68 struct ptlrpc_ctx_ops;
71 * \addtogroup flavor flavor
73 * RPC flavor is represented by a 32 bits integer. Currently the high 12 bits
74 * are unused, must be set to 0 for future expansion.
76 * ------------------------------------------------------------------------
77 * | 4b (bulk svc) | 4b (bulk type) | 4b (svc) | 4b (mech) | 4b (policy) |
78 * ------------------------------------------------------------------------
88 SPTLRPC_POLICY_NULL = 0,
89 SPTLRPC_POLICY_PLAIN = 1,
90 SPTLRPC_POLICY_GSS = 2,
94 enum sptlrpc_mech_null {
95 SPTLRPC_MECH_NULL = 0,
96 SPTLRPC_MECH_NULL_MAX,
99 enum sptlrpc_mech_plain {
100 SPTLRPC_MECH_PLAIN = 0,
101 SPTLRPC_MECH_PLAIN_MAX,
104 enum sptlrpc_mech_gss {
105 SPTLRPC_MECH_GSS_NULL = 0,
106 SPTLRPC_MECH_GSS_KRB5 = 1,
107 SPTLRPC_MECH_GSS_SK = 2,
108 SPTLRPC_MECH_GSS_MAX,
111 enum sptlrpc_service_type {
112 SPTLRPC_SVC_NULL = 0, /**< no security */
113 SPTLRPC_SVC_AUTH = 1, /**< authentication only */
114 SPTLRPC_SVC_INTG = 2, /**< integrity */
115 SPTLRPC_SVC_PRIV = 3, /**< privacy */
119 enum sptlrpc_bulk_type {
120 SPTLRPC_BULK_DEFAULT = 0, /**< follow rpc flavor */
121 SPTLRPC_BULK_HASH = 1, /**< hash integrity */
125 enum sptlrpc_bulk_service {
126 SPTLRPC_BULK_SVC_NULL = 0, /**< no security */
127 SPTLRPC_BULK_SVC_AUTH = 1, /**< authentication only */
128 SPTLRPC_BULK_SVC_INTG = 2, /**< integrity */
129 SPTLRPC_BULK_SVC_PRIV = 3, /**< privacy */
130 SPTLRPC_BULK_SVC_MAX,
134 * compose/extract macros
136 #define FLVR_POLICY_OFFSET (0)
137 #define FLVR_MECH_OFFSET (4)
138 #define FLVR_SVC_OFFSET (8)
139 #define FLVR_BULK_TYPE_OFFSET (12)
140 #define FLVR_BULK_SVC_OFFSET (16)
142 #define MAKE_FLVR(policy, mech, svc, btype, bsvc) \
143 (((__u32)(policy) << FLVR_POLICY_OFFSET) | \
144 ((__u32)(mech) << FLVR_MECH_OFFSET) | \
145 ((__u32)(svc) << FLVR_SVC_OFFSET) | \
146 ((__u32)(btype) << FLVR_BULK_TYPE_OFFSET) | \
147 ((__u32)(bsvc) << FLVR_BULK_SVC_OFFSET))
152 #define SPTLRPC_FLVR_POLICY(flavor) \
153 ((((__u32)(flavor)) >> FLVR_POLICY_OFFSET) & 0xF)
154 #define SPTLRPC_FLVR_MECH(flavor) \
155 ((((__u32)(flavor)) >> FLVR_MECH_OFFSET) & 0xF)
156 #define SPTLRPC_FLVR_SVC(flavor) \
157 ((((__u32)(flavor)) >> FLVR_SVC_OFFSET) & 0xF)
158 #define SPTLRPC_FLVR_BULK_TYPE(flavor) \
159 ((((__u32)(flavor)) >> FLVR_BULK_TYPE_OFFSET) & 0xF)
160 #define SPTLRPC_FLVR_BULK_SVC(flavor) \
161 ((((__u32)(flavor)) >> FLVR_BULK_SVC_OFFSET) & 0xF)
163 #define SPTLRPC_FLVR_BASE(flavor) \
164 ((((__u32)(flavor)) >> FLVR_POLICY_OFFSET) & 0xFFF)
165 #define SPTLRPC_FLVR_BASE_SUB(flavor) \
166 ((((__u32)(flavor)) >> FLVR_MECH_OFFSET) & 0xFF)
171 #define MAKE_BASE_SUBFLVR(mech, svc) \
173 ((__u32)(svc) << (FLVR_SVC_OFFSET - FLVR_MECH_OFFSET)))
175 #define SPTLRPC_SUBFLVR_GSSNULL \
176 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_NULL, SPTLRPC_SVC_NULL)
177 #define SPTLRPC_SUBFLVR_KRB5N \
178 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_NULL)
179 #define SPTLRPC_SUBFLVR_KRB5A \
180 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_AUTH)
181 #define SPTLRPC_SUBFLVR_KRB5I \
182 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_INTG)
183 #define SPTLRPC_SUBFLVR_KRB5P \
184 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_PRIV)
185 #define SPTLRPC_SUBFLVR_SKI \
186 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_SK, SPTLRPC_SVC_INTG)
187 #define SPTLRPC_SUBFLVR_SKPI \
188 MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_SK, SPTLRPC_SVC_PRIV)
193 #define SPTLRPC_FLVR_NULL \
194 MAKE_FLVR(SPTLRPC_POLICY_NULL, \
197 SPTLRPC_BULK_DEFAULT, \
198 SPTLRPC_BULK_SVC_NULL)
199 #define SPTLRPC_FLVR_PLAIN \
200 MAKE_FLVR(SPTLRPC_POLICY_PLAIN, \
201 SPTLRPC_MECH_PLAIN, \
204 SPTLRPC_BULK_SVC_INTG)
205 #define SPTLRPC_FLVR_GSSNULL \
206 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
207 SPTLRPC_MECH_GSS_NULL, \
209 SPTLRPC_BULK_DEFAULT, \
210 SPTLRPC_BULK_SVC_NULL)
211 #define SPTLRPC_FLVR_KRB5N \
212 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
213 SPTLRPC_MECH_GSS_KRB5, \
215 SPTLRPC_BULK_DEFAULT, \
216 SPTLRPC_BULK_SVC_NULL)
217 #define SPTLRPC_FLVR_KRB5A \
218 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
219 SPTLRPC_MECH_GSS_KRB5, \
221 SPTLRPC_BULK_DEFAULT, \
222 SPTLRPC_BULK_SVC_NULL)
223 #define SPTLRPC_FLVR_KRB5I \
224 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
225 SPTLRPC_MECH_GSS_KRB5, \
227 SPTLRPC_BULK_DEFAULT, \
228 SPTLRPC_BULK_SVC_INTG)
229 #define SPTLRPC_FLVR_KRB5P \
230 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
231 SPTLRPC_MECH_GSS_KRB5, \
233 SPTLRPC_BULK_DEFAULT, \
234 SPTLRPC_BULK_SVC_PRIV)
235 #define SPTLRPC_FLVR_SKI \
236 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
237 SPTLRPC_MECH_GSS_SK, \
239 SPTLRPC_BULK_DEFAULT, \
240 SPTLRPC_BULK_SVC_PRIV)
241 #define SPTLRPC_FLVR_SKPI \
242 MAKE_FLVR(SPTLRPC_POLICY_GSS, \
243 SPTLRPC_MECH_GSS_SK, \
245 SPTLRPC_BULK_DEFAULT, \
246 SPTLRPC_BULK_SVC_PRIV)
248 #define SPTLRPC_FLVR_DEFAULT SPTLRPC_FLVR_NULL
250 #define SPTLRPC_FLVR_INVALID ((__u32) 0xFFFFFFFF)
251 #define SPTLRPC_FLVR_ANY ((__u32) 0xFFF00000)
254 * extract the useful part from wire flavor
256 #define WIRE_FLVR(wflvr) (((__u32) (wflvr)) & 0x000FFFFF)
260 static inline void flvr_set_svc(__u32 *flvr, __u32 svc)
262 LASSERT(svc < SPTLRPC_SVC_MAX);
263 *flvr = MAKE_FLVR(SPTLRPC_FLVR_POLICY(*flvr),
264 SPTLRPC_FLVR_MECH(*flvr),
266 SPTLRPC_FLVR_BULK_TYPE(*flvr),
267 SPTLRPC_FLVR_BULK_SVC(*flvr));
270 static inline void flvr_set_bulk_svc(__u32 *flvr, __u32 svc)
272 LASSERT(svc < SPTLRPC_BULK_SVC_MAX);
273 *flvr = MAKE_FLVR(SPTLRPC_FLVR_POLICY(*flvr),
274 SPTLRPC_FLVR_MECH(*flvr),
275 SPTLRPC_FLVR_SVC(*flvr),
276 SPTLRPC_FLVR_BULK_TYPE(*flvr),
280 struct bulk_spec_hash {
285 * Full description of flavors being used on a ptlrpc connection, include
286 * both regular RPC and bulk transfer parts.
288 struct sptlrpc_flavor {
290 * wire flavor, should be renamed to sf_wire.
294 * general flags of PTLRPC_SEC_FL_*
298 * rpc flavor specification
301 /* nothing for now */
304 * bulk flavor specification
307 struct bulk_spec_hash hash;
312 * identify the RPC is generated from what part of Lustre. It's encoded into
313 * RPC requests and to be checked by ptlrpc service.
315 enum lustre_sec_part {
324 const char *sptlrpc_part2name(enum lustre_sec_part sp);
325 enum lustre_sec_part sptlrpc_target_sec_part(struct obd_device *obd);
328 * A rule specifies a flavor to be used by a ptlrpc connection between
331 struct sptlrpc_rule {
332 __u32 sr_netid; /* LNET network ID */
333 __u8 sr_from; /* sec_part */
334 __u8 sr_to; /* sec_part */
336 struct sptlrpc_flavor sr_flvr;
340 * A set of rules in memory.
342 * Rules are generated and stored on MGS, and propagated to MDT, OST,
343 * and client when needed.
345 struct sptlrpc_rule_set {
348 struct sptlrpc_rule *srs_rules;
351 int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr);
352 int sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr);
354 static inline void sptlrpc_rule_set_init(struct sptlrpc_rule_set *set)
356 memset(set, 0, sizeof(*set));
359 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *set);
360 int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *set);
361 int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *set,
362 struct sptlrpc_rule *rule);
363 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
364 enum lustre_sec_part from,
365 enum lustre_sec_part to,
367 struct sptlrpc_flavor *sf);
368 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *set);
370 int sptlrpc_process_config(struct lustre_cfg *lcfg);
371 void sptlrpc_conf_log_start(const char *logname);
372 void sptlrpc_conf_log_stop(const char *logname);
373 void sptlrpc_conf_log_update_begin(const char *logname);
374 void sptlrpc_conf_log_update_end(const char *logname);
375 void sptlrpc_conf_client_adapt(struct obd_device *obd);
376 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
377 struct sptlrpc_rule_set *rset,
379 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
380 enum lustre_sec_part from,
382 struct sptlrpc_flavor *flavor);
384 /* The maximum length of security payload. 1024 is enough for Kerberos 5,
385 * and should be enough for other future mechanisms but not sure.
386 * Only used by pre-allocated request/reply pool.
388 #define SPTLRPC_MAX_PAYLOAD (1024)
396 struct ptlrpc_ctx_ops {
398 * To determine whether it's suitable to use the \a ctx for \a vcred.
400 int (*match) (struct ptlrpc_cli_ctx *ctx,
401 struct vfs_cred *vcred);
404 * To bring the \a ctx uptodate.
406 int (*refresh) (struct ptlrpc_cli_ctx *ctx);
409 * Validate the \a ctx.
411 int (*validate) (struct ptlrpc_cli_ctx *ctx);
414 * Force the \a ctx to die.
416 void (*die) (struct ptlrpc_cli_ctx *ctx,
418 int (*display) (struct ptlrpc_cli_ctx *ctx,
419 char *buf, int bufsize);
422 * Sign the request message using \a ctx.
424 * \pre req->rq_reqmsg point to request message.
425 * \pre req->rq_reqlen is the request message length.
426 * \post req->rq_reqbuf point to request message with signature.
427 * \post req->rq_reqdata_len is set to the final request message size.
429 * \see null_ctx_sign(), plain_ctx_sign(), gss_cli_ctx_sign().
431 int (*sign) (struct ptlrpc_cli_ctx *ctx,
432 struct ptlrpc_request *req);
435 * Verify the reply message using \a ctx.
437 * \pre req->rq_repdata point to reply message with signature.
438 * \pre req->rq_repdata_len is the total reply message length.
439 * \post req->rq_repmsg point to reply message without signature.
440 * \post req->rq_replen is the reply message length.
442 * \see null_ctx_verify(), plain_ctx_verify(), gss_cli_ctx_verify().
444 int (*verify) (struct ptlrpc_cli_ctx *ctx,
445 struct ptlrpc_request *req);
448 * Encrypt the request message using \a ctx.
450 * \pre req->rq_reqmsg point to request message in clear text.
451 * \pre req->rq_reqlen is the request message length.
452 * \post req->rq_reqbuf point to request message.
453 * \post req->rq_reqdata_len is set to the final request message size.
455 * \see gss_cli_ctx_seal().
457 int (*seal) (struct ptlrpc_cli_ctx *ctx,
458 struct ptlrpc_request *req);
461 * Decrypt the reply message using \a ctx.
463 * \pre req->rq_repdata point to encrypted reply message.
464 * \pre req->rq_repdata_len is the total cipher text length.
465 * \post req->rq_repmsg point to reply message in clear text.
466 * \post req->rq_replen is the reply message length in clear text.
468 * \see gss_cli_ctx_unseal().
470 int (*unseal) (struct ptlrpc_cli_ctx *ctx,
471 struct ptlrpc_request *req);
474 * Wrap bulk request data. This is called before wrapping RPC
477 * \pre bulk buffer is descripted by desc->bd_iov and
478 * desc->bd_iov_count. note for read it's just buffer, no data
479 * need to be sent; for write it contains data in clear text.
480 * \post when necessary, ptlrpc_bulk_sec_desc was properly prepared
481 * (usually inside of RPC request message).
482 * - encryption: cipher text bulk buffer is descripted by
483 * desc->bd_enc_iov and desc->bd_iov_count (currently assume iov
484 * count remains the same).
485 * - otherwise: bulk buffer is still desc->bd_iov and
486 * desc->bd_iov_count.
488 * \return 0: success.
489 * \return -ev: error code.
491 * \see plain_cli_wrap_bulk(), gss_cli_ctx_wrap_bulk().
493 int (*wrap_bulk) (struct ptlrpc_cli_ctx *ctx,
494 struct ptlrpc_request *req,
495 struct ptlrpc_bulk_desc *desc);
498 * Unwrap bulk reply data. This is called after wrapping RPC
501 * \pre bulk buffer is descripted by desc->bd_iov/desc->bd_enc_iov and
502 * desc->bd_iov_count, according to wrap_bulk().
503 * \post final bulk data in clear text is placed in buffer described
504 * by desc->bd_iov and desc->bd_iov_count.
505 * \return +ve nob of actual bulk data in clear text.
506 * \return -ve error code.
508 * \see plain_cli_unwrap_bulk(), gss_cli_ctx_unwrap_bulk().
510 int (*unwrap_bulk) (struct ptlrpc_cli_ctx *ctx,
511 struct ptlrpc_request *req,
512 struct ptlrpc_bulk_desc *desc);
515 #define PTLRPC_CTX_NEW_BIT (0) /* newly created */
516 #define PTLRPC_CTX_UPTODATE_BIT (1) /* uptodate */
517 #define PTLRPC_CTX_DEAD_BIT (2) /* mark expired gracefully */
518 #define PTLRPC_CTX_ERROR_BIT (3) /* fatal error (refresh, etc.) */
519 #define PTLRPC_CTX_CACHED_BIT (8) /* in ctx cache (hash etc.) */
520 #define PTLRPC_CTX_ETERNAL_BIT (9) /* always valid */
522 #define PTLRPC_CTX_NEW (1 << PTLRPC_CTX_NEW_BIT)
523 #define PTLRPC_CTX_UPTODATE (1 << PTLRPC_CTX_UPTODATE_BIT)
524 #define PTLRPC_CTX_DEAD (1 << PTLRPC_CTX_DEAD_BIT)
525 #define PTLRPC_CTX_ERROR (1 << PTLRPC_CTX_ERROR_BIT)
526 #define PTLRPC_CTX_CACHED (1 << PTLRPC_CTX_CACHED_BIT)
527 #define PTLRPC_CTX_ETERNAL (1 << PTLRPC_CTX_ETERNAL_BIT)
529 #define PTLRPC_CTX_STATUS_MASK (PTLRPC_CTX_NEW_BIT | \
530 PTLRPC_CTX_UPTODATE | \
534 struct ptlrpc_cli_ctx {
535 struct hlist_node cc_cache; /* linked into ctx cache */
536 atomic_t cc_refcount;
537 struct ptlrpc_sec *cc_sec;
538 struct ptlrpc_ctx_ops *cc_ops;
539 cfs_time_t cc_expire; /* in seconds */
540 unsigned int cc_early_expire:1;
541 unsigned long cc_flags;
542 struct vfs_cred cc_vcred;
544 struct list_head cc_req_list; /* waiting reqs linked here */
545 struct list_head cc_gc_chain; /* linked to gc chain */
549 * client side policy operation vector.
551 struct ptlrpc_sec_cops {
553 * Given an \a imp, create and initialize a ptlrpc_sec structure.
554 * \param ctx service context:
555 * - regular import: \a ctx should be NULL;
556 * - reverse import: \a ctx is obtained from incoming request.
557 * \param flavor specify what flavor to use.
559 * When necessary, policy module is responsible for taking reference
562 * \see null_create_sec(), plain_create_sec(), gss_sec_create_kr().
564 struct ptlrpc_sec * (*create_sec) (struct obd_import *imp,
565 struct ptlrpc_svc_ctx *ctx,
566 struct sptlrpc_flavor *flavor);
569 * Destructor of ptlrpc_sec. When called, refcount has been dropped
570 * to 0 and all contexts has been destroyed.
572 * \see null_destroy_sec(), plain_destroy_sec(), gss_sec_destroy_kr().
574 void (*destroy_sec) (struct ptlrpc_sec *sec);
577 * Notify that this ptlrpc_sec is going to die. Optionally, policy
578 * module is supposed to set sec->ps_dying and whatever necessary
581 * \see plain_kill_sec(), gss_sec_kill().
583 void (*kill_sec) (struct ptlrpc_sec *sec);
586 * Given \a vcred, lookup and/or create its context. The policy module
587 * is supposed to maintain its own context cache.
588 * XXX currently \a create and \a remove_dead is always 1, perhaps
589 * should be removed completely.
591 * \see null_lookup_ctx(), plain_lookup_ctx(), gss_sec_lookup_ctx_kr().
593 struct ptlrpc_cli_ctx * (*lookup_ctx) (struct ptlrpc_sec *sec,
594 struct vfs_cred *vcred,
599 * Called then the reference of \a ctx dropped to 0. The policy module
600 * is supposed to destroy this context or whatever else according to
601 * its cache maintainance mechamism.
603 * \param sync if zero, we shouldn't wait for the context being
604 * destroyed completely.
606 * \see plain_release_ctx(), gss_sec_release_ctx_kr().
608 void (*release_ctx) (struct ptlrpc_sec *sec,
609 struct ptlrpc_cli_ctx *ctx,
613 * Flush the context cache.
615 * \param uid context of which user, -1 means all contexts.
616 * \param grace if zero, the PTLRPC_CTX_UPTODATE_BIT of affected
617 * contexts should be cleared immediately.
618 * \param force if zero, only idle contexts will be flushed.
620 * \see plain_flush_ctx_cache(), gss_sec_flush_ctx_cache_kr().
622 int (*flush_ctx_cache)
623 (struct ptlrpc_sec *sec,
629 * Called periodically by garbage collector to remove dead contexts
632 * \see gss_sec_gc_ctx_kr().
634 void (*gc_ctx) (struct ptlrpc_sec *sec);
637 * Given an context \a ctx, install a corresponding reverse service
638 * context on client side.
639 * XXX currently it's only used by GSS module, maybe we should remove
640 * this from general API.
642 int (*install_rctx)(struct obd_import *imp,
643 struct ptlrpc_sec *sec,
644 struct ptlrpc_cli_ctx *ctx);
647 * To allocate request buffer for \a req.
649 * \pre req->rq_reqmsg == NULL.
650 * \pre req->rq_reqbuf == NULL, otherwise it must be pre-allocated,
651 * we are not supposed to free it.
652 * \post if success, req->rq_reqmsg point to a buffer with size
653 * at least \a lustre_msg_size.
655 * \see null_alloc_reqbuf(), plain_alloc_reqbuf(), gss_alloc_reqbuf().
657 int (*alloc_reqbuf)(struct ptlrpc_sec *sec,
658 struct ptlrpc_request *req,
659 int lustre_msg_size);
662 * To free request buffer for \a req.
664 * \pre req->rq_reqbuf != NULL.
666 * \see null_free_reqbuf(), plain_free_reqbuf(), gss_free_reqbuf().
668 void (*free_reqbuf) (struct ptlrpc_sec *sec,
669 struct ptlrpc_request *req);
672 * To allocate reply buffer for \a req.
674 * \pre req->rq_repbuf == NULL.
675 * \post if success, req->rq_repbuf point to a buffer with size
676 * req->rq_repbuf_len, the size should be large enough to receive
677 * reply which be transformed from \a lustre_msg_size of clear text.
679 * \see null_alloc_repbuf(), plain_alloc_repbuf(), gss_alloc_repbuf().
681 int (*alloc_repbuf)(struct ptlrpc_sec *sec,
682 struct ptlrpc_request *req,
683 int lustre_msg_size);
686 * To free reply buffer for \a req.
688 * \pre req->rq_repbuf != NULL.
689 * \post req->rq_repbuf == NULL.
690 * \post req->rq_repbuf_len == 0.
692 * \see null_free_repbuf(), plain_free_repbuf(), gss_free_repbuf().
694 void (*free_repbuf) (struct ptlrpc_sec *sec,
695 struct ptlrpc_request *req);
698 * To expand the request buffer of \a req, thus the \a segment in
699 * the request message pointed by req->rq_reqmsg can accommodate
700 * at least \a newsize of data.
702 * \pre req->rq_reqmsg->lm_buflens[segment] < newsize.
704 * \see null_enlarge_reqbuf(), plain_enlarge_reqbuf(),
705 * gss_enlarge_reqbuf().
707 int (*enlarge_reqbuf)
708 (struct ptlrpc_sec *sec,
709 struct ptlrpc_request *req,
710 int segment, int newsize);
714 int (*display) (struct ptlrpc_sec *sec,
715 struct seq_file *seq);
719 * server side policy operation vector.
721 struct ptlrpc_sec_sops {
723 * verify an incoming request.
725 * \pre request message is pointed by req->rq_reqbuf, size is
726 * req->rq_reqdata_len; and the message has been unpacked to
729 * \retval SECSVC_OK success, req->rq_reqmsg point to request message
730 * in clear text, size is req->rq_reqlen; req->rq_svc_ctx is set;
731 * req->rq_sp_from is decoded from request.
732 * \retval SECSVC_COMPLETE success, the request has been fully
733 * processed, and reply message has been prepared; req->rq_sp_from is
734 * decoded from request.
735 * \retval SECSVC_DROP failed, this request should be dropped.
737 * \see null_accept(), plain_accept(), gss_svc_accept_kr().
739 int (*accept) (struct ptlrpc_request *req);
742 * Perform security transformation upon reply message.
744 * \pre reply message is pointed by req->rq_reply_state->rs_msg, size
746 * \post req->rs_repdata_len is the final message size.
747 * \post req->rq_reply_off is set.
749 * \see null_authorize(), plain_authorize(), gss_svc_authorize().
751 int (*authorize) (struct ptlrpc_request *req);
754 * Invalidate server context \a ctx.
756 * \see gss_svc_invalidate_ctx().
758 void (*invalidate_ctx)
759 (struct ptlrpc_svc_ctx *ctx);
762 * Allocate a ptlrpc_reply_state.
764 * \param msgsize size of the reply message in clear text.
765 * \pre if req->rq_reply_state != NULL, then it's pre-allocated, we
766 * should simply use it; otherwise we'll responsible for allocating
768 * \post req->rq_reply_state != NULL;
769 * \post req->rq_reply_state->rs_msg != NULL;
771 * \see null_alloc_rs(), plain_alloc_rs(), gss_svc_alloc_rs().
773 int (*alloc_rs) (struct ptlrpc_request *req,
777 * Free a ptlrpc_reply_state.
779 void (*free_rs) (struct ptlrpc_reply_state *rs);
782 * Release the server context \a ctx.
784 * \see gss_svc_free_ctx().
786 void (*free_ctx) (struct ptlrpc_svc_ctx *ctx);
789 * Install a reverse context based on the server context \a ctx.
791 * \see gss_svc_install_rctx_kr().
793 int (*install_rctx)(struct obd_import *imp,
794 struct ptlrpc_svc_ctx *ctx);
797 * Prepare buffer for incoming bulk write.
799 * \pre desc->bd_iov and desc->bd_iov_count describes the buffer
800 * intended to receive the write.
802 * \see gss_svc_prep_bulk().
804 int (*prep_bulk) (struct ptlrpc_request *req,
805 struct ptlrpc_bulk_desc *desc);
808 * Unwrap the bulk write data.
810 * \see plain_svc_unwrap_bulk(), gss_svc_unwrap_bulk().
812 int (*unwrap_bulk) (struct ptlrpc_request *req,
813 struct ptlrpc_bulk_desc *desc);
816 * Wrap the bulk read data.
818 * \see plain_svc_wrap_bulk(), gss_svc_wrap_bulk().
820 int (*wrap_bulk) (struct ptlrpc_request *req,
821 struct ptlrpc_bulk_desc *desc);
824 struct ptlrpc_sec_policy {
825 struct module *sp_owner;
827 __u16 sp_policy; /* policy number */
828 struct ptlrpc_sec_cops *sp_cops; /* client ops */
829 struct ptlrpc_sec_sops *sp_sops; /* server ops */
832 #define PTLRPC_SEC_FL_REVERSE 0x0001 /* reverse sec */
833 #define PTLRPC_SEC_FL_ROOTONLY 0x0002 /* treat everyone as root */
834 #define PTLRPC_SEC_FL_UDESC 0x0004 /* ship udesc */
835 #define PTLRPC_SEC_FL_BULK 0x0008 /* intensive bulk i/o expected */
836 #define PTLRPC_SEC_FL_PAG 0x0010 /* PAG mode */
839 * The ptlrpc_sec represents the client side ptlrpc security facilities,
840 * each obd_import (both regular and reverse import) must associate with
843 * \see sptlrpc_import_sec_adapt().
846 struct ptlrpc_sec_policy *ps_policy;
847 atomic_t ps_refcount;
848 /** statistic only */
850 /** unique identifier */
852 struct sptlrpc_flavor ps_flvr;
853 enum lustre_sec_part ps_part;
854 /** after set, no more new context will be created */
855 unsigned int ps_dying:1;
857 struct obd_import *ps_import;
863 struct list_head ps_gc_list;
864 cfs_time_t ps_gc_interval; /* in seconds */
865 cfs_time_t ps_gc_next; /* in seconds */
868 static inline int sec_is_reverse(struct ptlrpc_sec *sec)
870 return (sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_REVERSE);
873 static inline int sec_is_rootonly(struct ptlrpc_sec *sec)
875 return (sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_ROOTONLY);
879 struct ptlrpc_svc_ctx {
880 atomic_t sc_refcount;
881 struct ptlrpc_sec_policy *sc_policy;
885 * user identity descriptor
887 #define LUSTRE_MAX_GROUPS (128)
889 struct ptlrpc_user_desc {
902 enum sptlrpc_bulk_hash_alg {
903 BULK_HASH_ALG_NULL = 0,
904 BULK_HASH_ALG_ADLER32,
908 BULK_HASH_ALG_SHA256,
909 BULK_HASH_ALG_SHA384,
910 BULK_HASH_ALG_SHA512,
914 const char * sptlrpc_get_hash_name(__u8 hash_alg);
915 __u8 sptlrpc_get_hash_alg(const char *algname);
921 struct ptlrpc_bulk_sec_desc {
922 __u8 bsd_version; /* 0 */
923 __u8 bsd_type; /* SPTLRPC_BULK_XXX */
924 __u8 bsd_svc; /* SPTLRPC_BULK_SVC_XXXX */
925 __u8 bsd_flags; /* flags */
926 __u32 bsd_nob; /* nob of bulk data */
927 __u8 bsd_data[0]; /* policy-specific token */
934 struct proc_dir_entry;
935 extern struct proc_dir_entry *sptlrpc_proc_root;
938 * round size up to next power of 2, for slab allocation.
939 * @size must be sane (can't overflow after round up)
941 static inline int size_roundup_power2(int size)
954 * internal support libraries
956 void _sptlrpc_enlarge_msg_inplace(struct lustre_msg *msg,
957 int segment, int newsize);
962 int sptlrpc_register_policy(struct ptlrpc_sec_policy *policy);
963 int sptlrpc_unregister_policy(struct ptlrpc_sec_policy *policy);
965 __u32 sptlrpc_name2flavor_base(const char *name);
966 const char *sptlrpc_flavor2name_base(__u32 flvr);
967 char *sptlrpc_flavor2name_bulk(struct sptlrpc_flavor *sf,
968 char *buf, int bufsize);
969 char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize);
970 char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize);
972 static inline struct ptlrpc_sec_policy *
973 sptlrpc_policy_get(struct ptlrpc_sec_policy *policy)
975 __module_get(policy->sp_owner);
980 sptlrpc_policy_put(struct ptlrpc_sec_policy *policy)
982 module_put(policy->sp_owner);
989 unsigned long cli_ctx_status(struct ptlrpc_cli_ctx *ctx)
991 return (ctx->cc_flags & PTLRPC_CTX_STATUS_MASK);
995 int cli_ctx_is_ready(struct ptlrpc_cli_ctx *ctx)
997 return (cli_ctx_status(ctx) == PTLRPC_CTX_UPTODATE);
1001 int cli_ctx_is_refreshed(struct ptlrpc_cli_ctx *ctx)
1003 return (cli_ctx_status(ctx) != 0);
1007 int cli_ctx_is_uptodate(struct ptlrpc_cli_ctx *ctx)
1009 return ((ctx->cc_flags & PTLRPC_CTX_UPTODATE) != 0);
1013 int cli_ctx_is_error(struct ptlrpc_cli_ctx *ctx)
1015 return ((ctx->cc_flags & PTLRPC_CTX_ERROR) != 0);
1019 int cli_ctx_is_dead(struct ptlrpc_cli_ctx *ctx)
1021 return ((ctx->cc_flags & (PTLRPC_CTX_DEAD | PTLRPC_CTX_ERROR)) != 0);
1025 int cli_ctx_is_eternal(struct ptlrpc_cli_ctx *ctx)
1027 return ((ctx->cc_flags & PTLRPC_CTX_ETERNAL) != 0);
1033 struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec);
1034 void sptlrpc_sec_put(struct ptlrpc_sec *sec);
1037 * internal apis which only used by policy impelentation
1039 int sptlrpc_get_next_secid(void);
1040 void sptlrpc_sec_destroy(struct ptlrpc_sec *sec);
1043 * exported client context api
1045 struct ptlrpc_cli_ctx *sptlrpc_cli_ctx_get(struct ptlrpc_cli_ctx *ctx);
1046 void sptlrpc_cli_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync);
1047 void sptlrpc_cli_ctx_expire(struct ptlrpc_cli_ctx *ctx);
1048 void sptlrpc_cli_ctx_wakeup(struct ptlrpc_cli_ctx *ctx);
1049 int sptlrpc_cli_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
1052 * exported client context wrap/buffers
1054 int sptlrpc_cli_wrap_request(struct ptlrpc_request *req);
1055 int sptlrpc_cli_unwrap_reply(struct ptlrpc_request *req);
1056 int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize);
1057 void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req);
1058 int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize);
1059 void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req);
1060 int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
1061 int segment, int newsize);
1062 int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
1063 struct ptlrpc_request **req_ret);
1064 void sptlrpc_cli_finish_early_reply(struct ptlrpc_request *early_req);
1066 void sptlrpc_request_out_callback(struct ptlrpc_request *req);
1069 * exported higher interface of import & request
1071 int sptlrpc_import_sec_adapt(struct obd_import *imp,
1072 struct ptlrpc_svc_ctx *ctx,
1073 struct sptlrpc_flavor *flvr);
1074 struct ptlrpc_sec *sptlrpc_import_sec_ref(struct obd_import *imp);
1075 void sptlrpc_import_sec_put(struct obd_import *imp);
1077 int sptlrpc_import_check_ctx(struct obd_import *imp);
1078 void sptlrpc_import_flush_root_ctx(struct obd_import *imp);
1079 void sptlrpc_import_flush_my_ctx(struct obd_import *imp);
1080 void sptlrpc_import_flush_all_ctx(struct obd_import *imp);
1081 int sptlrpc_req_get_ctx(struct ptlrpc_request *req);
1082 void sptlrpc_req_put_ctx(struct ptlrpc_request *req, int sync);
1083 int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout);
1084 int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req);
1085 void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode);
1087 int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule);
1090 void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec);
1091 void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec);
1092 void sptlrpc_gc_add_ctx(struct ptlrpc_cli_ctx *ctx);
1095 const char * sec2target_str(struct ptlrpc_sec *sec);
1096 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev);
1101 enum secsvc_accept_res {
1107 int sptlrpc_svc_unwrap_request(struct ptlrpc_request *req);
1108 int sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen);
1109 int sptlrpc_svc_wrap_reply(struct ptlrpc_request *req);
1110 void sptlrpc_svc_free_rs(struct ptlrpc_reply_state *rs);
1111 void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req);
1112 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req);
1113 void sptlrpc_svc_ctx_invalidate(struct ptlrpc_request *req);
1115 int sptlrpc_target_export_check(struct obd_export *exp,
1116 struct ptlrpc_request *req);
1117 void sptlrpc_target_update_exp_flavor(struct obd_device *obd,
1118 struct sptlrpc_rule_set *rset);
1123 int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
1124 struct ptlrpc_svc_ctx *ctx);
1125 int sptlrpc_cli_install_rvs_ctx(struct obd_import *imp,
1126 struct ptlrpc_cli_ctx *ctx);
1128 /* bulk security api */
1129 int sptlrpc_enc_pool_add_user(void);
1130 int sptlrpc_enc_pool_del_user(void);
1131 int sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc);
1132 void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc);
1133 int get_free_pages_in_pool(void);
1134 int pool_is_at_full_capacity(void);
1136 int sptlrpc_cli_wrap_bulk(struct ptlrpc_request *req,
1137 struct ptlrpc_bulk_desc *desc);
1138 int sptlrpc_cli_unwrap_bulk_read(struct ptlrpc_request *req,
1139 struct ptlrpc_bulk_desc *desc,
1141 int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
1142 struct ptlrpc_bulk_desc *desc);
1143 #ifdef HAVE_SERVER_SUPPORT
1144 int sptlrpc_svc_prep_bulk(struct ptlrpc_request *req,
1145 struct ptlrpc_bulk_desc *desc);
1146 int sptlrpc_svc_wrap_bulk(struct ptlrpc_request *req,
1147 struct ptlrpc_bulk_desc *desc);
1148 int sptlrpc_svc_unwrap_bulk(struct ptlrpc_request *req,
1149 struct ptlrpc_bulk_desc *desc);
1152 /* bulk helpers (internal use only by policies) */
1153 int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
1154 void *buf, int buflen);
1156 int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed);
1158 /* user descriptor helpers */
1159 static inline int sptlrpc_user_desc_size(int ngroups)
1161 return sizeof(struct ptlrpc_user_desc) + ngroups * sizeof(__u32);
1164 int sptlrpc_current_user_desc_size(void);
1165 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset);
1166 int sptlrpc_unpack_user_desc(struct lustre_msg *req, int offset, int swabbed);
1169 #define CFS_CAP_CHOWN_MASK (1 << CFS_CAP_CHOWN)
1170 #define CFS_CAP_SYS_RESOURCE_MASK (1 << CFS_CAP_SYS_RESOURCE)
1173 LUSTRE_SEC_NONE = 0,
1174 LUSTRE_SEC_REMOTE = 1,
1175 LUSTRE_SEC_SPECIFY = 2,
1181 #endif /* _LUSTRE_SEC_H_ */