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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. @@ -170,7 +172,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. @@ -203,7 +205,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. @@ -245,6 +247,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/Makefile.am
  65. +++ b/tests/Makefile.am
  66. @@ -2,7 +2,8 @@
  67. LDFLAGS += $(top_builddir)/lib/libjose.la @jansson_LIBS@
  68. EXTRA_DIST = vectors
  69. -AM_TESTS_ENVIRONMENT=PATH=$(top_builddir)/cmd:$(PATH) VECTORS=$(top_srcdir)/tests/vectors
  70. +AM_TESTS_ENVIRONMENT=PATH=$(top_builddir)/cmd:$(PATH) VECTORS=$(top_srcdir)/tests/vectors CVE_2023_50967=$(top_srcdir)/tests/cve-2023-50967
  71. +
  72. TESTS = $(dist_check_SCRIPTS) $(check_PROGRAMS)
  73. check_PROGRAMS = \