X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fsec_plain.c;h=ec9ee7bd2f47e5b94ddb9e611ce588c96fea5acc;hb=862cdaa5db90edaeee64e21b2b7b0dba3986a3da;hp=0e2bd160095bf2a130d2826114b20a9920cd2aed;hpb=1f0e2723f37eb86f3a88807d1200e78c10ab9565;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/sec_plain.c b/lustre/ptlrpc/sec_plain.c index 0e2bd16..ec9ee7b 100644 --- a/lustre/ptlrpc/sec_plain.c +++ b/lustre/ptlrpc/sec_plain.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,6 +26,8 @@ /* * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2011, 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -38,9 +38,6 @@ * Author: Eric Mei */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif #define DEBUG_SUBSYSTEM S_SEC #ifndef __KERNEL__ @@ -55,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; }; @@ -161,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) @@ -273,14 +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) { - CWARN("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 */ @@ -351,8 +352,8 @@ int plain_cli_unwrap_bulk(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req, struct ptlrpc_bulk_desc *desc) { - struct ptlrpc_bulk_sec_desc *bsdr, *bsdv; - struct plain_bulk_token *tokenr, *tokenv; + struct ptlrpc_bulk_sec_desc *bsdv; + struct plain_bulk_token *tokenv; int rc; #ifdef __KERNEL__ int i, nob; @@ -362,8 +363,6 @@ int plain_cli_unwrap_bulk(struct ptlrpc_cli_ctx *ctx, LASSERT(req->rq_reqbuf->lm_bufcount == PLAIN_PACK_SEGMENTS); LASSERT(req->rq_repdata->lm_bufcount == PLAIN_PACK_SEGMENTS); - bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0); - tokenr = (struct plain_bulk_token *) bsdr->bsd_data; bsdv = lustre_msg_buf(req->rq_repdata, PLAIN_PACK_BULK_OFF, 0); tokenv = (struct plain_bulk_token *) bsdv->bsd_data; @@ -399,11 +398,11 @@ 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) { @@ -420,7 +419,7 @@ struct ptlrpc_cli_ctx *plain_sec_install_ctx(struct plain_sec *plsec) 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); + spin_lock_init(&ctx->cc_lock); CFS_INIT_LIST_HEAD(&ctx->cc_req_list); CFS_INIT_LIST_HEAD(&ctx->cc_gc_chain); @@ -431,9 +430,9 @@ struct ptlrpc_cli_ctx *plain_sec_install_ctx(struct plain_sec *plsec) cfs_atomic_inc(&ctx->cc_refcount); /* for caller */ } - cfs_write_unlock(&plsec->pls_lock); + write_unlock(&plsec->pls_lock); - return ctx; + return ctx; } static @@ -479,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; + 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; + spin_lock_init(&sec->ps_lock); CFS_INIT_LIST_HEAD(&sec->ps_gc_list); sec->ps_gc_interval = 0; sec->ps_gc_next = 0; @@ -512,20 +511,20 @@ 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) + cfs_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 @@ -555,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); @@ -591,7 +590,7 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec, LASSERT(!req->rq_pool); alloc_len = size_roundup_power2(alloc_len); - OBD_ALLOC(req->rq_reqbuf, alloc_len); + OBD_ALLOC_LARGE(req->rq_reqbuf, alloc_len); if (!req->rq_reqbuf) RETURN(-ENOMEM); @@ -617,7 +616,7 @@ void plain_free_reqbuf(struct ptlrpc_sec *sec, { ENTRY; if (!req->rq_pool) { - OBD_FREE(req->rq_reqbuf, req->rq_reqbuf_len); + OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len); req->rq_reqbuf = NULL; req->rq_reqbuf_len = 0; } @@ -648,7 +647,7 @@ int plain_alloc_repbuf(struct ptlrpc_sec *sec, alloc_len = size_roundup_power2(alloc_len); - OBD_ALLOC(req->rq_repbuf, alloc_len); + OBD_ALLOC_LARGE(req->rq_repbuf, alloc_len); if (!req->rq_repbuf) RETURN(-ENOMEM); @@ -661,7 +660,7 @@ void plain_free_repbuf(struct ptlrpc_sec *sec, struct ptlrpc_request *req) { ENTRY; - OBD_FREE(req->rq_repbuf, req->rq_repbuf_len); + OBD_FREE_LARGE(req->rq_repbuf, req->rq_repbuf_len); req->rq_repbuf = NULL; req->rq_repbuf_len = 0; EXIT; @@ -702,13 +701,13 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec, if (req->rq_reqbuf_len < newbuf_size) { newbuf_size = size_roundup_power2(newbuf_size); - OBD_ALLOC(newbuf, newbuf_size); + OBD_ALLOC_LARGE(newbuf, newbuf_size); if (newbuf == NULL) RETURN(-ENOMEM); memcpy(newbuf, req->rq_reqbuf, req->rq_reqbuf_len); - OBD_FREE(req->rq_reqbuf, req->rq_reqbuf_len); + OBD_FREE_LARGE(req->rq_reqbuf, req->rq_reqbuf_len); req->rq_reqbuf = newbuf; req->rq_reqbuf_len = newbuf_size; req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, @@ -828,7 +827,7 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize) /* pre-allocated */ LASSERT(rs->rs_size >= rs_size); } else { - OBD_ALLOC(rs, rs_size); + OBD_ALLOC_LARGE(rs, rs_size); if (rs == NULL) RETURN(-ENOMEM); @@ -856,7 +855,7 @@ void plain_free_rs(struct ptlrpc_reply_state *rs) cfs_atomic_dec(&rs->rs_svc_ctx->sc_refcount); if (!rs->rs_prealloc) - OBD_FREE(rs, rs->rs_size); + OBD_FREE_LARGE(rs, rs->rs_size); EXIT; } @@ -896,10 +895,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); @@ -911,7 +913,7 @@ int plain_svc_unwrap_bulk(struct ptlrpc_request *req, { struct ptlrpc_reply_state *rs = req->rq_reply_state; struct ptlrpc_bulk_sec_desc *bsdr, *bsdv; - struct plain_bulk_token *tokenr, *tokenv; + struct plain_bulk_token *tokenr; int rc; LASSERT(req->rq_bulk_write); @@ -920,7 +922,6 @@ int plain_svc_unwrap_bulk(struct ptlrpc_request *req, bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0); tokenr = (struct plain_bulk_token *) bsdr->bsd_data; bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0); - tokenv = (struct plain_bulk_token *) bsdv->bsd_data; bsdv->bsd_version = 0; bsdv->bsd_type = SPTLRPC_BULK_DEFAULT; @@ -946,14 +947,13 @@ int plain_svc_wrap_bulk(struct ptlrpc_request *req, { struct ptlrpc_reply_state *rs = req->rq_reply_state; struct ptlrpc_bulk_sec_desc *bsdr, *bsdv; - struct plain_bulk_token *tokenr, *tokenv; + struct plain_bulk_token *tokenv; int rc; LASSERT(req->rq_bulk_read); LASSERT(req->rq_pack_bulk); bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0); - tokenr = (struct plain_bulk_token *) bsdr->bsd_data; bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0); tokenv = (struct plain_bulk_token *) bsdv->bsd_data;