Bug 281820 - mdo: failed to call initgroups: Operation not permitted
Summary: mdo: failed to call initgroups: Operation not permitted
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Olivier Certner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-02 14:10 UTC by Jose Luis Duran
Modified: 2024-11-18 09:36 UTC (History)
3 users (show)

See Also:


Attachments
WIP: Not thoroughly tested (2.02 KB, patch)
2024-10-06 20:40 UTC, Jose Luis Duran
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jose Luis Duran freebsd_committer freebsd_triage 2024-10-02 14:10:39 UTC
As 'root' issue:

    # kldload mac_do
    # sysctl security.mac.do.rules=gid=0:any

A user 'freebsd' already exists and belongs to 'wheel':

    $ mdo pkg upgrade
uma_zalloc_debug: zone "malloc-1024" with the following non-sleepable locks held:
exclusive sleep mutex process lock (process lock) r = 0 (0xfffffe0049457188) locked @ /usr/src/sys/kern/kern_prot.c:846
stack backtrace:
#0 0xffffffff80bc6bfc at witness_debugger+0x6c
#1 0xffffffff80bc7df3 at witness_warn+0x403
#2 0xffffffff80ef7864 at uma_zalloc_debug+0x34
#3 0xffffffff80ef7387 at uma_zalloc_arg+0x27
#4 0xffffffff80b23d8d at malloc+0x7d
#5 0xffffffff80c2bce1 at vn_fullpath+0x41
#6 0xffffffff8331c9dc at check_setgroups+0x5c
#7 0xffffffff80e8b2e4 at mac_cred_check_setgroups+0xa4
#8 0xffffffff80b3bbc7 at kern_setgroups+0x157
#9 0xffffffff80b3ba5e at sys_setgroups+0x9e
#10 0xffffffff8107c9b8 at amd64_syscall+0x158
#11 0xffffffff8104e7bb at fast_syscall_common+0xf8
mdo: failed to call initgroups: Operation not permitted
Comment 1 Jose Luis Duran freebsd_committer freebsd_triage 2024-10-06 20:40:59 UTC
Created attachment 254060 [details]
WIP: Not thoroughly tested

- mac_do: Allow a gid-only rule to any
- mac_do: Avoid locking around vn_fullpath()
- mac_do: check if freebuf is non-NULL before freeing

This is my weekly progress on this bug.  I would like to test it further, and familiarize with the code a bit more before submitting it for review.

Posting it here just in case it is of any help.

Tests:

As 'root' issue:

    # kldload mac_do
    # sysctl security.mac.do.rules=gid=0:any [1]
    # sysctl security.mac.do.rules=gid=1001:any [2]

A user 'freebsd' already exists with a GID 1001 and belongs to 'wheel':

    $ mdo pkg upgrade [1] [2]
    Updating FreeBSD repository catalogue...
    ...
Comment 2 Olivier Certner freebsd_committer freebsd_triage 2024-10-07 07:37:06 UTC
Hello Jose,

There are several code and conceptual problems in the current implementation of mac_do(4), and I would advise not to use it in a production setup yet.

I have been working on a full revamp of it.  Prerequisite commits (about general infrastructure changes) are already under review, and the bulk of if (changes in mac_do(4)) proper will soon follow (an earlier version can be globally seen at https://github.com/freebsd/freebsd-src/compare/main...OlCe2:freebsd-src:oc-mac_do).
As you can see there, the format of the rules specification in `security.mac.do.rules` has been changed.

Thanks and regards.
Comment 3 Jose Luis Duran freebsd_committer freebsd_triage 2024-10-07 14:01:50 UTC
(In reply to Olivier Certner from comment #2)

Thank you for sharing this information.
Comment 4 Olivier Certner freebsd_committer freebsd_triage 2024-10-07 14:11:32 UTC
I'll be glad if you can test, or even review, the changes in their final form.  If you are OK, I can add you to the upcoming reviews.  In any case, I intend to update the GitHub series above next (still working with reviewers on the prerequisite ones), and will post an update here so that interested people can test.
Comment 5 Jose Luis Duran freebsd_committer freebsd_triage 2024-10-07 14:22:01 UTC
(In reply to Olivier Certner from comment #4)

Yes, I am installing this branch as we speak. Thank you!
Comment 6 Jose Luis Duran freebsd_committer freebsd_triage 2024-10-29 06:02:39 UTC
This bug can be closed as FIXED by review D47304.
Comment 7 Olivier Certner freebsd_committer freebsd_triage 2024-11-18 09:05:23 UTC
(In reply to Olivier Certner from comment #4)
(In reply to Jose Luis Duran from comment #5)

Hi Jose, I have added you as a subscriber to differential revisions concerning the revamped mac_do(4).  If you have some time and interest, please review what you can.  If you find it more convenient, the full series of commits (including some prerequisites mostly reviewed and some not really related commits) is also available at my GitHub (https://github.com/freebsd/freebsd-src/compare/main...OlCe2:freebsd-src:oc-mac_do; the 'oc-mac_do' branch has been updated).

I've just noticed that you added yourself to D47633 (the "umbrella" revision), great.  If, on the other hand, you're annoyed to have been added as a subscriber to all incremental changes, don't hesitate to say so and I'll remove these subscriptions.
Comment 8 Jose Luis Duran freebsd_committer freebsd_triage 2024-11-18 09:36:41 UTC
(In reply to Olivier Certner from comment #7)
No problem at all. Thank you!
I'll take a look.