user_namespace.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef _LINUX_USER_NAMESPACE_H
  2. #define _LINUX_USER_NAMESPACE_H
  3. #include <linux/kref.h>
  4. #include <linux/nsproxy.h>
  5. #include <linux/sched.h>
  6. #include <linux/err.h>
  7. #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
  8. #define UIDHASH_SZ (1 << UIDHASH_BITS)
  9. struct user_namespace {
  10. struct kref kref;
  11. struct hlist_head uidhash_table[UIDHASH_SZ];
  12. struct user_struct *root_user;
  13. };
  14. extern struct user_namespace init_user_ns;
  15. #ifdef CONFIG_USER_NS
  16. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  17. {
  18. if (ns)
  19. kref_get(&ns->kref);
  20. return ns;
  21. }
  22. extern struct user_namespace *copy_user_ns(int flags,
  23. struct user_namespace *old_ns);
  24. extern void free_user_ns(struct kref *kref);
  25. static inline void put_user_ns(struct user_namespace *ns)
  26. {
  27. if (ns)
  28. kref_put(&ns->kref, free_user_ns);
  29. }
  30. #else
  31. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  32. {
  33. return &init_user_ns;
  34. }
  35. static inline struct user_namespace *copy_user_ns(int flags,
  36. struct user_namespace *old_ns)
  37. {
  38. if (flags & CLONE_NEWUSER)
  39. return ERR_PTR(-EINVAL);
  40. return old_ns;
  41. }
  42. static inline void put_user_ns(struct user_namespace *ns)
  43. {
  44. }
  45. #endif
  46. #endif /* _LINUX_USER_H */