Article ID: 120600, created on Mar 18, 2014, last review on May 10, 2014

  • Applies to:
  • Virtuozzo 6.0
  • Virtuozzo containers for Linux 4.7
  • Virtuozzo hypervisor

Symptoms

It is impossible to build 3rd party encryption kernel module from Gazzang, zNcrypt:

[root@localhost CU-2.6.32-042stab063.2]# more /var/lib/dkms/zncryptfs/3.3.0/build/make.log
DKMS make.log for zncryptfs-3.3.0 for kernel 2.6.32-042stab063.2 (x86_64)
Fri Feb 14 23:22:12 EST 2014
Searching known bugs on kernel...
make -C /lib/modules/2.6.32-042stab063.2/build M=/var/lib/dkms/zncryptfs/3.3.0/b
uild modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-042stab063.2'
  CC [M]  /var/lib/dkms/zncryptfs/3.3.0/build/main.o
  CC [M]  /var/lib/dkms/zncryptfs/3.3.0/build/hooks.o
  CC [M]  /var/lib/dkms/zncryptfs/3.3.0/build/messaging.o
  CC [M]  /var/lib/dkms/zncryptfs/3.3.0/build/auth.o
  CC [M]  /var/lib/dkms/zncryptfs/3.3.0/build/acl.o
  CC [M]  /var/lib/dkms/zncryptfs/3.3.0/build/profile.o
cc1: warnings being treated as errors
/var/lib/dkms/zncryptfs/3.3.0/build/profile.c: In function âzncrypt_get_cwd_path
â:
/var/lib/dkms/zncryptfs/3.3.0/build/profile.c:309: error: passing argument 1 of
â_read_lockâ from incompatible pointer type
include/linux/spinlock_api_smp.h:27: note: expected âstruct rwlock_t *â but argu
ment is of type âstruct spinlock_t *â
/var/lib/dkms/zncryptfs/3.3.0/build/profile.c:312: error: passing argument 1 of
â__read_unlockâ from incompatible pointer type
include/linux/spinlock_api_smp.h:363: note: expected âstruct rwlock_t *â but arg
ument is of type âstruct spinlock_t *â
make[2]: *** [/var/lib/dkms/zncryptfs/3.3.0/build/profile.o] Error 1
make[1]: *** [_module_/var/lib/dkms/zncryptfs/3.3.0/build] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.32-042stab063.2'
make: *** [all] Error 2

Cause

In the module function zncrypt_get_cwd_path gets incompatible variable(pointer) type passed:

/var/lib/dkms/zncryptfs/3.3.0/build/profile.c:309: error: passing argument 1 of <_read_lock> from incompatible pointer type
include/linux/spinlock_api_smp.h:27: note: expected <struct rwlock_t *> but argument is of type <struct spinlock_t *>
/var/lib/dkms/zncryptfs/3.3.0/build/profile.c:312: error: passing argument 1 of <__read_unlock> from incompatible pointer type
include/linux/spinlock_api_smp.h:363: note: expected <struct rwlock_t *> but argument is of type <struct spinlock_t *>

Cause

Taking a closer look in the code shows that these two types (struct rwlock_t and struct spinlock_t) are absolutely identical. It should be a bug in zNcrypt code.

We can tell it by looking into following files:

from include/linux/spinlock_types.h:

typedef struct {
        raw_spinlock_t raw_lock;
#ifdef CONFIG_GENERIC_LOCKBREAK
        unsigned int break_lock;
#endif
#ifdef CONFIG_DEBUG_SPINLOCK
        unsigned int magic, owner_cpu;
        void *owner;
#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
        struct lockdep_map dep_map;
#endif
} spinlock_t;

#define SPINLOCK_MAGIC          0xdead4ead

typedef struct {
        raw_rwlock_t raw_lock;
#ifdef CONFIG_GENERIC_LOCKBREAK
        unsigned int break_lock;
#endif
#ifdef CONFIG_DEBUG_SPINLOCK
        unsigned int magic, owner_cpu;
        void *owner;
#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
        struct lockdep_map dep_map;
#endif
} rwlock_t;

And from arch/x86/include/asm/spinlock_types.h:

typedef struct {
        volatile unsigned int lock;
} raw_spinlock_t;

#define __RAW_SPIN_LOCK_UNLOCKED        { 0 }

typedef struct {
        volatile unsigned int lock;
} raw_rwlock_t;

#define __RAW_RW_LOCK_UNLOCKED          { 0 }

Resolution

By implementing explicit typecasting we can compile module successfully:

[root@localhost ~]# diff -u /usr/src/zncryptfs-3.3.0/profile.c{,.orig}
--- /usr/src/zncryptfs-3.3.0/profile.c  2014-02-15 04:38:15.967686041 -0500
+++ /usr/src/zncryptfs-3.3.0/profile.c.orig     2014-02-15 04:37:39.422652152 -0500
@@ -306,10 +306,10 @@
        path_get(path);
        read_unlock(&fs->lock);
        #elif LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
-       read_lock((rwlock_t *)(&fs->lock));
+       read_lock(&fs->lock);
        *path = fs->root;
        path_get(path);
-       read_unlock((rwlock_t *)(&fs->lock));
+       read_unlock(&fs->lock);
        #else
        get_fs_pwd(fs, path);
        #endif
[root@localhost ~]#
[root@localhost ~]# zncrypt-module-setup
Removing existing zncryptfs 3.3.0 DKMS kernel modules...
Building zncryptfs 3.3.0 DKMS kernel module...
Successfully installed zncryptfs module.
[root@localhost ~]#
[root@localhost ~]# modprobe zncryptfs
[root@localhost ~]# lsmod | grep zncryptfs
zncryptfs              77431  0
[root@localhost ~]# modinfo zncryptfs
filename:       /lib/modules/2.6.32-042stab063.2/extra/zncryptfs.ko
license:        GPL v2
description:    zncryptfs (v3.3.0-734)
author:         Sergio Pena <sergio.pena@gazzang.com>
srcversion:     413AFFC59D88485CC03A373
depends:
vermagic:       2.6.32-042stab063.2 SMP mod_unload modversions
parm:           zncryptfs_stats_enabled:Enable data statistics (int)
parm:           zncryptfs_acl_cache_size:Set ACL cache size (int)
parm:           zncryptfs_acl_verbose:Display more information on an access denied (int)
parm:           zncryptfs_debug:Display debug information (int)
[root@localhost ~]#

Search Words

encryption module

zNcrypt

a26b38f94253cdfbf1028d72cf3a498b 2897d76d56d2010f4e3a28f864d69223 e8e50b42231236b82df27684e7ec0beb d02f9caf3e11b191a38179103495106f 0dd5b9380c7d4884d77587f3eb0fa8ef 0c05f0c76fec3dd785e9feafce1099a9 c62e8726973f80975db0531f1ed5c6a2

Email subscription for changes to this article
Save as PDF