Whamcloud - gitweb
LU-13127 ptlrpc: don't require CONFIG_CRYPTO_CRC32 01/39201/5
authorAndreas Dilger <adilger@whamcloud.com>
Sat, 27 Jun 2020 11:32:37 +0000 (05:32 -0600)
committerOleg Drokin <green@whamcloud.com>
Thu, 13 Aug 2020 05:58:26 +0000 (05:58 +0000)
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 <adilger@whamcloud.com>
Change-Id: I00511df418ddfbd8522936cf2bc0f3193d2540e5
Reviewed-on: https://review.whamcloud.com/39201
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexey Lyashkov <alexey.lyashkov@hpe.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/autoconf/lustre-libcfs.m4
lustre/include/lustre_net.h
lustre/ptlrpc/pack_generic.c
lustre/ptlrpc/sec_null.c
lustre/ptlrpc/sec_plain.c

index 0152d51..dcf8028 100644 (file)
@@ -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
index 2e631d2..0240880 100644 (file)
@@ -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);
index 973e3f0..0e382c4 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_RPC
 
+#ifndef CONFIG_CRYPTO_CRC32
+#include <linux/crc32.h>
+#endif
+
 #include <libcfs/libcfs.h>
 
 #include <llog_swab.h>
@@ -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:
index 6ad0c0a..1687033 100644 (file)
@@ -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;
index ea9a469..3d75653 100644 (file)
@@ -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);