From 726897c87c42c1a74cae46795acda1a88ef43605 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Sat, 27 Jun 2020 05:32:37 -0600 Subject: [PATCH] LU-13127 ptlrpc: don't require CONFIG_CRYPTO_CRC32 Don't require CONFIG_CRYPTO_CRC32 to build if not configured, as it may not be available for all kernels and is easily fixed. Consolidate the early reply code in sec_plain.c to also call lustre_msg_calc_cksum() to reduce code duplication. Fixes: e1a0f602a608 ("LU-13127 libcfs: make noise to console if CRC32 is missing") Signed-off-by: Andreas Dilger Change-Id: I00511df418ddfbd8522936cf2bc0f3193d2540e5 Reviewed-on: https://review.whamcloud.com/39201 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alexey Lyashkov Reviewed-by: Sebastien Buisson Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 14 -------------- lustre/include/lustre_net.h | 2 +- lustre/ptlrpc/pack_generic.c | 17 ++++++++++++----- lustre/ptlrpc/sec_null.c | 10 +++++----- lustre/ptlrpc/sec_plain.c | 18 +++--------------- 5 files changed, 21 insertions(+), 40 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 0152d51..dcf8028 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -1289,19 +1289,6 @@ cache_detail_writers_atomic, [ EXTRA_KCFLAGS="$tmp_flags" ]) # LIBCFS_CACHE_DETAIL_WRITERS -# -# LIBCFS_CONFIG_CRYPTO_CRC32 -# -# The kernel must support CONFIG_CRYPTO_CRC32 to RPC checksumming -# -AC_DEFUN([LIBCFS_CONFIG_CRYPTO_CRC32], [ -LB_CHECK_CONFIG_IM([CRYPTO_CRC32], [], - [AC_MSG_ERROR([ - -Lustre requires that CONFIG_CRYPTO_CRC32 is enabled in your kernel. -])]) -]) # LIBCFS_CONFIG_CRYPTO_CRC32 - AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [] ) AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], []) @@ -1314,7 +1301,6 @@ AC_DEFUN([LIBCFS_PROG_LINUX], [ AC_MSG_NOTICE([LibCFS kernel checks ==============================================================================]) LIBCFS_CONFIG_PANIC_DUMPLOG -LIBCFS_CONFIG_CRYPTO_CRC32 # 3.11 LIBCFS_KTIME_GET_TS64 diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index 2e631d2..0240880 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -2378,7 +2378,7 @@ timeout_t lustre_msg_get_service_timeout(struct lustre_msg *msg); char *lustre_msg_get_jobid(struct lustre_msg *msg); __u32 lustre_msg_get_cksum(struct lustre_msg *msg); __u64 lustre_msg_get_mbits(struct lustre_msg *msg); -__u32 lustre_msg_calc_cksum(struct lustre_msg *msg); +__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, __u32 buf); void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle); void lustre_msg_set_type(struct lustre_msg *msg, __u32 type); void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc); diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index 973e3f0..0e382c4 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -40,6 +40,10 @@ #define DEBUG_SUBSYSTEM S_RPC +#ifndef CONFIG_CRYPTO_CRC32 +#include +#endif + #include #include @@ -1374,20 +1378,23 @@ __u64 lustre_msg_get_mbits(struct lustre_msg *msg) } } -__u32 lustre_msg_calc_cksum(struct lustre_msg *msg) +__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, __u32 buf) { switch (msg->lm_magic) { case LUSTRE_MSG_MAGIC_V2: { - struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg); - __u32 len = lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF); - - unsigned int hsize = 4; + struct ptlrpc_body *pb = lustre_msg_buf_v2(msg, buf, 0); + __u32 len = lustre_msg_buflen(msg, buf); __u32 crc; LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg); +#ifdef CONFIG_CRYPTO_CRC32 + unsigned int hsize = 4; cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb, len, NULL, 0, (unsigned char *)&crc, &hsize); +#else + crc = crc32_le(~(__u32)0, (unsigned char *)pb, len); +#endif return crc; } default: diff --git a/lustre/ptlrpc/sec_null.c b/lustre/ptlrpc/sec_null.c index 6ad0c0a..1687033 100644 --- a/lustre/ptlrpc/sec_null.c +++ b/lustre/ptlrpc/sec_null.c @@ -100,7 +100,8 @@ int null_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req) if (req->rq_early) { cksums = lustre_msg_get_cksum(req->rq_repdata); - cksumc = lustre_msg_calc_cksum(req->rq_repmsg); + cksumc = lustre_msg_calc_cksum(req->rq_repmsg, + MSG_PTLRPC_BODY_OFF); if (cksumc != cksums) { CDEBUG(D_SEC, @@ -355,18 +356,17 @@ int null_authorize(struct ptlrpc_request *req) rs->rs_repbuf->lm_secflvr = SPTLRPC_FLVR_NULL; rs->rs_repdata_len = req->rq_replen; + req->rq_reply_off = 0; if (likely(req->rq_packed_final)) { if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT) req->rq_reply_off = lustre_msg_early_size(); - else - req->rq_reply_off = 0; } else { __u32 cksum; - cksum = lustre_msg_calc_cksum(rs->rs_repbuf); + cksum = lustre_msg_calc_cksum(rs->rs_repbuf, + MSG_PTLRPC_BODY_OFF); lustre_msg_set_cksum(rs->rs_repbuf, cksum); - req->rq_reply_off = 0; } return 0; diff --git a/lustre/ptlrpc/sec_plain.c b/lustre/ptlrpc/sec_plain.c index ea9a469..3d75653 100644 --- a/lustre/ptlrpc/sec_plain.c +++ b/lustre/ptlrpc/sec_plain.c @@ -216,7 +216,6 @@ int plain_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req) { struct lustre_msg *msg = req->rq_repdata; struct plain_header *phdr; - __u32 cksum; bool swabbed; ENTRY; @@ -251,12 +250,8 @@ int plain_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req) } if (unlikely(req->rq_early)) { - unsigned int hsize = 4; + __u32 cksum = lustre_msg_calc_cksum(msg, PLAIN_PACK_MSG_OFF); - 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", @@ -890,20 +885,13 @@ int plain_authorize(struct ptlrpc_request *req) phdr->ph_flags |= PLAIN_FL_BULK; rs->rs_repdata_len = len; + req->rq_reply_off = 0; if (likely(req->rq_packed_final)) { if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT) req->rq_reply_off = plain_at_offset; - else - req->rq_reply_off = 0; } else { - 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; + msg->lm_cksum = lustre_msg_calc_cksum(msg, PLAIN_PACK_MSG_OFF); } RETURN(0); -- 1.8.3.1