X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fsec_plain.c;h=6adce851130bbe05ab8a32e23cec0abd252c2c4c;hb=6d8c562350f9f0709a1280de5e0734deaac236c1;hp=d123e30aa175f781b71ab0c58c2baf10c7d7a9a8;hpb=e2af7fb3c91dfb13d34d8e1b2f2df8c09621f768;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/sec_plain.c b/lustre/ptlrpc/sec_plain.c index d123e30..6adce85 100644 --- a/lustre/ptlrpc/sec_plain.c +++ b/lustre/ptlrpc/sec_plain.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Whamcloud, Inc. + * Copyright (c) 2011, 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -52,7 +52,7 @@ struct plain_sec { struct ptlrpc_sec pls_base; - cfs_rwlock_t pls_lock; + rwlock_t pls_lock; struct ptlrpc_cli_ctx *pls_ctx; }; @@ -158,19 +158,19 @@ static int plain_verify_bulk_csum(struct ptlrpc_bulk_desc *desc, #ifdef __KERNEL__ static void corrupt_bulk_data(struct ptlrpc_bulk_desc *desc) { - char *ptr; - unsigned int off, i; - - for (i = 0; i < desc->bd_iov_count; i++) { - if (desc->bd_iov[i].kiov_len == 0) - continue; - - ptr = cfs_kmap(desc->bd_iov[i].kiov_page); - off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK; - ptr[off] ^= 0x1; - cfs_kunmap(desc->bd_iov[i].kiov_page); - return; - } + char *ptr; + unsigned int off, i; + + for (i = 0; i < desc->bd_iov_count; i++) { + if (desc->bd_iov[i].kiov_len == 0) + continue; + + ptr = kmap(desc->bd_iov[i].kiov_page); + off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK; + ptr[off] ^= 0x1; + kunmap(desc->bd_iov[i].kiov_page); + return; + } } #else static void corrupt_bulk_data(struct ptlrpc_bulk_desc *desc) @@ -270,15 +270,18 @@ int plain_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req) } if (unlikely(req->rq_early)) { - cksum = crc32_le(!(__u32) 0, - lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0), - lustre_msg_buflen(msg, PLAIN_PACK_MSG_OFF)); - if (cksum != msg->lm_cksum) { - CDEBUG(D_SEC, - "early reply checksum mismatch: %08x != %08x\n", - cpu_to_le32(cksum), msg->lm_cksum); - RETURN(-EINVAL); - } + unsigned int hsize = 4; + + cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, + lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0), + lustre_msg_buflen(msg, PLAIN_PACK_MSG_OFF), + NULL, 0, (unsigned char *)&cksum, &hsize); + if (cksum != msg->lm_cksum) { + CDEBUG(D_SEC, + "early reply checksum mismatch: %08x != %08x\n", + cpu_to_le32(cksum), msg->lm_cksum); + RETURN(-EINVAL); + } } else { /* whether we sent with bulk or not, we expect the same * in reply, except for early reply */ @@ -395,59 +398,59 @@ int plain_cli_unwrap_bulk(struct ptlrpc_cli_ctx *ctx, static struct ptlrpc_cli_ctx *plain_sec_install_ctx(struct plain_sec *plsec) { - struct ptlrpc_cli_ctx *ctx, *ctx_new; + struct ptlrpc_cli_ctx *ctx, *ctx_new; - OBD_ALLOC_PTR(ctx_new); + OBD_ALLOC_PTR(ctx_new); - cfs_write_lock(&plsec->pls_lock); + write_lock(&plsec->pls_lock); - ctx = plsec->pls_ctx; - if (ctx) { - cfs_atomic_inc(&ctx->cc_refcount); - - if (ctx_new) - OBD_FREE_PTR(ctx_new); - } else if (ctx_new) { - ctx = ctx_new; - - cfs_atomic_set(&ctx->cc_refcount, 1); /* for cache */ - ctx->cc_sec = &plsec->pls_base; - ctx->cc_ops = &plain_ctx_ops; - ctx->cc_expire = 0; - ctx->cc_flags = PTLRPC_CTX_CACHED | PTLRPC_CTX_UPTODATE; - ctx->cc_vcred.vc_uid = 0; - cfs_spin_lock_init(&ctx->cc_lock); - CFS_INIT_LIST_HEAD(&ctx->cc_req_list); - CFS_INIT_LIST_HEAD(&ctx->cc_gc_chain); - - plsec->pls_ctx = ctx; - cfs_atomic_inc(&plsec->pls_base.ps_nctx); - cfs_atomic_inc(&plsec->pls_base.ps_refcount); - - cfs_atomic_inc(&ctx->cc_refcount); /* for caller */ - } + ctx = plsec->pls_ctx; + if (ctx) { + atomic_inc(&ctx->cc_refcount); + + if (ctx_new) + OBD_FREE_PTR(ctx_new); + } else if (ctx_new) { + ctx = ctx_new; + + atomic_set(&ctx->cc_refcount, 1); /* for cache */ + ctx->cc_sec = &plsec->pls_base; + ctx->cc_ops = &plain_ctx_ops; + ctx->cc_expire = 0; + ctx->cc_flags = PTLRPC_CTX_CACHED | PTLRPC_CTX_UPTODATE; + ctx->cc_vcred.vc_uid = 0; + spin_lock_init(&ctx->cc_lock); + CFS_INIT_LIST_HEAD(&ctx->cc_req_list); + CFS_INIT_LIST_HEAD(&ctx->cc_gc_chain); + + plsec->pls_ctx = ctx; + atomic_inc(&plsec->pls_base.ps_nctx); + atomic_inc(&plsec->pls_base.ps_refcount); - cfs_write_unlock(&plsec->pls_lock); + atomic_inc(&ctx->cc_refcount); /* for caller */ + } - return ctx; + write_unlock(&plsec->pls_lock); + + return ctx; } static void plain_destroy_sec(struct ptlrpc_sec *sec) { - struct plain_sec *plsec = sec2plsec(sec); - ENTRY; + struct plain_sec *plsec = sec2plsec(sec); + ENTRY; - LASSERT(sec->ps_policy == &plain_policy); - LASSERT(sec->ps_import); - LASSERT(cfs_atomic_read(&sec->ps_refcount) == 0); - LASSERT(cfs_atomic_read(&sec->ps_nctx) == 0); - LASSERT(plsec->pls_ctx == NULL); + LASSERT(sec->ps_policy == &plain_policy); + LASSERT(sec->ps_import); + LASSERT(atomic_read(&sec->ps_refcount) == 0); + LASSERT(atomic_read(&sec->ps_nctx) == 0); + LASSERT(plsec->pls_ctx == NULL); - class_import_put(sec->ps_import); + class_import_put(sec->ps_import); - OBD_FREE_PTR(plsec); - EXIT; + OBD_FREE_PTR(plsec); + EXIT; } static @@ -475,17 +478,17 @@ struct ptlrpc_sec *plain_create_sec(struct obd_import *imp, /* * initialize plain_sec */ - cfs_rwlock_init(&plsec->pls_lock); - plsec->pls_ctx = NULL; - - sec = &plsec->pls_base; - sec->ps_policy = &plain_policy; - cfs_atomic_set(&sec->ps_refcount, 0); - cfs_atomic_set(&sec->ps_nctx, 0); - sec->ps_id = sptlrpc_get_next_secid(); - sec->ps_import = class_import_get(imp); - sec->ps_flvr = *sf; - cfs_spin_lock_init(&sec->ps_lock); + rwlock_init(&plsec->pls_lock); + plsec->pls_ctx = NULL; + + sec = &plsec->pls_base; + sec->ps_policy = &plain_policy; + atomic_set(&sec->ps_refcount, 0); + atomic_set(&sec->ps_nctx, 0); + sec->ps_id = sptlrpc_get_next_secid(); + sec->ps_import = class_import_get(imp); + sec->ps_flvr = *sf; + spin_lock_init(&sec->ps_lock); CFS_INIT_LIST_HEAD(&sec->ps_gc_list); sec->ps_gc_interval = 0; sec->ps_gc_next = 0; @@ -508,35 +511,35 @@ struct ptlrpc_cli_ctx *plain_lookup_ctx(struct ptlrpc_sec *sec, struct vfs_cred *vcred, int create, int remove_dead) { - struct plain_sec *plsec = sec2plsec(sec); - struct ptlrpc_cli_ctx *ctx; - ENTRY; + struct plain_sec *plsec = sec2plsec(sec); + struct ptlrpc_cli_ctx *ctx; + ENTRY; - cfs_read_lock(&plsec->pls_lock); - ctx = plsec->pls_ctx; - if (ctx) - cfs_atomic_inc(&ctx->cc_refcount); - cfs_read_unlock(&plsec->pls_lock); + read_lock(&plsec->pls_lock); + ctx = plsec->pls_ctx; + if (ctx) + atomic_inc(&ctx->cc_refcount); + read_unlock(&plsec->pls_lock); - if (unlikely(ctx == NULL)) - ctx = plain_sec_install_ctx(plsec); + if (unlikely(ctx == NULL)) + ctx = plain_sec_install_ctx(plsec); - RETURN(ctx); + RETURN(ctx); } static void plain_release_ctx(struct ptlrpc_sec *sec, struct ptlrpc_cli_ctx *ctx, int sync) { - LASSERT(cfs_atomic_read(&sec->ps_refcount) > 0); - LASSERT(cfs_atomic_read(&sec->ps_nctx) > 0); - LASSERT(cfs_atomic_read(&ctx->cc_refcount) == 0); - LASSERT(ctx->cc_sec == sec); + LASSERT(atomic_read(&sec->ps_refcount) > 0); + LASSERT(atomic_read(&sec->ps_nctx) > 0); + LASSERT(atomic_read(&ctx->cc_refcount) == 0); + LASSERT(ctx->cc_sec == sec); - OBD_FREE_PTR(ctx); + OBD_FREE_PTR(ctx); - cfs_atomic_dec(&sec->ps_nctx); - sptlrpc_sec_put(sec); + atomic_dec(&sec->ps_nctx); + sptlrpc_sec_put(sec); } static @@ -551,10 +554,10 @@ int plain_flush_ctx_cache(struct ptlrpc_sec *sec, if (uid != -1) RETURN(0); - cfs_write_lock(&plsec->pls_lock); + write_lock(&plsec->pls_lock); ctx = plsec->pls_ctx; plsec->pls_ctx = NULL; - cfs_write_unlock(&plsec->pls_lock); + write_unlock(&plsec->pls_lock); if (ctx) sptlrpc_cli_ctx_put(ctx, 1); @@ -702,6 +705,15 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec, if (newbuf == NULL) RETURN(-ENOMEM); + /* Must lock this, so that otherwise unprotected change of + * rq_reqmsg is not racing with parallel processing of + * imp_replay_list traversing threads. See LU-3333 + * This is a bandaid at best, we really need to deal with this + * in request enlarging code before unpacking that's already + * there */ + if (req->rq_import) + spin_lock(&req->rq_import->imp_lock); + memcpy(newbuf, req->rq_reqbuf, req->rq_reqbuf_len); OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len); @@ -709,6 +721,9 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec, req->rq_reqbuf_len = newbuf_size; req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_MSG_OFF, 0); + + if (req->rq_import) + spin_unlock(&req->rq_import->imp_lock); } _sptlrpc_enlarge_msg_inplace(req->rq_reqbuf, PLAIN_PACK_MSG_OFF, @@ -724,7 +739,7 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec, ****************************************/ static struct ptlrpc_svc_ctx plain_svc_ctx = { - .sc_refcount = CFS_ATOMIC_INIT(1), + .sc_refcount = ATOMIC_INIT(1), .sc_policy = &plain_policy, }; @@ -791,13 +806,13 @@ int plain_accept(struct ptlrpc_request *req) req->rq_pack_bulk = 1; } - req->rq_reqmsg = lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0); - req->rq_reqlen = msg->lm_buflens[PLAIN_PACK_MSG_OFF]; + req->rq_reqmsg = lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0); + req->rq_reqlen = msg->lm_buflens[PLAIN_PACK_MSG_OFF]; - req->rq_svc_ctx = &plain_svc_ctx; - cfs_atomic_inc(&req->rq_svc_ctx->sc_refcount); + req->rq_svc_ctx = &plain_svc_ctx; + atomic_inc(&req->rq_svc_ctx->sc_refcount); - RETURN(SECSVC_OK); + RETURN(SECSVC_OK); } static @@ -831,29 +846,29 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize) rs->rs_size = rs_size; } - rs->rs_svc_ctx = req->rq_svc_ctx; - cfs_atomic_inc(&req->rq_svc_ctx->sc_refcount); - rs->rs_repbuf = (struct lustre_msg *) (rs + 1); - rs->rs_repbuf_len = rs_size - sizeof(*rs); + rs->rs_svc_ctx = req->rq_svc_ctx; + atomic_inc(&req->rq_svc_ctx->sc_refcount); + rs->rs_repbuf = (struct lustre_msg *) (rs + 1); + rs->rs_repbuf_len = rs_size - sizeof(*rs); - lustre_init_msg_v2(rs->rs_repbuf, PLAIN_PACK_SEGMENTS, buflens, NULL); - rs->rs_msg = lustre_msg_buf_v2(rs->rs_repbuf, PLAIN_PACK_MSG_OFF, 0); + lustre_init_msg_v2(rs->rs_repbuf, PLAIN_PACK_SEGMENTS, buflens, NULL); + rs->rs_msg = lustre_msg_buf_v2(rs->rs_repbuf, PLAIN_PACK_MSG_OFF, 0); - req->rq_reply_state = rs; - RETURN(0); + req->rq_reply_state = rs; + RETURN(0); } static void plain_free_rs(struct ptlrpc_reply_state *rs) { - ENTRY; + ENTRY; - LASSERT(cfs_atomic_read(&rs->rs_svc_ctx->sc_refcount) > 1); - cfs_atomic_dec(&rs->rs_svc_ctx->sc_refcount); + LASSERT(atomic_read(&rs->rs_svc_ctx->sc_refcount) > 1); + atomic_dec(&rs->rs_svc_ctx->sc_refcount); - if (!rs->rs_prealloc) - OBD_FREE_LARGE(rs, rs->rs_size); - EXIT; + if (!rs->rs_prealloc) + OBD_FREE_LARGE(rs, rs->rs_size); + EXIT; } static @@ -892,10 +907,13 @@ int plain_authorize(struct ptlrpc_request *req) else req->rq_reply_off = 0; } else { - msg->lm_cksum = crc32_le(!(__u32) 0, - lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0), - lustre_msg_buflen(msg, PLAIN_PACK_MSG_OFF)); - req->rq_reply_off = 0; + unsigned int hsize = 4; + + cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, + lustre_msg_buf(msg, PLAIN_PACK_MSG_OFF, 0), + lustre_msg_buflen(msg, PLAIN_PACK_MSG_OFF), + NULL, 0, (unsigned char *)&msg->lm_cksum, &hsize); + req->rq_reply_off = 0; } RETURN(0);