user_namespace.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. kuid_t owner;
  23. kgid_t group;
  24. unsigned int proc_inum;
  25. };
  26. extern struct user_namespace init_user_ns;
  27. #ifdef CONFIG_USER_NS
  28. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  29. {
  30. if (ns)
  31. atomic_inc(&ns->count);
  32. return ns;
  33. }
  34. extern int create_user_ns(struct cred *new);
  35. extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
  36. extern void free_user_ns(struct user_namespace *ns);
  37. static inline void put_user_ns(struct user_namespace *ns)
  38. {
  39. if (ns && atomic_dec_and_test(&ns->count))
  40. free_user_ns(ns);
  41. }
  42. struct seq_operations;
  43. extern struct seq_operations proc_uid_seq_operations;
  44. extern struct seq_operations proc_gid_seq_operations;
  45. extern struct seq_operations proc_projid_seq_operations;
  46. extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
  47. extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
  48. extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
  49. #else
  50. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  51. {
  52. return &init_user_ns;
  53. }
  54. static inline int create_user_ns(struct cred *new)
  55. {
  56. return -EINVAL;
  57. }
  58. static inline int unshare_userns(unsigned long unshare_flags,
  59. struct cred **new_cred)
  60. {
  61. if (unshare_flags & CLONE_NEWUSER)
  62. return -EINVAL;
  63. return 0;
  64. }
  65. static inline void put_user_ns(struct user_namespace *ns)
  66. {
  67. }
  68. #endif
  69. #endif /* _LINUX_USER_H */