*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
#include <linux/mutex.h>
#include <asm/atomic.h>
+#include <libcfs/linux/linux-list.h>
#include <obd.h>
#include <obd_class.h>
#include <obd_support.h>
-#include <lustre/lustre_idl.h>
+#include <uapi/linux/lustre/lustre_idl.h>
#include <lustre_sec.h>
#include <lustre_net.h>
#include <lustre_import.h>
#define DUMP_KEY(key) \
{ \
- CWARN("DUMP KEY: %p(%d) ref %d u%u/g%u desc %s\n", \
- key, key->serial, atomic_read(&key->usage), \
- key->uid, key->gid, \
- key->description ? key->description : "n/a" \
- ); \
+ CWARN("DUMP KEY: %p(%d) ref %d u%u/g%u desc %s\n", \
+ key, key->serial, ll_read_key_usage(key), \
+ key->uid, key->gid, \
+ key->description ? key->description : "n/a" \
+ ); \
}
#define key_cred(tsk) ((tsk)->cred)
set_bit(KEY_FLAG_REVOKED, &key->flags);
}
-static void ctx_upcall_timeout_kr(unsigned long data)
+static void ctx_upcall_timeout_kr(cfs_timer_cb_arg_t data)
{
- struct ptlrpc_cli_ctx *ctx = (struct ptlrpc_cli_ctx *) data;
- struct key *key = ctx2gctx_keyring(ctx)->gck_key;
+ struct gss_cli_ctx_keyring *gctx_kr = cfs_from_timer(gctx_kr,
+ &data, gck_timer);
+ struct ptlrpc_cli_ctx *ctx = &(gctx_kr->gck_base.gc_base);
+ struct key *key = gctx_kr->gck_key;
CWARN("ctx %p, key %p\n", ctx, key);
key_revoke_locked(key);
}
-static void ctx_start_timer_kr(struct ptlrpc_cli_ctx *ctx, long timeout)
+static void ctx_start_timer_kr(struct ptlrpc_cli_ctx *ctx, time64_t timeout)
{
struct gss_cli_ctx_keyring *gctx_kr = ctx2gctx_keyring(ctx);
- struct timer_list *timer = gctx_kr->gck_timer;
+ struct timer_list *timer = gctx_kr->gck_timer;
LASSERT(timer);
- CDEBUG(D_SEC, "ctx %p: start timer %lds\n", ctx, timeout);
- timeout = msecs_to_jiffies(timeout * MSEC_PER_SEC) +
- cfs_time_current();
-
- init_timer(timer);
- timer->expires = timeout;
- timer->data = (unsigned long ) ctx;
- timer->function = ctx_upcall_timeout_kr;
+ CDEBUG(D_SEC, "ctx %p: start timer %llds\n", ctx, timeout);
+ cfs_timer_setup(timer, ctx_upcall_timeout_kr,
+ (unsigned long)gctx_kr, 0);
+ timer->expires = cfs_time_seconds(timeout) + jiffies;
add_timer(timer);
}
struct ptlrpc_cli_ctx *ctx_create_kr(struct ptlrpc_sec *sec,
struct vfs_cred *vcred)
{
- struct ptlrpc_cli_ctx *ctx;
- struct gss_cli_ctx_keyring *gctx_kr;
+ struct ptlrpc_cli_ctx *ctx;
+ struct gss_cli_ctx_keyring *gctx_kr;
- OBD_ALLOC_PTR(gctx_kr);
- if (gctx_kr == NULL)
- return NULL;
+ OBD_ALLOC_PTR(gctx_kr);
+ if (gctx_kr == NULL)
+ return NULL;
- OBD_ALLOC_PTR(gctx_kr->gck_timer);
- if (gctx_kr->gck_timer == NULL) {
- OBD_FREE_PTR(gctx_kr);
- return NULL;
- }
- init_timer(gctx_kr->gck_timer);
+ OBD_ALLOC_PTR(gctx_kr->gck_timer);
+ if (gctx_kr->gck_timer == NULL) {
+ OBD_FREE_PTR(gctx_kr);
+ return NULL;
+ }
+ cfs_timer_setup(gctx_kr->gck_timer, NULL, 0, 0);
- ctx = &gctx_kr->gck_base.gc_base;
+ ctx = &gctx_kr->gck_base.gc_base;
- if (gss_cli_ctx_init_common(sec, ctx, &gss_keyring_ctxops, vcred)) {
- OBD_FREE_PTR(gctx_kr->gck_timer);
- OBD_FREE_PTR(gctx_kr);
- return NULL;
- }
+ if (gss_cli_ctx_init_common(sec, ctx, &gss_keyring_ctxops, vcred)) {
+ OBD_FREE_PTR(gctx_kr->gck_timer);
+ OBD_FREE_PTR(gctx_kr);
+ return NULL;
+ }
- ctx->cc_expire = cfs_time_current_sec() + KEYRING_UPCALL_TIMEOUT;
+ ctx->cc_expire = ktime_get_real_seconds() + KEYRING_UPCALL_TIMEOUT;
clear_bit(PTLRPC_CTX_NEW_BIT, &ctx->cc_flags);
atomic_inc(&ctx->cc_refcount); /* for the caller */
static void bind_key_ctx(struct key *key, struct ptlrpc_cli_ctx *ctx)
{
LASSERT(atomic_read(&ctx->cc_refcount) > 0);
- LASSERT(atomic_read(&key->usage) > 0);
+ LASSERT(ll_read_key_usage(key) > 0);
LASSERT(ctx2gctx_keyring(ctx)->gck_key == NULL);
LASSERT(!key_get_payload(key, 0));
struct ptlrpc_cli_ctx *new_ctx,
struct key *key)
{
- struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
- struct hlist_node __maybe_unused *hnode;
- struct ptlrpc_cli_ctx *ctx;
- cfs_time_t now;
- ENTRY;
+ struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
+ struct hlist_node __maybe_unused *hnode;
+ struct ptlrpc_cli_ctx *ctx;
+ time64_t now;
- LASSERT(sec_is_reverse(sec));
+ ENTRY;
+ LASSERT(sec_is_reverse(sec));
spin_lock(&sec->ps_lock);
- now = cfs_time_current_sec();
+ now = ktime_get_real_seconds();
/* set all existing ctxs short expiry */
cfs_hlist_for_each_entry(ctx, hnode, &gsec_kr->gsk_clist, cc_cache) {
char *coinfo;
int coinfo_size;
const char *sec_part_flags = "";
- char svc_flag = '\0';
+ char svc_flag = '-';
ENTRY;
LASSERT(imp != NULL);
construct_key_desc(desc, sizeof(desc), sec, vcred->vc_uid);
/* callout info format:
- * secid:mech:uid:gid:sec_flags:svc_flag:svc_type:peer_nid:target_uuid
+ * secid:mech:uid:gid:sec_flags:svc_flag:svc_type:peer_nid:target_uuid:
+ * self_nid:pid
*/
- coinfo_size = sizeof(struct obd_uuid) + MAX_OBD_NAME + 64;
- OBD_ALLOC(coinfo, coinfo_size);
- if (coinfo == NULL)
- goto out;
-
- snprintf(coinfo, coinfo_size, "%d:%s:%u:%u:%s:%c:%d:"LPX64":%s:"LPX64,
+ coinfo_size = sizeof(struct obd_uuid) + MAX_OBD_NAME + 64;
+ OBD_ALLOC(coinfo, coinfo_size);
+ if (coinfo == NULL)
+ goto out;
+
+ /* Last callout parameter is pid of process whose namespace will be used
+ * for credentials' retrieval.
+ * For user's credentials (in which case sec_part_flags is empty), use
+ * current PID instead of import's reference PID to get reference
+ * namespace. */
+ snprintf(coinfo, coinfo_size, "%d:%s:%u:%u:%s:%c:%d:%#llx:%s:%#llx:%d",
sec->ps_id, sec2gsec(sec)->gs_mech->gm_name,
vcred->vc_uid, vcred->vc_gid,
sec_part_flags, svc_flag, import_to_gss_svc(imp),
imp->imp_connection->c_peer.nid, imp->imp_obd->obd_name,
- imp->imp_connection->c_self);
+ imp->imp_connection->c_self,
+ sec_part_flags[0] == '\0' ?
+ current_pid() : imp->imp_sec_refpid);
CDEBUG(D_SEC, "requesting key for %s\n", desc);
if (likely(ctx)) {
LASSERT(atomic_read(&ctx->cc_refcount) >= 1);
LASSERT(ctx2gctx_keyring(ctx)->gck_key == key);
- LASSERT(atomic_read(&key->usage) >= 2);
+ LASSERT(ll_read_key_usage(key) >= 2);
/* simply take a ref and return. it's upper layer's
* responsibility to detect & replace dead ctx. */
static
int gss_sec_display_kr(struct ptlrpc_sec *sec, struct seq_file *seq)
{
- struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
- struct hlist_node __maybe_unused *pos, *next;
- struct ptlrpc_cli_ctx *ctx;
- struct gss_cli_ctx *gctx;
- time_t now = cfs_time_current_sec();
- ENTRY;
+ struct gss_sec_keyring *gsec_kr = sec2gsec_keyring(sec);
+ struct hlist_node __maybe_unused *pos, *next;
+ struct ptlrpc_cli_ctx *ctx;
+ struct gss_cli_ctx *gctx;
+ time64_t now = ktime_get_real_seconds();
+ ENTRY;
spin_lock(&sec->ps_lock);
cfs_hlist_for_each_entry_safe(ctx, pos, next,
&gsec_kr->gsk_clist, cc_cache) {
snprintf(mech, sizeof(mech), "N/A");
mech[sizeof(mech) - 1] = '\0';
- seq_printf(seq, "%p: uid %u, ref %d, expire %lu(%+ld), fl %s, "
- "seq %d, win %u, key %08x(ref %d), "
- "hdl "LPX64":"LPX64", mech: %s\n",
+ seq_printf(seq,
+ "%p: uid %u, ref %d, expire %lld(%+lld), fl %s, seq %d, win %u, key %08x(ref %d), hdl %#llx:%#llx, mech: %s\n",
ctx, ctx->cc_vcred.vc_uid,
atomic_read(&ctx->cc_refcount),
ctx->cc_expire,
atomic_read(&gctx->gc_seq),
gctx->gc_win,
key ? key->serial : 0,
- key ? atomic_read(&key->usage) : 0,
+ key ? ll_read_key_usage(key) : 0,
gss_handle_to_u64(&gctx->gc_handle),
gss_handle_to_u64(&gctx->gc_svc_handle),
mech);
static
int sec_install_rctx_kr(struct ptlrpc_sec *sec,
- struct ptlrpc_svc_ctx *svc_ctx)
+ struct ptlrpc_svc_ctx *svc_ctx)
{
- struct ptlrpc_cli_ctx *cli_ctx;
- struct vfs_cred vcred = { 0, 0 };
- int rc;
+ struct ptlrpc_cli_ctx *cli_ctx;
+ struct vfs_cred vcred = { .vc_uid = 0 };
+ int rc;
LASSERT(sec);
LASSERT(svc_ctx);
static
int sec_install_rctx_kr(struct ptlrpc_sec *sec,
- struct ptlrpc_svc_ctx *svc_ctx)
+ struct ptlrpc_svc_ctx *svc_ctx)
{
- struct ptlrpc_cli_ctx *cli_ctx = NULL;
- struct key *key;
- struct vfs_cred vcred = { 0, 0 };
- char desc[64];
- int rc;
+ struct ptlrpc_cli_ctx *cli_ctx = NULL;
+ struct key *key;
+ struct vfs_cred vcred = { .vc_uid = 0 };
+ char desc[64];
+ int rc;
LASSERT(sec);
LASSERT(svc_ctx);