Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil only returns uids of user-owned process on Solaris 10 #1193

Closed
gsauthof opened this issue Dec 13, 2017 · 1 comment · Fixed by #1248
Closed

psutil only returns uids of user-owned process on Solaris 10 #1193

gsauthof opened this issue Dec 13, 2017 · 1 comment · Fixed by #1248

Comments

@gsauthof
Copy link
Contributor

How to reproduce:

As normal user, chose a PID of another user:

>>> p = psutil.Process(12345)
>>> p.uids()
Traceback (most recent call last):
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 346, in wrapper
    return fun(self, *args, **kwargs)
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 477, in uids
    real, effective, saved, _, _, _ = self._proc_cred()
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_common.py", line 336, in wrapper
    return fun(self)
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 400, in _proc_cred
    return cext.proc_cred(self.pid, self._procfs_path)
PermissionError: [Errno 13] Permission denied: '/proc/12345/cred'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_common.py", line 336, in wrapper
    return fun(self)
  File "/path/to/venv/lib/python3.5/site-packages/psutil/__init__.py", line 768, in uids
    return self._proc.uids()
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 362, in wrapper
    raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=12345)

The thing is that psutil tries to read the uids from /proc/$pid/cred that is always only user-readable on Solaris 10:

$ ls /proc/12345/cred -l
-r-------- 1 juser juser 52 2017-11-23 11:27 /proc/12345/cred

A better choice on Solaris 10 is to use /proc/$pid/psinfo since it also contains the uids (modulo the saved user id) - and is readable by everyone. Thus, if psutil really cares about the saved user id, it could also try /proc/$pid/cred first and then fall back to /proc/$pid/psinfo.

For our example:

$ ls /proc/12345/psinfo -l
-r--r--r-- 1 juser juser 336 2017-11-23 11:27 /proc/12345/psinfo
@giampaolo
Copy link
Owner

Can you provide a PR?

gsauthof added a commit to gsauthof/psutil that referenced this issue Mar 15, 2018
gsauthof added a commit to gsauthof/psutil that referenced this issue Mar 17, 2018
giampaolo pushed a commit that referenced this issue Mar 17, 2018
* Fix nice() for realtime processes under Solaris 10

fixes #1194

* Use psinfo as fallback [gu]id source on Solaris 10

fixes #1193

* Fix double free

* Match ssize_t return type of read functions

* Fix undefined behavior

with respect to strict aliasing rules and fix some warnings

For example, under strict aliasing rules of the C standard, casting a
char pointer to a struct pointer and accessing the character array
through that struct pointer yields undefined behavior.

* Update HISTORY with Solaris notes
giampaolo added a commit that referenced this issue Mar 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants