devices.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ===========================
  2. Device Whitelist Controller
  3. ===========================
  4. 1. Description
  5. ==============
  6. Implement a cgroup to track and enforce open and mknod restrictions
  7. on device files. A device cgroup associates a device access
  8. whitelist with each cgroup. A whitelist entry has 4 fields.
  9. 'type' is a (all), c (char), or b (block). 'all' means it applies
  10. to all types and all major and minor numbers. Major and minor are
  11. either an integer or * for all. Access is a composition of r
  12. (read), w (write), and m (mknod).
  13. The root device cgroup starts with rwm to 'all'. A child device
  14. cgroup gets a copy of the parent. Administrators can then remove
  15. devices from the whitelist or add new entries. A child cgroup can
  16. never receive a device access which is denied by its parent.
  17. 2. User Interface
  18. =================
  19. An entry is added using devices.allow, and removed using
  20. devices.deny. For instance::
  21. echo 'c 1:3 mr' > /sys/fs/cgroup/1/devices.allow
  22. allows cgroup 1 to read and mknod the device usually known as
  23. /dev/null. Doing::
  24. echo a > /sys/fs/cgroup/1/devices.deny
  25. will remove the default 'a *:* rwm' entry. Doing::
  26. echo a > /sys/fs/cgroup/1/devices.allow
  27. will add the 'a *:* rwm' entry to the whitelist.
  28. 3. Security
  29. ===========
  30. Any task can move itself between cgroups. This clearly won't
  31. suffice, but we can decide the best way to adequately restrict
  32. movement as people get some experience with this. We may just want
  33. to require CAP_SYS_ADMIN, which at least is a separate bit from
  34. CAP_MKNOD. We may want to just refuse moving to a cgroup which
  35. isn't a descendant of the current one. Or we may want to use
  36. CAP_MAC_ADMIN, since we really are trying to lock down root.
  37. CAP_SYS_ADMIN is needed to modify the whitelist or move another
  38. task to a new cgroup. (Again we'll probably want to change that).
  39. A cgroup may not be granted more permissions than the cgroup's
  40. parent has.
  41. 4. Hierarchy
  42. ============
  43. device cgroups maintain hierarchy by making sure a cgroup never has more
  44. access permissions than its parent. Every time an entry is written to
  45. a cgroup's devices.deny file, all its children will have that entry removed
  46. from their whitelist and all the locally set whitelist entries will be
  47. re-evaluated. In case one of the locally set whitelist entries would provide
  48. more access than the cgroup's parent, it'll be removed from the whitelist.
  49. Example::
  50. A
  51. / \
  52. B
  53. group behavior exceptions
  54. A allow "b 8:* rwm", "c 116:1 rw"
  55. B deny "c 1:3 rwm", "c 116:2 rwm", "b 3:* rwm"
  56. If a device is denied in group A::
  57. # echo "c 116:* r" > A/devices.deny
  58. it'll propagate down and after revalidating B's entries, the whitelist entry
  59. "c 116:2 rwm" will be removed::
  60. group whitelist entries denied devices
  61. A all "b 8:* rwm", "c 116:* rw"
  62. B "c 1:3 rwm", "b 3:* rwm" all the rest
  63. In case parent's exceptions change and local exceptions are not allowed
  64. anymore, they'll be deleted.
  65. Notice that new whitelist entries will not be propagated::
  66. A
  67. / \
  68. B
  69. group whitelist entries denied devices
  70. A "c 1:3 rwm", "c 1:5 r" all the rest
  71. B "c 1:3 rwm", "c 1:5 r" all the rest
  72. when adding ``c *:3 rwm``::
  73. # echo "c *:3 rwm" >A/devices.allow
  74. the result::
  75. group whitelist entries denied devices
  76. A "c *:3 rwm", "c 1:5 r" all the rest
  77. B "c 1:3 rwm", "c 1:5 r" all the rest
  78. but now it'll be possible to add new entries to B::
  79. # echo "c 2:3 rwm" >B/devices.allow
  80. # echo "c 50:3 r" >B/devices.allow
  81. or even::
  82. # echo "c *:3 rwm" >B/devices.allow
  83. Allowing or denying all by writing 'a' to devices.allow or devices.deny will
  84. not be possible once the device cgroups has children.
  85. 4.1 Hierarchy (internal implementation)
  86. ---------------------------------------
  87. device cgroups is implemented internally using a behavior (ALLOW, DENY) and a
  88. list of exceptions. The internal state is controlled using the same user
  89. interface to preserve compatibility with the previous whitelist-only
  90. implementation. Removal or addition of exceptions that will reduce the access
  91. to devices will be propagated down the hierarchy.
  92. For every propagated exception, the effective rules will be re-evaluated based
  93. on current parent's access rules.