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

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