1711969854.v12-3-g4ee7708.fix-potential-dos-issue-with-p2c-header.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Subject: Fix potential DoS issue with p2c header
  2. ID: CVE-2023-50967
  3. Origin: v12-3-g4ee7708 <https://github.com/latchset/jose/commit/v12-3-g4ee7708>
  4. Upstream-Author: Sergio Correia <scorreia@redhat.com>
  5. Date: Mon Apr 1 12:10:54 2024 +0100
  6. Unbounded p2c headers may be used to cause an application that accept
  7. PBES algorithms to spend a lot of resources running PBKDF2 with a very
  8. high number of iterations.
  9. Limit the maximum number of iterations to to 32768.
  10. Fixes: CVE-2023-50967
  11. Signed-off-by: Sergio Correia <scorreia@redhat.com>
  12. --- a/lib/openssl/pbes2.c
  13. +++ b/lib/openssl/pbes2.c
  14. @@ -25,6 +25,8 @@
  15. #include <string.h>
  16. #define NAMES "PBES2-HS256+A128KW", "PBES2-HS384+A192KW", "PBES2-HS512+A256KW"
  17. +#define P2C_MIN_ITERATIONS 1000
  18. +#define P2C_MAX_ITERATIONS 32768
  19. static json_t *
  20. pbkdf2(const char *alg, jose_cfg_t *cfg, const json_t *jwk, int iter,
  21. @@ -193,7 +195,7 @@
  22. json_auto_t *hdr = NULL;
  23. const char *aes = NULL;
  24. json_t *h = NULL;
  25. - int p2c = 10000;
  26. + int p2c = P2C_MAX_ITERATIONS;
  27. size_t stl = 0;
  28. if (!json_object_get(cek, "k") && !jose_jwk_gen(cfg, cek))
  29. @@ -226,7 +228,7 @@
  30. json_object_set_new(h, "p2c", json_integer(p2c)) < 0)
  31. return false;
  32. - if (p2c < 1000)
  33. + if (p2c < P2C_MIN_ITERATIONS || p2c > P2C_MAX_ITERATIONS)
  34. return false;
  35. if (json_object_set_new(h, "p2s", jose_b64_enc(st, stl)) == -1)
  36. @@ -268,6 +270,9 @@
  37. if (json_unpack(hdr, "{s:I}", "p2c", &p2c) == -1)
  38. return false;
  39. + if (p2c > P2C_MAX_ITERATIONS)
  40. + return false;
  41. +
  42. stl = jose_b64_dec(json_object_get(hdr, "p2s"), NULL, 0);
  43. if (stl < 8 || stl > sizeof(st))
  44. return false;
  45. --- /dev/null
  46. +++ b/tests/cve-2023-50967/cve-2023-50967.jwe
  47. @@ -0,0 +1 @@
  48. +{"ciphertext":"aaPb-JYGACs-loPwJkZewg","encrypted_key":"P1h8q8wLVxqYsZUuw6iEQTzgXVZHCsu8Eik-oqbE4AJGIDto3gb3SA","header":{"alg":"PBES2-HS256+A128KW","p2c":1000000000,"p2s":"qUQQWWkyyIqculSiC93mlg"},"iv":"Clg3JX9oNl_ck3sLSGrlgg","protected":"eyJlbmMiOiJBMTI4Q0JDLUhTMjU2In0","tag":"i7vga9tJkwRswFd7HlyD_A"}
  49. --- /dev/null
  50. +++ b/tests/cve-2023-50967/cve-2023-50967.jwk
  51. @@ -0,0 +1 @@
  52. +{"alg":"PBES2-HS256+A128KW","k":"VHBLJ4-PmnqELoKbQoXuRA","key_ops":["wrapKey","unwrapKey"],"kty":"oct"}
  53. --- a/tests/jose-jwe-dec
  54. +++ b/tests/jose-jwe-dec
  55. @@ -53,3 +53,8 @@
  56. test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.1.jwk`" = "`cat $prfx.13.pt`"
  57. test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.2.jwk`" = "`cat $prfx.13.pt`"
  58. test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.3.jwk`" = "`cat $prfx.13.pt`"
  59. +
  60. +# CVE-2023-50967 - test originally from https://github.com/P3ngu1nW/CVE_Request/blob/main/latch-jose.md
  61. +# This test is expected to fail quickly on patched systems.
  62. +prfx="${CVE_2023_50967}/cve-2023-50967"
  63. +! test "$(jose jwe dec -i $prfx.jwe -k $prfx.jwk)"
  64. --- a/tests/meson.build
  65. +++ b/tests/meson.build
  66. @@ -31,6 +31,8 @@
  67. e = environment()
  68. e.prepend('PATH', meson.current_build_dir() + '/../cmd', separator: ':')
  69. e.set('VECTORS', meson.current_source_dir() + '/vectors')
  70. +e.set('CVE_2023_50967', meson.current_source_dir() + '/cve-2023-50967')
  71. +
  72. foreach p: progs
  73. exe = executable(p, p + '.c', dependencies: jansson, link_with: libjose)