From 9a8f2080d7547ba3187b7532837ca2101e4f7cea Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 11 Oct 2018 10:58:38 +0300 Subject: [PATCH] - Fix ancient Python GIL locking bug (#1632488) - Use the appropriate macro for tmpfiles.d now that one exists --- ...on-GIL-locking-bug-on-callback-RhBug.patch | 46 +++++++++++++++++++ rpm.spec | 7 ++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-ancient-python-GIL-locking-bug-on-callback-RhBug.patch diff --git a/0001-Fix-ancient-python-GIL-locking-bug-on-callback-RhBug.patch b/0001-Fix-ancient-python-GIL-locking-bug-on-callback-RhBug.patch new file mode 100644 index 0000000..b66710a --- /dev/null +++ b/0001-Fix-ancient-python-GIL-locking-bug-on-callback-RhBug.patch @@ -0,0 +1,46 @@ +From 531dc8495cd3aabd3f659ecab604106fdbacbe98 Mon Sep 17 00:00:00 2001 +Message-Id: <531dc8495cd3aabd3f659ecab604106fdbacbe98.1539244476.git.pmatilai@redhat.com> +From: Panu Matilainen +Date: Wed, 3 Oct 2018 11:51:38 +0300 +Subject: [PATCH] Fix ancient python GIL locking bug on callback + (RhBug:1632488) + +Introduced in commit c7881d801745b4c156a8aa2afc17b95f97481e34 back in 2002, +synthesizing a python object for the callback occurs before retaking +the GIL lock, which is not allowed. Somehow this has managed to stay +latent all these years, and even now requires fairly specific conditions: +when the callback gets called without an associated key, such as erasures +or file trigger script start/stop events (in the case of RhBug:1632488), +when Python 3 is running in PYTHONMALLOC=debug mode, +it crashes with "Python memory allocator called without holding the GIL". + +Simply retake the lock before any Python operations take place to fix. +--- + python/rpmts-py.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/python/rpmts-py.c b/python/rpmts-py.c +index e4c5e1250..1ddfc9a1e 100644 +--- a/python/rpmts-py.c ++++ b/python/rpmts-py.c +@@ -495,6 +495,8 @@ rpmtsCallback(const void * hd, const rpmCallbackType what, + + if (cbInfo->cb == Py_None) return NULL; + ++ PyEval_RestoreThread(cbInfo->_save); ++ + /* Synthesize a python object for callback (if necessary). */ + if (pkgObj == NULL) { + if (h) { +@@ -506,8 +508,6 @@ rpmtsCallback(const void * hd, const rpmCallbackType what, + } else + Py_INCREF(pkgObj); + +- PyEval_RestoreThread(cbInfo->_save); +- + args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data); + result = PyEval_CallObject(cbInfo->cb, args); + Py_DECREF(args); +-- +2.17.1 + diff --git a/rpm.spec b/rpm.spec index f2e05f7..7368575 100644 --- a/rpm.spec +++ b/rpm.spec @@ -23,7 +23,7 @@ %global rpmver 4.14.2 #global snapver rc2 -%global rel 1 +%global rel 2 %global srcver %{version}%{?snapver:-%{snapver}} %global srcdir %{?snapver:testing}%{!?snapver:%{name}-%(echo %{version} | cut -d'.' -f1-2).x} @@ -60,6 +60,7 @@ Patch5: rpm-4.12.0-rpm2cpio-hack.patch Patch6: 0001-find-debuginfo.sh-decompress-DWARF-compressed-ELF-se.patch # Patches already upstream: +Patch101: 0001-Fix-ancient-python-GIL-locking-bug-on-callback-RhBug.patch # These are not yet upstream Patch906: rpm-4.7.1-geode-i686.patch @@ -597,6 +598,10 @@ make check || cat tests/rpmtests.log %doc doc/librpm/html/* %changelog +* Thu Oct 11 2018 Panu Matilainen - 4.14.2-2 +- Fix ancient Python GIL locking bug (#1632488) +- Use the appropriate macro for tmpfiles.d now that one exists + * Tue Aug 21 2018 Panu Matilainen - 4.14.2-1 - Update to rpm 4.14.2 final (http://rpm.org/wiki/Releases/4.14.2)