GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_mmap.test_access_parameter failing on macOS Sonoma 14.0 beta on Apple Silicon · Issue #107888 · python/cpython

test_mmap.test_access_parameter failing on macOS Sonoma 14.0 beta on Apple Silicon #107888

New issue
Copy link
New issue
Copy link
Closed
Closed
test_mmap.test_access_parameter failing on macOS Sonoma 14.0 beta on Apple Silicon#107888
Copy link
Labels
OS-mactestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@smontanaro
smontanaro
opened on Aug 11, 2023
Issue body actions

Bug report

The other day I decided to give the MacOS Sonoma beta a go on my M1 MBP. test_mmap is now consistently failing with a PermissionError on main and 3.12 branches.

A clear and concise description of the bug

I happened to have an old MacBook Air laying about which is still running MacOS Monterey. I verified that all tests pass there.

Here's the output from the failing test:

test_access_parameter (test.test_mmap.MmapTests.test_access_parameter) ... ERROR

======================================================================
ERROR: test_access_parameter (test.test_mmap.MmapTests.test_access_parameter)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/skip/src/python/cpython/Lib/test/test_mmap.py", line 258, in test_access_parameter
    m = mmap.mmap(f.fileno(), mapsize, prot=prot)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 1] Operation not permitted

Your environment

  • CPython versions tested on: main and 3.12 branches
  • Operating system and architecture: MacBook Pro M1 Pro, MacOS Sonoma 14.0 beta 5

Linked PRs

  • gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 #109928
  • [3.12] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (GH-109928) #109929
  • [3.11] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (GH-109928) #109930
  • gh-107888: Fix test_mmap PROT_EXEC comment #110125
  • [3.11] gh-107888: Fix test_mmap PROT_EXEC comment (GH-110125) #110130
  • [3.8] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (GH-109928) #114183
  • [3.9] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (GH-109928) #114184
  • [3.10] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (GH-109928) #114185

Activity

