Skip to content

gh-152936: Make privileged functions available on Android#152977

Open
sabamdarif wants to merge 1 commit into
python:mainfrom
sabamdarif:main
Open

gh-152936: Make privileged functions available on Android#152977
sabamdarif wants to merge 1 commit into
python:mainfrom
sabamdarif:main

Conversation

@sabamdarif

@sabamdarif sabamdarif commented Jul 3, 2026

Copy link
Copy Markdown

os.chroot,initgroups,setegid,seteuid,setgid.... are currently blocked on Android.
Because the underlying C functions crash the process when called by a non-root user on android, rather than returning an error.
So i added getuid() != 0 check (under #ifdef ANDROID) before each call, so it will return PermissionError for non-root just like normal Unix

@bedevere-app

bedevere-app Bot commented Jul 3, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@sabamdarif

Copy link
Copy Markdown
Author

it's my first pr here so i don't know much about the NEWS entry, if it's not a problem can anyone tell me if i do need to add any NEWS entry ?

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33432191 | 📁 Comparing 8b77d9d against main (423ae0f)

  🔍 Preview build  

2 files changed
± library/os.html
± library/socket.html

@Aniketsy

Aniketsy commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

it's my first pr here so i don't know much about the NEWS entry, if it's not a problem can anyone tell me if i do need to add any NEWS entry ?

thanks for the PR, as per my thought yes, this will need NEWS entry but you can wait for the review and then you can add NEWS entry ( to get 100 % sure 😀)

@mhsmith mhsmith self-requested a review July 4, 2026 01:26
@sabamdarif

Copy link
Copy Markdown
Author

i have another question for the Android test failure should i update the test_posix.py ? to do something like if support.is_android and os.getuid() != 0: so it will not failed on PermissionError ? or should i need to update something on my patch so the existing test pass

@sabamdarif

Copy link
Copy Markdown
Author

why did the Tests / Sanitizers / TSan (free-threading) (pull_request) failed i don't get it ?

@robertkirkman

Copy link
Copy Markdown
Contributor

We can see that the cause of one of the test failures probably is that the Python test suite has interpreted the unblocking of setresuid() as an indication that it should be usable as non-root user, even though we want to use it as root user and continue to show an error for non-root users;

@unittest.skipUnless(hasattr(posix, 'setresuid'),
'test needs posix.setresuid()')
def test_setresuid(self):
current_user_ids = posix.getresuid()
self.assertIsNone(posix.setresuid(*current_user_ids))
# -1 means don't change that value.
self.assertIsNone(posix.setresuid(-1, -1, -1))

I would say that yes, the test should probably be modified to check for Android platform, and in the case of Android platform, only test that function if the test is running as root user;

however, what I find concerning is that the CI here only produced a failure for x86_64, and not for aarch64, even though in my own separate test, both x86_64 and aarch64 architectures of Android should be returning the same result from the same function:

image

I wonder if that suggests there is a deeper problem with the tests or an inconsistency somewhere in the test implementation between x86_64 and aarch64.

@sabamdarif

Copy link
Copy Markdown
Author

@robertkirkman yes, let see what others are saying about this . I still didn't get any other comment from any of the core maintainers

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make privileged functions available on Android

3 participants