From dfc166d174c1550dab8b4528232449e3e0d8f9e1 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 9 Aug 2010 14:48:12 -0700 Subject: [PATCH] Limit sysfs name to KOBJ_NAME_LEN It appears that in earlier kernels the maximum name length of a kobject was KOBJ_NAME_LEN (20) bytes. This was later extended to dynamically allocate enough memory if it was over KOBJ_NAME_LEN, and finally it was always made dynamic. Unfortunately, util this last step happened it doesn't look like it always safe to use names larger than KOBJ_NAME_LEN. For example, under the RHEL5 2.6.18 kernel if the kobject name length exceeds KOBJ_NAME_LEN a NULL dereference is tripped. To avoid this issue the build system has been update to check to see if KOBJ_NAME_LEN is defined. If it is we have to assume the maximum kobject name length is only 20 bytes. This 20 byte name must minimally include the following components. /[@snapshot[partition]] --- config/kernel-kobj-name-len.m4 | 21 +++++++++++++++++++++ config/kernel.m4 | 1 + 2 files changed, 22 insertions(+) create mode 100644 config/kernel-kobj-name-len.m4 diff --git a/config/kernel-kobj-name-len.m4 b/config/kernel-kobj-name-len.m4 new file mode 100644 index 0000000000..5363a41ca2 --- /dev/null +++ b/config/kernel-kobj-name-len.m4 @@ -0,0 +1,21 @@ +dnl # +dnl # 2.6.27 API change, +dnl # kobject KOBJ_NAME_LEN static limit removed. All users of this +dnl # constant were removed prior to 2.6.27, but to be on the safe +dnl # side this check ensures the constant is undefined. +dnl # +AC_DEFUN([ZFS_AC_KERNEL_KOBJ_NAME_LEN], [ + AC_MSG_CHECKING([whether kernel defines KOBJ_NAME_LEN]) + ZFS_LINUX_TRY_COMPILE([ + #include + ],[ + int val; + val = KOBJ_NAME_LEN; + ],[ + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_KOBJ_NAME_LEN, 1, + [kernel defines KOBJ_NAME_LEN]) + ],[ + AC_MSG_RESULT([no]) + ]) +]) diff --git a/config/kernel.m4 b/config/kernel.m4 index ca61dfd174..4c06981dcc 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -7,6 +7,7 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [ ZFS_AC_KERNEL_CONFIG ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS ZFS_AC_KERNEL_TYPE_FMODE_T + ZFS_AC_KERNEL_KOBJ_NAME_LEN ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE