user_namespace.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 kref kref;
  20. struct user_namespace *parent;
  21. kuid_t owner;
  22. kgid_t group;
  23. };
  24. extern struct user_namespace init_user_ns;
  25. #ifdef CONFIG_USER_NS
  26. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  27. {
  28. if (ns)
  29. kref_get(&ns->kref);
  30. return ns;
  31. }
  32. extern int create_user_ns(struct cred *new);
  33. extern void free_user_ns(struct kref *kref);
  34. static inline void put_user_ns(struct user_namespace *ns)
  35. {
  36. if (ns)
  37. kref_put(&ns->kref, free_user_ns);
  38. }
  39. struct seq_operations;
  40. extern struct seq_operations proc_uid_seq_operations;
  41. extern struct seq_operations proc_gid_seq_operations;
  42. extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
  43. extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
  44. #else
  45. static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
  46. {
  47. return &init_user_ns;
  48. }
  49. static inline int create_user_ns(struct cred *new)
  50. {
  51. return -EINVAL;
  52. }
  53. static inline void put_user_ns(struct user_namespace *ns)
  54. {
  55. }
  56. #endif
  57. static inline uid_t user_ns_map_uid(struct user_namespace *to,
  58. const struct cred *cred, kuid_t uid)
  59. {
  60. return from_kuid_munged(to, uid);
  61. }
  62. static inline gid_t user_ns_map_gid(struct user_namespace *to,
  63. const struct cred *cred, kgid_t gid)
  64. {
  65. return from_kgid_munged(to, gid);
  66. }
  67. #endif /* _LINUX_USER_H */