1623378825.v18-3-g4600bd6.do-not-kill-non-clevis-slots-315.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. Subject: Do not kill non clevis slots (#315)
  2. Origin: v18-3-g4600bd6 <https://github.com/latchset/clevis/commit/v18-3-g4600bd6>
  3. Upstream-Author: Sergio Arroutbi <sarroutb@redhat.com>
  4. Date: Fri Jun 11 04:33:45 2021 +0200
  5. When using clevis-luks-unbind against a slot
  6. that has no clevis token assigned, removing the slot
  7. must be avoided. Fixes #183
  8. Signed-off-by: Sergio Arroutbi Braojos <sarroutb@redhat.com>
  9. --- a/src/luks/clevis-luks-unbind.in
  10. +++ b/src/luks/clevis-luks-unbind.in
  11. @@ -106,6 +106,10 @@
  12. grep -q "^\s*$SLT: luks2" <<< "$dump" && KILL=true
  13. TOK="$(grep -E -B1 "^\s+Keyslot:\s+$SLT$" <<< "$dump" \
  14. | sed -rn 's|^\s+([0-9]+): clevis|\1|p')"
  15. + if [ -z "${TOK}" ]; then
  16. + echo "No clevis slot detected on device ${DEV}:${SLT}!" >&2
  17. + exit 1
  18. + fi
  19. fi
  20. if [ -z "${FRC[*]}" ]; then
  21. --- a/src/luks/tests/unbind-luks2
  22. +++ b/src/luks/tests/unbind-luks2
  23. @@ -42,10 +42,23 @@
  24. new_device "luks2" "${DEV}"
  25. # Binding.
  26. if ! clevis luks bind -d "${DEV}" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
  27. - error "${TEST}: Binding is expected to succeed." >&2
  28. + error "${TEST}: Binding is expected to succeed."
  29. fi
  30. SLT=1
  31. if ! clevis luks unbind -f -d "${DEV}" -s "${SLT}"; then
  32. - error "${TEST}: Unbind is expected to succeed for device ${DEV} and slot ${SLT}" >&2
  33. + error "${TEST}: Unbind is expected to succeed for device ${DEV} and slot ${SLT}"
  34. +fi
  35. +
  36. +SLT=0
  37. +if ! echo "${DEFAULT_PASS}" | cryptsetup open --test-passphrase "${DEV}" --key-slot "${SLT}"; then
  38. + error "${TEST}: Unable to open device ${DEV}:${SLT}"
  39. +fi
  40. +
  41. +if clevis luks unbind -f -d "${DEV}" -s "${SLT}"; then
  42. + error "${TEST}: Unbind is expected to fail for device ${DEV}:${SLT} that is not bound with clevis"
  43. +fi
  44. +
  45. +if ! echo "${DEFAULT_PASS}" | cryptsetup open --test-passphrase "${DEV}" --key-slot "${SLT}"; then
  46. + error "${TEST}: Unbind is expected not to remove non clevis slots"
  47. fi