Blame SOURCES/cryptsetup-avoid-rh-kernel-bug.patch

7751a4
--- a/lib/crypto_backend/crypto_cipher_kernel.c
7751a4
+++ b/lib/crypto_backend/crypto_cipher_kernel.c
7751a4
@@ -31,6 +31,7 @@
7751a4
 #ifdef ENABLE_AF_ALG
7751a4
 
7751a4
 #include <linux/if_alg.h>
7751a4
+#include <sys/utsname.h>
7751a4
 
7751a4
 #ifndef AF_ALG
7751a4
 #define AF_ALG 38
ceb0a2
@@ -88,6 +89,35 @@ int crypt_cipher_blocksize(const char *n
ceb0a2
 	return ca ? ca->blocksize : -EINVAL;
7751a4
 }
7751a4
 
7751a4
+static size_t pagesize(size_t defsize)
7751a4
+{
7751a4
+	long r = sysconf(_SC_PAGESIZE);
7751a4
+	return r < 0 ? defsize : (size_t)r;
7751a4
+}
7751a4
+
7751a4
+static int check_rh_kernel_version(void)
7751a4
+{
7751a4
+	unsigned maj, mid, min, rel;
7751a4
+	static struct utsname uts = {{ 0 }};
7751a4
+	size_t ps = pagesize(32768);
7751a4
+
7751a4
+	if (ps < 32768)
7751a4
+		return 0;
7751a4
+
7751a4
+	if (!*uts.release && uname(&uts) < 0)
7751a4
+		return -ENOTSUP;
7751a4
+	/*
7751a4
+	 * RH kernels 3.10.0-185 and lower are affected by a crypto API kernel
7751a4
+	 * socket bug. The bug only manifests on archs with page size >= 32 KiB.
7751a4
+	 *
7751a4
+	 * For reference, see rhbz#1136075
7751a4
+	 */
7751a4
+	if (sscanf(uts.release, "%u.%u.%u-%u", &maj, &mid, &min, &rel) == 4)
7751a4
+		return (maj == 3 && mid == 10 && min == 0 && rel < 186) ? -ENOTSUP : 0;
7751a4
+
7751a4
+	return -ENOTSUP;
7751a4
+}
7751a4
+
7751a4
 /*
ceb0a2
  * ciphers
7751a4
  *
ceb0a2
@@ -104,6 +134,9 @@ int crypt_cipher_init(struct crypt_ciphe
ceb0a2
 		.salg_type = "skcipher",
7751a4
 	};
7751a4
 
ceb0a2
+	if (check_rh_kernel_version())
ceb0a2
+		return -ENOTSUP;
7751a4
+
7751a4
 	h = malloc(sizeof(*h));
7751a4
 	if (!h)
7751a4
 		return -ENOMEM;