1623754283.v18-5-gd8a25e3.avoid-luksmeta-corruption-on-clevis-bind-319.patch 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Subject: Avoid luksmeta corruption on clevis bind (#319)
  2. Origin: v18-5-gd8a25e3 <https://github.com/latchset/clevis/commit/v18-5-gd8a25e3>
  3. Upstream-Author: Sergio Arroutbi <sarroutb@redhat.com>
  4. Date: Tue Jun 15 12:51:23 2021 +0200
  5. When using long key information to be stored in luks metadata,
  6. luksmeta save is not reporting the corruption of LUKs meta.
  7. This change detects if issue occurs after luksmeta metadata save
  8. and, in that case, restores the device. Fixes #181
  9. Signed-off-by: Sergio Arroutbi Braojos <sarroutb@redhat.com>
  10. --- a/src/luks/clevis-luks-common-functions.in
  11. +++ b/src/luks/clevis-luks-common-functions.in
  12. @@ -448,6 +448,12 @@
  13. echo "Error saving metadata to LUKSMeta slot ${SLOT} from ${DEV}" >&2
  14. return 1
  15. fi
  16. +
  17. + if ! luksmeta test -d "${DEV}" 2>/dev/null >/dev/null ; then
  18. + echo "Error detected after saving metadata to LUKSMeta slot ${SLOT}, device ${DEV}" >&2
  19. + return 1
  20. + fi
  21. +
  22. return 0
  23. }
  24. --- /dev/null
  25. +++ b/src/luks/tests/bind-luks1-avoid-luksmeta-corruption
  26. @@ -0,0 +1,55 @@
  27. +#!/bin/bash -ex
  28. +#
  29. +# Copyright (c) 2021 Red Hat, Inc.
  30. +# Author: Sergio Arroutbi Braojos <sarroutb@redhat.com>
  31. +#
  32. +# This program is free software: you can redistribute it and/or modify
  33. +# it under the terms of the GNU General Public License as published by
  34. +# the Free Software Foundation, either version 3 of the License, or
  35. +# (at your option) any later version.
  36. +#
  37. +# This program is distributed in the hope that it will be useful,
  38. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. +# GNU General Public License for more details.
  41. +#
  42. +# You should have received a copy of the GNU General Public License
  43. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  44. +#
  45. +
  46. +TEST=$(basename "${0}")
  47. +. tests-common-functions
  48. +
  49. +on_exit() {
  50. + [ ! -d "${TMP}" ] && return 0
  51. + tang_stop "${TMP}"
  52. + rm -rf "${TMP}"
  53. +}
  54. +
  55. +trap 'on_exit' EXIT
  56. +
  57. +TMP="$(mktemp -d)"
  58. +
  59. +ADV_AMOUNT=50
  60. +
  61. +# Create LUKS1 device
  62. +DEV="${TMP}/luks1-device"
  63. +new_device "luks1" "${DEV}"
  64. +
  65. +# TANG server specifics
  66. +port=$(tang_new_random_port)
  67. +tang_run "${TMP}" "${port}"
  68. +url="http://localhost:${port}"
  69. +
  70. +# Initial binding to ensure luksmeta gets corrupted
  71. +for ADV_NU in $(seq 0 ${ADV_AMOUNT}); do
  72. + "${TANGD_KEYGEN}" "${TMP}/db"
  73. +done
  74. +tang_new_keys "${TMP}"
  75. +
  76. +CFG=$(printf '{"url":"%s"}' "${url}")
  77. +
  78. +# At this point, luks bind must return an error. If not, test fails
  79. +if clevis luks bind -y -d "${DEV}" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
  80. + error "${TEST}: Binding is expected to fail when given a too long adv"
  81. +fi
  82. --- a/src/luks/tests/meson.build
  83. +++ b/src/luks/tests/meson.build
  84. @@ -59,6 +59,7 @@
  85. test('backup-restore-luks1', find_program('backup-restore-luks1'), env: env, timeout: 60)
  86. test('pass-tang-luks1', find_program('pass-tang-luks1'), env: env, timeout: 60)
  87. +test('bind-luks1-avoid-luksmeta-corruption', find_program('bind-luks1-avoid-luksmeta-corruption'), env: env, timeout: 60)
  88. # LUKS2 tests go here, and they get included if we get support for it, based
  89. # on the cryptsetup version.