Bug 33923 - Traceback in top module when uid is unknown
Traceback in top module when uid is unknown
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UMC - Process overview
UCS 3.2
Other Linux
: P5 normal (vote)
: UCS 4.0-1-errata
Assigned To: Johannes Keiser
Florian Best
https://github.com/giampaolo/psutil/i...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-01-14 11:03 CET by Dirk Wiesenthal
Modified: 2015-09-09 13:58 CEST (History)
4 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Error handling, External feedback
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Wiesenthal univentionstaff 2014-01-14 11:03:57 CET
I tried my best to reproduce this, but I failed. See the bottom for what we got as feedback. Looks as if the Uid of the process was removed in the meantime or (look at the number) that somehow Uid and Gid swapped. Anyone knows how to run a process with one's Gid as Uid?

Anyway, "except KeyError: continue" would _hide_ such a problem. The real cause remains unknown (to me). The processlist is generated by os.listdir('/proc'), the uid is found in /proc/%s/status, line "Uid:".

 Execution of command 'top/query' has failed:

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/univention/management/console/modules/__init__.py",
line 204, in execute
    func( request )
  File "/usr/lib/pymodules/python2.6/univention/management/console/modules/decorators.py",
line 178, in _response
    return function(self, request)
  File
"/usr/lib/pymodules/python2.6/univention/management/console/modules/top/__init__.py", line
63, in query
    listEntry['user'] = process.username
  File "/usr/lib/pymodules/python2.6/psutil/__init__.py", line 238, in username
    self._procinfo.username = pwd.getpwuid(self.uid).pw_name
KeyError: 'getpwuid(): uid not found: 5025'
Comment 1 Dirk Wiesenthal univentionstaff 2014-01-14 12:08:39 CET
(In reply to Dirk Wiesenthal from comment #0)
> Anyone knows how to run a process with one's Gid as Uid?

Clarification: Uids normally start with 1000, Gids with 5000. So it seems as if not the Uid, but the Gid was used as Uid. But this is only a guess.
Comment 2 Dirk Wiesenthal univentionstaff 2014-02-03 10:32:27 CET
Reported again, again a Uid > 5000:

 Traceback:
Die Ausführung des Kommandos top/query ist fehlgeschlagen:

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/univention/management/console/modules/__init__.py",
line 204, in execute
    func( request )
  File "/usr/lib/pymodules/python2.6/univention/management/console/modules/decorators.py",
line 178, in _response
    return function(self, request)
  File
"/usr/lib/pymodules/python2.6/univention/management/console/modules/top/__init__.py", line
63, in query
    listEntry['user'] = process.username
  File "/usr/lib/pymodules/python2.6/psutil/__init__.py", line 238, in username
    self._procinfo.username = pwd.getpwuid(self.uid).pw_name
KeyError: 'getpwuid(): uid not found: 5109'

 Remark:
In der UMC auf "Prozesse" geklickt.
Comment 3 Florian Best univentionstaff 2014-02-03 11:31:56 CET
maybe there is a broken process with wrong uid:

cat <<<"#include <unistd.h>
int main()
{
        setuid(12345);
        char* envp[1]={0};
        execle("/usr/bin/python","python",(char*)0,envp);
}" > fakeuid.c && gcc fakeuid.c -o fake && ./fake

→ UMC traceback
Comment 4 Stefan Gohmann univentionstaff 2014-10-06 07:16:54 CEST
Reported again: Ticket #2014092521000292
Comment 5 Florian Best univentionstaff 2014-12-05 10:52:39 CET
Reported again, 4.0-0 errata0 (Walle) Remark:
Ich wollte mir eine Übersicht über die aktuell laufenden Prozesse mit dem Admin User
machen.
Comment 6 Alexander Kläser univentionstaff 2015-01-09 12:07:11 CET
It could be that this issue has been resolved in the psutil itself:

> root@ucs-6489:~# rgrep getpwuid /usr/share/pyshared/psutil/
> /usr/share/pyshared/psutil/__init__.py:            return pwd.getpwuid(self.uids.real).pw_name

I would opt for waiting for more feedback with a more recent UCS version.
Comment 7 Florian Best univentionstaff 2015-01-09 12:18:44 CET
(In reply to Alexander Kläser from comment #6)
> It could be that this issue has been resolved in the psutil itself:
→ No, i don't think so. We received this traceback with UCS 4.0 which is already a never version. We can also just catch the exception without reproducing it. For the QA it can be reproduced with the script from comment #3.
Comment 8 Florian Best univentionstaff 2015-01-09 12:51:32 CET
The UCS 4.0-0 traceback:
Die Ausführung des Kommandos top/query ist fehlgeschlagen:

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/univention/management/console/modules/__init__.py",
line 176, in _decorated
    return function(self, request, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/univention/management/console/modules/decorators.py",
line 188, in _response
    return function(self, request)
  File
"/usr/lib/pymodules/python2.7/univention/management/console/modules/top/__init__.py", line
62, in query
    listEntry['user'] = process.username
  File "/usr/lib/pymodules/python2.7/psutil/__init__.py", line 369, in username
    return pwd.getpwuid(self.uids.real).pw_name
KeyError: 'getpwuid(): uid not found: 3000051'
Comment 9 Florian Best univentionstaff 2015-02-06 09:13:58 CET
Reported again, 3.2-4 errata277
Comment 10 Florian Best univentionstaff 2015-02-16 10:27:27 CET
Reported again, 4.0-1 errata82 (Walle)
Comment 11 Johannes Keiser univentionstaff 2015-03-17 13:58:40 CET
It would be fixed in python-psutil "2.2.0", we currently have python-psutil "0.7.0".

The behavior from psutil has been integrated into the UMC module.

Fixed:
r59100
univention-management-console-module-top (4.1.0-4)
* Bug #33923: Use process uid as process username if the uid can not be
resolved by the system.

YAML: r59117
Comment 12 Florian Best univentionstaff 2015-03-17 14:34:48 CET
Reproduces with:
cat <<<'
#include <unistd.h>
int main()
{
        setuid(12345);
        char* envp[1]={0};
        execle("/bin/cat","<b>cat</b>",(char*)0,envp);
}' > fakeuid.c && gcc fakeuid.c -o fake && ./fake

Fix: OK
Code-Review: OK
YAML: OK
Comment 13 Janek Walkenhorst univentionstaff 2015-03-25 16:42:04 CET
<http://errata.univention.de/ucs/4.0/133.html>