user_namespace.h 2.1 KB

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