Skip to content

Commit 4ee7708

Browse files
Fix potential DoS issue with p2c header
Unbounded p2c headers may be used to cause an application that accept PBES algorithms to spend a lot of resources running PBKDF2 with a very high number of iterations. Limit the maximum number of iterations to to 32768. Fixes: CVE-2023-50967 Signed-off-by: Sergio Correia <[email protected]>
1 parent dae5654 commit 4ee7708

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

lib/openssl/pbes2.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <string.h>
2626

2727
#define NAMES "PBES2-HS256+A128KW", "PBES2-HS384+A192KW", "PBES2-HS512+A256KW"
28+
#define P2C_MIN_ITERATIONS 1000
29+
#define P2C_MAX_ITERATIONS 32768
2830

2931
static json_t *
3032
pbkdf2(const char *alg, jose_cfg_t *cfg, const json_t *jwk, int iter,
@@ -193,7 +195,7 @@ alg_wrap_wrp(const jose_hook_alg_t *alg, jose_cfg_t *cfg, json_t *jwe,
193195
json_auto_t *hdr = NULL;
194196
const char *aes = NULL;
195197
json_t *h = NULL;
196-
int p2c = 10000;
198+
int p2c = P2C_MAX_ITERATIONS;
197199
size_t stl = 0;
198200

199201
if (!json_object_get(cek, "k") && !jose_jwk_gen(cfg, cek))
@@ -226,7 +228,7 @@ alg_wrap_wrp(const jose_hook_alg_t *alg, jose_cfg_t *cfg, json_t *jwe,
226228
json_object_set_new(h, "p2c", json_integer(p2c)) < 0)
227229
return false;
228230

229-
if (p2c < 1000)
231+
if (p2c < P2C_MIN_ITERATIONS || p2c > P2C_MAX_ITERATIONS)
230232
return false;
231233

232234
if (json_object_set_new(h, "p2s", jose_b64_enc(st, stl)) == -1)
@@ -268,6 +270,9 @@ alg_wrap_unw(const jose_hook_alg_t *alg, jose_cfg_t *cfg, const json_t *jwe,
268270
if (json_unpack(hdr, "{s:I}", "p2c", &p2c) == -1)
269271
return false;
270272

273+
if (p2c > P2C_MAX_ITERATIONS)
274+
return false;
275+
271276
stl = jose_b64_dec(json_object_get(hdr, "p2s"), NULL, 0);
272277
if (stl < 8 || stl > sizeof(st))
273278
return false;
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"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"}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"alg":"PBES2-HS256+A128KW","k":"VHBLJ4-PmnqELoKbQoXuRA","key_ops":["wrapKey","unwrapKey"],"kty":"oct"}

tests/jose-jwe-dec

+5
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ test "`jose jwe dec -i $prfx.12.jweg -k $prfx.12.jwk`" = "`cat $prfx.12.pt`"
5353
test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.1.jwk`" = "`cat $prfx.13.pt`"
5454
test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.2.jwk`" = "`cat $prfx.13.pt`"
5555
test "`jose jwe dec -i $prfx.13.jweg -k $prfx.13.3.jwk`" = "`cat $prfx.13.pt`"
56+
57+
# CVE-2023-50967 - test originally from https://github.com/P3ngu1nW/CVE_Request/blob/main/latch-jose.md
58+
# This test is expected to fail quickly on patched systems.
59+
prfx="${CVE_2023_50967}/cve-2023-50967"
60+
! test "$(jose jwe dec -i $prfx.jwe -k $prfx.jwk)"

tests/meson.build

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ progs = [
3131
e = environment()
3232
e.prepend('PATH', meson.current_build_dir() + '/../cmd', separator: ':')
3333
e.set('VECTORS', meson.current_source_dir() + '/vectors')
34+
e.set('CVE_2023_50967', meson.current_source_dir() + '/cve-2023-50967')
35+
3436

3537
foreach p: progs
3638
exe = executable(p, p + '.c', dependencies: libjose_dep)

0 commit comments

Comments
 (0)