Bug 1140886 - mock fails with OSError: [Errno 0] Success when it run with wrong privs
Summary: mock fails with OSError: [Errno 0] Success when it run with wrong privs
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: mock
Version: 20
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Clark Williams
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1131825
TreeView+ depends on / blocked
 
Reported: 2014-09-12 00:07 UTC by Dan Callaghan
Modified: 2014-10-22 06:20 UTC (History)
9 users (show)

Fixed In Version: mock-1.2.0
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-10-12 21:18:12 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Dan Callaghan 2014-09-12 00:07:03 UTC
Description of problem:
There are a few different problems here which combine to cause some very weird behaviour...

Version-Release number of selected component (if applicable):
mock-1.1.41-1.fc20.noarch

How reproducible:
easily

Steps to Reproduce:
1. Make an unprivileged user account in the mock group
2. From a root shell, run: su myuser (note that I omitted the - option to start a login shell)
3. Run any mock commands, for example: mock -r fedora-19-x86_64 --init

Actual results:
OSError: [Errno 0] Success
ERROR: Error in configuration

Expected results:
mock should work

Additional info:
First I had to comment out the traceback printing stuff in update_config_from_file in util.py line 765, which doesn't seem to work. So then I got an actual traceback:

Traceback (most recent call last):
  File "/usr/sbin/mock", line 306, in <module>
    def do_buildsrpm(config_opts, chroot, options, args):
  File "/usr/sbin/mock", line 424, in main
    mockbuild.util.update_config_from_file(config_opts, cfg, uidManager)
  File "/usr/lib/python2.7/site-packages/mockbuild/util.py", line 735, in update_config_from_file
    uidManager.dropPrivsForever()
  File "<peak.util.decorators.rewrap wrapping mockbuild.uid.dropPrivsForever at 0x01BB2CF8>", line 3, in dropPrivsForever
  File "/usr/lib/python2.7/site-packages/mockbuild/trace_decorator.py", line 70, in trace
    result = func(*args, **kw)
  File "/usr/lib/python2.7/site-packages/mockbuild/uid.py", line 45, in dropPrivsForever
    self._elevatePrivs()
  File "<peak.util.decorators.rewrap wrapping mockbuild.uid._elevatePrivs at 0x01BB15F0>", line 3, in _elevatePrivs
  File "/usr/lib/python2.7/site-packages/mockbuild/trace_decorator.py", line 70, in trace
    result = func(*args, **kw)
  File "/usr/lib/python2.7/site-packages/mockbuild/uid.py", line 61, in _elevatePrivs
    setresuid(0, 0, 0)
  File "/usr/lib/python2.7/site-packages/mockbuild/uid.py", line 100, in setresuid
    raise OSError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))
OSError: [Errno 0] Success
ERROR: Error in configuration

So next I can see that for the privilege escalation/dropping stuff it is calling setresuid(0, 0, 0) which is apparently failing but the errno is not being set. That's because the ctypes library handle does not have use_errno=True which means the ctypes.get_errno() function does not work.

That can be fixed by changing uid.py line 83 to:

_libc = ctypes.CDLL(None, use_errno=True)

Now I get the real error, and mock helpfully has an explanation of what I was doing wrong:

ERROR: [Errno 1] Operation not permitted

ERROR: The most common cause for this error is trying to run /usr/sbin/mock as an unprivileged user.
ERROR: Check your path to make sure that /usr/bin/ is listed before /usr/sbin, or manually run /usr/bin/mock to see if that fixes this problem.

Comment 1 Michael Simacek 2014-09-12 07:16:52 UTC
This should be already fixed upstream in commit b58757c

Comment 2 Tomas Dabašinskas 2014-10-03 04:25:20 UTC
I'm not sure if it's related, but I'm getting same error. --verbose option doesn't do anything...

[packager@d131a8d6e5c0 ~]$ rpm -q mock
mock-1.1.41-3.fc20.noarch

[packager@d131a8d6e5c0 ~]$ id
uid=1000(packager) gid=1000(packager) groups=1000(packager),10(wheel),135(mock)

[packager@d131a8d6e5c0 ~]$ mock -r fedora-20-x86_64 --init

OSError: [Errno 0] Success

ERROR: Error in configuration

[packager@d131a8d6e5c0 ~]$ sudo mock -r fedora-20-x86_64 --init
INFO: mock.py version 1.1.41 starting...
Start: init plugins
INFO: selinux disabled
Finish: init plugins
Start: run
ERROR: Namespace unshare failed.

Comment 3 Michael Simacek 2014-10-03 07:33:24 UTC
That's seems like a separate issue. Please fill a new bug and attach output of
sudo strace -e unshare mock -r fedora-20-x86_64 --init
and include your kernel version (and whether it's custom)

Comment 4 Miroslav Suchý 2014-10-12 21:18:12 UTC
Fixed in mock-1.2.0, which just landed in rawhide.

Comment 5 Sergio Durigan Junior 2014-10-22 04:21:41 UTC
Any chance you of this fix being backported to F20?  Thanks.

Comment 6 Miroslav Suchý 2014-10-22 06:20:27 UTC
Once we will be confident that it is stable enough. For reasoning see:
http://miroslav.suchy.cz/blog/archives/2014/10/12/big_changes_in_mock/index.html


Note You need to log in before you can comment on or make changes to this bug.