devices.txt 4.3 KB

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