about summary refs log tree commit diff
path: root/pkgs/development/python2-modules
diff options
context:
space:
mode:
authorTheodore Ni <3806110+tjni@users.noreply.github.com>2022-08-20 13:01:12 -0700
committerTheodore Ni <3806110+tjni@users.noreply.github.com>2022-11-20 16:16:07 -0800
commit4fc97dce3cfe544151c49e072180863d586084d4 (patch)
treef0510fadf737141c8b285e7dd30fc5643f9d3045 /pkgs/development/python2-modules
parent231da8ef225fac545de2a1891e8f96c21ccbad35 (diff)
downloadnixlib-4fc97dce3cfe544151c49e072180863d586084d4.tar
nixlib-4fc97dce3cfe544151c49e072180863d586084d4.tar.gz
nixlib-4fc97dce3cfe544151c49e072180863d586084d4.tar.bz2
nixlib-4fc97dce3cfe544151c49e072180863d586084d4.tar.lz
nixlib-4fc97dce3cfe544151c49e072180863d586084d4.tar.xz
nixlib-4fc97dce3cfe544151c49e072180863d586084d4.tar.zst
nixlib-4fc97dce3cfe544151c49e072180863d586084d4.zip
python310Packages.cffi: patch closures to work on M1 machines
Trusts the libffi library inside of nixpkgs on Apple devices.

When Apple's fork of libffi is not detected, cffi assumes that libffi
uses a strategy for creating closures (i.e. callbacks) that is in
certain cases susceptible to a security exploit.

Based on some analysis I did:

  https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk

I believe that libffi already contains the code from Apple's fork that
is deemed safe to trust in cffi.

It uses a more sophisticated strategy for creating trampolines to
support closures that works on Apple Silicon, while the simple approach
that cffi falls back on does not, so this patch enables code that uses
closures on M1 Macs again.

Notably, pyOpenSSL is impacted and will be fixed by this, reported in

  https://github.com/pyca/pyopenssl/issues/873

Note that libffi closures still will not work on signed apps without the
com.apple.security.cs.allow-unsigned-executable-memory entitlement while

  https://github.com/libffi/libffi/pull/621

is still open (which I haven't tested but is my best guess from reading).

I am hopeful that all of these changes will be upstreamed back into cffi
and libffi, and that this comment provides enough breadcrumbs for future
maintainers to track and clean this up.
Diffstat (limited to 'pkgs/development/python2-modules')
-rw-r--r--pkgs/development/python2-modules/cffi/default.nix45
1 files changed, 45 insertions, 0 deletions
diff --git a/pkgs/development/python2-modules/cffi/default.nix b/pkgs/development/python2-modules/cffi/default.nix
new file mode 100644
index 000000000000..adeda6e90d22
--- /dev/null
+++ b/pkgs/development/python2-modules/cffi/default.nix
@@ -0,0 +1,45 @@
+{ lib, stdenv, cffi }:
+
+if cffi == null then null else cffi.overridePythonAttrs {
+  disabledTests = lib.optionals stdenv.isDarwin [
+    # cannot load library 'c'
+    "test_FILE"
+    "test_FILE_object"
+    "test_FILE_only_for_FILE_arg"
+    "test_load_and_call_function"
+    "test_load_library"
+
+    # cannot load library 'dl'
+    "test_dlopen_handle"
+
+    # cannot load library 'm'
+    "test_dir_on_dlopen_lib"
+    "test_dlclose"
+    "test_dlopen"
+    "test_dlopen_constant"
+    "test_dlopen_flags"
+    "test_function_typedef"
+    "test_line_continuation_in_defines"
+    "test_missing_function"
+    "test_remove_comments"
+    "test_remove_line_continuation_comments"
+    "test_simple"
+    "test_sin"
+    "test_sinf"
+    "test_stdcall_only_on_windows"
+    "test_wraps_from_stdlib"
+
+    # MemoryError
+    "test_callback_as_function_argument"
+    "test_callback_crash"
+    "test_callback_decorator"
+    "test_callback_large_struct"
+    "test_callback_returning_void"
+    "test_cast_functionptr_and_int"
+    "test_function_pointer"
+    "test_functionptr_intptr_return"
+    "test_functionptr_simple"
+    "test_functionptr_void_return"
+    "test_functionptr_voidptr_return"
+  ];
+}