user_namespace.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/ns_common.h>
  6. #include <linux/sched.h>
  7. #include <linux/err.h>
  8. #define UID_GID_MAP_MAX_EXTENTS 5
  9. struct uid_gid_map { /* 64 bytes -- 1 cache line */
  10. u32 nr_extents;
  11. struct uid_gid_extent {
  12. u32 first;
  13. u32 lower_first;
  14. u32 count;
  15. } extent[UID_GID_MAP_MAX_EXTENTS];
  16. };
  17. struct user_namespace {
  18. struct uid_gid_map uid_map;
  19. struct uid_gid_map gid_map;
  20. struct uid_gid_map projid_map;
  21. atomic_t count;
  22. struct user_namespace *parent;
  23. int level;
  24. kuid_t owner;
  25. kgid_t group;
  26. struct ns_common ns;
  27. /* Register of per-UID persistent keyrings for this namespace */
  28. #ifdef CONFIG_PERSISTENT_KEYRINGS
  29. struct key *persistent_keyring_register;
  30. struct rw_semaphore persistent_keyring_register_sem;
  31. #endif
  32. };
  33. extern struct user_namespace init_user_ns;
  34. #ifdef CONFIG_USER_NS
  35. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  36. {
  37. if (ns)
  38. atomic_inc(&ns->count);
  39. return ns;
  40. }
  41. extern int create_user_ns(struct cred *new);
  42. extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
  43. extern void free_user_ns(struct user_namespace *ns);
  44. static inline void put_user_ns(struct user_namespace *ns)
  45. {
  46. if (ns && atomic_dec_and_test(&ns->count))
  47. free_user_ns(ns);
  48. }
  49. struct seq_operations;
  50. extern const struct seq_operations proc_uid_seq_operations;
  51. extern const struct seq_operations proc_gid_seq_operations;
  52. extern const struct seq_operations proc_projid_seq_operations;
  53. extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
  54. extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
  55. extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
  56. #else
  57. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  58. {
  59. return &init_user_ns;
  60. }
  61. static inline int create_user_ns(struct cred *new)
  62. {
  63. return -EINVAL;
  64. }
  65. static inline int unshare_userns(unsigned long unshare_flags,
  66. struct cred **new_cred)
  67. {
  68. if (unshare_flags & CLONE_NEWUSER)
  69. return -EINVAL;
  70. return 0;
  71. }
  72. static inline void put_user_ns(struct user_namespace *ns)
  73. {
  74. }
  75. #endif
  76. #endif /* _LINUX_USER_H */