summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gilbert <floppym@gentoo.org>2018-04-19 15:43:52 -0400
committerMike Gilbert <floppym@gentoo.org>2018-04-19 15:44:13 -0400
commit0d123a4bd5046559e97746f6598c7f6030dccdda (patch)
tree063e541b8d0184932634fa1596f1605a80e00cc4 /dev-lang
parentmedia-gfx/sane-backends: stable 1.0.27-r1 for sparc (diff)
downloadgentoo-0d123a4bd5046559e97746f6598c7f6030dccdda.tar.gz
gentoo-0d123a4bd5046559e97746f6598c7f6030dccdda.tar.bz2
gentoo-0d123a4bd5046559e97746f6598c7f6030dccdda.zip
dev-lang/python: fix unaligned memory access
Thanks to Rolf Eike Beer for the patches. Closes: https://bugs.gentoo.org/636400 Package-Manager: Portage-2.3.24, Repoman-2.3.6_p81
Diffstat (limited to 'dev-lang')
-rw-r--r--dev-lang/python/files/python-3.5.5-hash-unaligned.patch43
-rw-r--r--dev-lang/python/files/python-3.6.5-hash-unaligned.patch42
-rw-r--r--dev-lang/python/python-3.4.8.ebuild1
-rw-r--r--dev-lang/python/python-3.5.5.ebuild1
-rw-r--r--dev-lang/python/python-3.6.5.ebuild1
5 files changed, 88 insertions, 0 deletions
diff --git a/dev-lang/python/files/python-3.5.5-hash-unaligned.patch b/dev-lang/python/files/python-3.5.5-hash-unaligned.patch
new file mode 100644
index 000000000000..c418f40b7da4
--- /dev/null
+++ b/dev-lang/python/files/python-3.5.5-hash-unaligned.patch
@@ -0,0 +1,43 @@
+The hash implementation casts the input pointer to uint64_t* and directly reads
+from this, which may cause unaligned accesses. Use memcpy() instead so this code
+will not crash with SIGBUS on sparc.
+
+--- a/Python/pyhash.c 2017-11-29 10:21:20.283094068 +0100
++++ b/Python/pyhash.c 2017-11-29 10:24:26.733087813 +0100
+@@ -372,7 +372,7 @@ siphash24(const void *src, Py_ssize_t sr
+ PY_UINT64_T k0 = _le64toh(_Py_HashSecret.siphash.k0);
+ PY_UINT64_T k1 = _le64toh(_Py_HashSecret.siphash.k1);
+ PY_UINT64_T b = (PY_UINT64_T)src_sz << 56;
+- const PY_UINT64_T *in = (PY_UINT64_T*)src;
++ const PY_UINT8_T *in = (PY_UINT8_T*)src;
+
+ PY_UINT64_T v0 = k0 ^ 0x736f6d6570736575ULL;
+ PY_UINT64_T v1 = k1 ^ 0x646f72616e646f6dULL;
+@@ -381,12 +381,14 @@ siphash24(const void *src, Py_ssize_t sr
+
+ PY_UINT64_T t;
+ PY_UINT8_T *pt;
+- PY_UINT8_T *m;
++ const PY_UINT8_T *m;
+
+ while (src_sz >= 8) {
+- PY_UINT64_T mi = _le64toh(*in);
+- in += 1;
+- src_sz -= 8;
++ PY_UINT64_T mi;
++ memcpy(&mi, in, sizeof(mi));
++ mi = _le64toh(mi);
++ in += sizeof(mi);
++ src_sz -= sizeof(mi);
+ v3 ^= mi;
+ DOUBLE_ROUND(v0,v1,v2,v3);
+ v0 ^= mi;
+@@ -394,7 +396,7 @@ siphash24(const void *src, Py_ssize_t sr
+
+ t = 0;
+ pt = (PY_UINT8_T *)&t;
+- m = (PY_UINT8_T *)in;
++ m = in;
+ switch (src_sz) {
+ case 7: pt[6] = m[6];
+ case 6: pt[5] = m[5];
diff --git a/dev-lang/python/files/python-3.6.5-hash-unaligned.patch b/dev-lang/python/files/python-3.6.5-hash-unaligned.patch
new file mode 100644
index 000000000000..d096887cbfb7
--- /dev/null
+++ b/dev-lang/python/files/python-3.6.5-hash-unaligned.patch
@@ -0,0 +1,42 @@
+The hash implementation casts the input pointer to uint64_t* and directly reads
+from this, which may cause unaligned accesses. Use memcpy() instead so this code
+will not crash with SIGBUS on sparc.
+
+--- a/Python/pyhash.c 2017-11-29 10:21:20.283094068 +0100
++++ b/Python/pyhash.c 2017-11-29 10:24:26.733087813 +0100
+@@ -369,7 +369,7 @@
+ uint64_t k0 = _le64toh(_Py_HashSecret.siphash.k0);
+ uint64_t k1 = _le64toh(_Py_HashSecret.siphash.k1);
+ uint64_t b = (uint64_t)src_sz << 56;
+- const uint64_t *in = (uint64_t*)src;
++ const uint8_t *in = (uint8_t*)src;
+
+ uint64_t v0 = k0 ^ 0x736f6d6570736575ULL;
+ uint64_t v1 = k1 ^ 0x646f72616e646f6dULL;
+@@ -378,11 +378,13 @@
+
+ uint64_t t;
+ uint8_t *pt;
+- uint8_t *m;
++ const uint8_t *m;
+
+ while (src_sz >= 8) {
+- uint64_t mi = _le64toh(*in);
+- in += 1;
+- src_sz -= 8;
++ uint64_t mi;
++ memcpy(&mi, in, sizeof(mi));
++ mi = _le64toh(mi);
++ in += sizeof(mi);
++ src_sz -= sizeof(mi);
+ v3 ^= mi;
+ DOUBLE_ROUND(v0,v1,v2,v3);
+@@ -391,7 +393,7 @@
+
+ t = 0;
+ pt = (uint8_t *)&t;
+- m = (uint8_t *)in;
++ m = in;
+ switch (src_sz) {
+ case 7: pt[6] = m[6]; /* fall through */
+ case 6: pt[5] = m[5]; /* fall through */
diff --git a/dev-lang/python/python-3.4.8.ebuild b/dev-lang/python/python-3.4.8.ebuild
index ad0ac881c61d..4472bc6f61a2 100644
--- a/dev-lang/python/python-3.4.8.ebuild
+++ b/dev-lang/python/python-3.4.8.ebuild
@@ -74,6 +74,7 @@ src_prepare() {
epatch "${FILESDIR}/${PN}-3.4.5-cross.patch"
epatch "${FILESDIR}/3.4-getentropy-linux.patch"
epatch "${FILESDIR}/3.6-disable-nis.patch"
+ epatch "${FILESDIR}/python-3.5.5-hash-unaligned.patch"
epatch_user
diff --git a/dev-lang/python/python-3.5.5.ebuild b/dev-lang/python/python-3.5.5.ebuild
index 972c02836e79..212e0bb7abce 100644
--- a/dev-lang/python/python-3.5.5.ebuild
+++ b/dev-lang/python/python-3.5.5.ebuild
@@ -75,6 +75,7 @@ src_prepare() {
epatch "${FILESDIR}/${PN}-3.5-distutils-OO-build.patch"
epatch "${FILESDIR}/3.6-disable-nis.patch"
epatch "${FILESDIR}/python-3.5.5-libressl-compatibility.patch"
+ epatch "${FILESDIR}/python-3.5.5-hash-unaligned.patch"
epatch_user
diff --git a/dev-lang/python/python-3.6.5.ebuild b/dev-lang/python/python-3.6.5.ebuild
index 400566cde2dc..1f15d64d39bc 100644
--- a/dev-lang/python/python-3.6.5.ebuild
+++ b/dev-lang/python/python-3.6.5.ebuild
@@ -69,6 +69,7 @@ src_prepare() {
"${FILESDIR}/${PN}-3.5-distutils-OO-build.patch"
"${FILESDIR}/3.6.5-disable-nis.patch"
"${FILESDIR}/python-3.6.5-libressl-compatibility.patch"
+ "${FILESDIR}/python-3.6.5-hash-unaligned.patch"
)
default