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

8af939
diff -rupN cryptsetup-2.0.3.old/lib/crypto_backend/crypto_cipher_kernel.c cryptsetup-2.0.3/lib/crypto_backend/crypto_cipher_kernel.c
8af939
--- cryptsetup-2.0.3.old/lib/crypto_backend/crypto_cipher_kernel.c	2018-04-17 09:20:35.000000000 +0200
8af939
+++ cryptsetup-2.0.3/lib/crypto_backend/crypto_cipher_kernel.c	2018-05-07 14:13:45.176124062 +0200
8af939
@@ -31,6 +31,7 @@
8af939
 #ifdef ENABLE_AF_ALG
8af939
 
8af939
 #include <linux/if_alg.h>
8af939
+#include <sys/utsname.h>
8af939
 
8af939
 #ifndef AF_ALG
8af939
 #define AF_ALG 38
8af939
@@ -44,6 +45,36 @@ struct crypt_cipher {
8af939
 	int opfd;
8af939
 };
8af939
 
8af939
+ 
8af939
+static size_t pagesize(size_t defsize)
8af939
+{
8af939
+	long r = sysconf(_SC_PAGESIZE);
8af939
+	return r < 0 ? defsize : (size_t)r;
8af939
+}
8af939
+
8af939
+static int check_rh_kernel_version(void)
8af939
+{
8af939
+	unsigned maj, mid, min, rel;
8af939
+	static struct utsname uts = {{ 0 }};
8af939
+	size_t ps = pagesize(32768);
8af939
+
8af939
+	if (ps < 32768)
8af939
+		return 0;
8af939
+
8af939
+	if (!*uts.release && uname(&uts) < 0)
8af939
+		return -ENOTSUP;
8af939
+	/*
8af939
+	 * RH kernels 3.10.0-185 and lower are affected by a crypto API kernel
8af939
+	 * socket bug. The bug only manifests on archs with page size >= 32 KiB.
8af939
+	 *
8af939
+	 * For reference, see rhbz#1136075
8af939
+	 */
8af939
+	if (sscanf(uts.release, "%u.%u.%u-%u", &maj, &mid, &min, &rel) == 4)
8af939
+		return (maj == 3 && mid == 10 && min == 0 && rel < 186) ? -ENOTSUP : 0;
8af939
+
8af939
+	return -ENOTSUP;
8af939
+}
8af939
+
8af939
 /*
8af939
  * ciphers
8af939
  *
8af939
@@ -60,6 +91,9 @@ int crypt_cipher_init(struct crypt_ciphe
8af939
 		.salg_type = "skcipher",
8af939
 	};
8af939
 
8af939
+	if (check_rh_kernel_version())
8af939
+		return -ENOTSUP;
8af939
+
8af939
 	h = malloc(sizeof(*h));
8af939
 	if (!h)
8af939
 		return -ENOMEM;
8af939
Binary files cryptsetup-2.0.3.old/lib/crypto_backend/.crypto_cipher_kernel.c.rej.swp and cryptsetup-2.0.3/lib/crypto_backend/.crypto_cipher_kernel.c.rej.swp differ