1. static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns)
    2. {
    3. struct user_namespace *user_ns = to_user_ns(ns);
    4. struct cred *cred;
    5. /* Don't allow gaining capabilities by reentering
    6. * the same user namespace.
    7. */
    8. if (user_ns == current_user_ns())
    9. return -EINVAL;
    10. /* 判断是否是多线程 */
    11. /* Tasks that share a thread group must share a user namespace */
    12. if (!thread_group_empty(current))
    13. return -EINVAL;
    14. if (current->fs->users != 1)
    15. return -EINVAL;
    16. if (!ns_capable(user_ns, CAP_SYS_ADMIN))
    17. return -EPERM;
    18. cred = prepare_creds();
    19. if (!cred)
    20. return -ENOMEM;
    21. put_user_ns(cred->user_ns);
    22. set_cred_user_ns(cred, get_user_ns(user_ns));
    23. return commit_creds(cred);
    24. }