Next
  1. smontanaro
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 11, 2023
  2. Eclips4
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    OS-mac
    on Aug 11, 2023
  3. smontanaro commented on Aug 12, 2023

    @smontanaro
    smontanaro
    on Aug 12, 2023
    ContributorAuthor
    More actions

    Failing on the 3.11 branch as well. I don't know if this is important enough to elevate for 3.12.0rc1, but Sonoma is supposed to be released in the fall. Fixing this issue now might be worth it.

  4. smontanaro commented on Aug 12, 2023

    @smontanaro
    smontanaro
    on Aug 12, 2023
    ContributorAuthor
    More actions

    Ping @Yhg1s so he sees this.

  5. ronaldoussoren commented on Aug 12, 2023

    @ronaldoussoren
    ronaldoussoren
    on Aug 12, 2023
    Contributor
    More actions

    MacOS 14 is still in beta and contains bugs. We generally don't add workarounds for bugs in beta versions of an OS.

    Is this something that can be reproduced in C?

  6. ronaldoussoren commented on Aug 12, 2023

    @ronaldoussoren
    ronaldoussoren
    on Aug 12, 2023
    Contributor
    More actions

    For me the test appears to pass just fine on the current beta (14.0, 23A5312d):

    $ python3.12 -m unittest test.test_mmap.MmapTests.test_access_parameter
    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.153s
    
    OK
    

    Likewise with 3.11. Both are the latest release installed using the python.org installers, and likewise while running the test_mmap tests using python3.12 -m test test.test_mmap -v.

    EDIT: This is in an x86_64 VM, I don't have an arm64 vm/machine running the 14.0 beta.

  7. smontanaro commented on Aug 12, 2023

    @smontanaro
    smontanaro
    on Aug 12, 2023
    ContributorAuthor
    More actions

    That's fine. I wasn't sure what three policy was, and thought it better to err on the side of caution.

    In case it's a problem with the Sonoma beta, I provided feedback to Apple with a reference to this issue as well.

  8. ned-deily
    changed the title [-]test_mmap.test_access_parameter failing on MacOS Sonoma 14.0 beta[/-] [+]test_mmap.test_access_parameter failing on macOS Sonoma 14.0 beta[/+] on Aug 12, 2023
  9. ned-deily commented on Aug 12, 2023

    @ned-deily
    ned-deily
    on Aug 12, 2023
    Member
    More actions

    I can also reproduce the failure on an arm64 Sonoma beta. While it seems to be a change in OS behavior, the test is supposed to fail anyway; it now unexpectedly fails earlier.

                # Try writing with PROT_EXEC and without PROT_WRITE
                prot = mmap.PROT_READ | getattr(mmap, 'PROT_EXEC', 0)
                with open(TESTFN, "r+b") as f:
                    m = mmap.mmap(f.fileno(), mapsize, prot=prot)
                    self.assertRaises(TypeError, m.write, b"abcdef")
                    self.assertRaises(TypeError, m.write_byte, 0)
                    m.close()
    
    

    With the Sonoma beta on arm64, the mmap.mmap() call is failing before it gets to try the Write calls that should fail. Dunno how significant a change that is or whether it might be an ill-defined test case.

    Reacted by sunmy2019
  10. ronaldoussoren commented on Aug 18, 2023

    @ronaldoussoren
    ronaldoussoren
    on Aug 18, 2023
    Contributor
    More actions

    The test itself looks sane.

    Is this something that can be reproduced in a small C program?

    The following code should be equivalent to the call to mmap.mmap in the test and works on my M1 laptop running 13.5:

    #include <sys/mman.h>
    #include <stdio.h>
    #include <fcntl.h>
    
    int main(void)
    {
        int fd = open("/dev/zero", O_RDONLY);
        if (fd == -1) {
            perror("open");
            return 1;
        }
    
        void* m = mmap(NULL, 10, PROT_READ|PROT_EXEC, 0, fd, 0);
        if (m == NULL) {
            perror("mmap");
            return 1;
        }
    
        printf("done\n");
        return 0;
    }

    If this does work, does code signing the binary with the same entitlements as CPython also work? Likewise code signing with a JIT entitlement.

  11. smontanaro commented on Aug 18, 2023

    @smontanaro
    smontanaro
    on Aug 18, 2023
    ContributorAuthor
    More actions

    Thanks, Ronald. That works. I have no idea what you're talking about "code signing" though.

  12. ronaldoussoren commented on Aug 19, 2023

    @ronaldoussoren
    ronaldoussoren
    on Aug 19, 2023
    Contributor
    More actions

    Thanks, Ronald. That works. I have no idea what you're talking about "code signing" though.

    Code signing as documented by Apple

    It is also possible to test this the other way:

    $ cp /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python Python.backup
    $ codesign --remove-signature /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python
    $ codesign -s - /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python
    $ /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python -m test test.test_mmap -v
    $ cp Python.backup /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python

    (The dollar signs at the start of lines represent the shell prompt and shouldn't be copied when executing this).

    This makes a copy of the interpreter in the framework, then replaces the code signing and entitlements by a trivial code signature that's required on Apple Silicon, then runs the test and finally restores the original signed versions of the interpreter.

    Doing this tells is if the error is related to changes in the hardened runtime on macOS, or is a general behaviour change that affects the mmap extension module.

  13. ned-deily commented on Aug 24, 2023

    @ned-deily
    ned-deily
    on Aug 24, 2023
    Member
    More actions

    Doing this tells is if the error is related to changes in the hardened runtime on macOS, or is a general behaviour change that affects the mmap extension module.

    FWIW, I was able to test this with the most recent macOS 14 Sonoma Developer Preview on both an Intel (x86_64) VM and an Apple Silicon (arm64) VM. test_mmap appears to only fail on Apple Silicon systems running Sonoma and it fails regardless of code signing and hardened runtime usage. That is, the test_mmap failures are seen when running from uninstalled developer builds (./configure && make && ./python.exe -m test test_mmap) as well as running from the latest python.org installer binaries (which are signed and use the hardened runtime).

  14. ned-deily
    changed the title [-]test_mmap.test_access_parameter failing on macOS Sonoma 14.0 beta[/-] [+]test_mmap.test_access_parameter failing on macOS Sonoma 14.0 beta on Apple Silicon[/+] on Aug 24, 2023
  15. 10 remaining items

  16. vstinner
    added a commit that references this issue on Sep 29, 2023

    gh-107888: Fix test_mmap PROT_EXEC comment (#110125)

    14098b7
  17. miss-islington
    added a commit that references this issue on Sep 29, 2023

    pythongh-107888: Fix test_mmap PROT_EXEC comment (pythonGH-110125)

    f033430
  18. vstinner
    added 3 commits that reference this issue on Sep 29, 2023

    pythongh-107888: Fix test_mmap PROT_EXEC comment (python#110125)

    8ca084c

    pythongh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (p…

    9820232

    [3.11] gh-107888: Fix test_mmap PROT_EXEC comment (GH-110125) (#110130)

    42b6883
  19. Yhg1s
    added a commit that references this issue on Oct 2, 2023

    [3.12] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (G…

    bb35fc3
  20. miss-islington
    added 3 commits that reference this issue on Jan 17, 2024

    pythongh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (p…

    068f4d1

    pythongh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (p…

    0b7fbe1

    pythongh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (p…

    bacf6be
  21. ambv
    added 3 commits that reference this issue on Jan 17, 2024

    [3.8] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (G…

    648c44d

    [3.10] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (G…

    1274896

    [3.9] gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (G…

    dd068ea
  22. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-107888: Fix test_mmap.test_access_parameter() on macOS 14 (p…

    2b21e8d

    pythongh-107888: Fix test_mmap PROT_EXEC comment (python#110125)

    a59e44d
  23. slozier
    added a commit that references this issue on Jan 6, 2025

    Backport fixes to python/cpython#107888 (#1865)

    719a446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-mactestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.