user_namespace.h 2.2 KB

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