Skip to content

Commit e96dc36

Browse files
committed
linuxkm/lkcapi_aes_glue.c: fix scatterwalk_map error handling in AesGcmCrypt_1
When scatterwalk_map fails in either the stream or non-stream path, the code jumped to cleanup without setting err, causing the function to return 0 (success) despite the failure. This could cause the kernel crypto layer to treat uninitialized data as valid ciphertext/plaintext. - Capture the error code (PTR_ERR) into err before goto out - Fix PTR_ERR arguments that incorrectly used assoc instead of in_map/out_map (assoc was NULL or pointed to the wrong mapping) - Make in_map/out_map NULL assignments unconditional (previously gated behind < 6.15, but the cleanup at out: checks these pointers on all kernel versions) - Remove bogus scatterwalk_unmap of a failed walk in the stream path on >= 6.15 Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
1 parent a6195c3 commit e96dc36

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

linuxkm/lkcapi_aes_glue.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,12 +1148,11 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
11481148
assoc = scatterwalk_map(&assocSgWalk);
11491149
#endif
11501150
if (unlikely(IS_ERR(assoc))) {
1151+
err = (int)PTR_ERR(assoc);
11511152
pr_err("%s: scatterwalk_map failed: %ld\n",
11521153
crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)),
11531154
PTR_ERR(assoc));
1154-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 15, 0)
1155-
scatterwalk_unmap(&assocSgWalk);
1156-
#endif
1155+
assoc = NULL;
11571156
goto out;
11581157
}
11591158
}
@@ -1355,12 +1354,11 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
13551354
in_map = scatterwalk_map(&in_walk);
13561355
#endif
13571356
if (unlikely(IS_ERR(in_map))) {
1357+
err = (int)PTR_ERR(in_map);
13581358
pr_err("%s: scatterwalk_map failed: %ld\n",
13591359
crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)),
1360-
PTR_ERR(assoc));
1361-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 15, 0)
1360+
PTR_ERR(in_map));
13621361
in_map = NULL;
1363-
#endif
13641362
goto out;
13651363
}
13661364
assoc = in_map;
@@ -1374,12 +1372,11 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
13741372
out_map = scatterwalk_map(&out_walk);
13751373
#endif
13761374
if (unlikely(IS_ERR(out_map))) {
1375+
err = (int)PTR_ERR(out_map);
13771376
pr_err("%s: scatterwalk_map failed: %ld\n",
13781377
crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)),
1379-
PTR_ERR(assoc));
1380-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 15, 0)
1378+
PTR_ERR(out_map));
13811379
out_map = NULL;
1382-
#endif
13831380
goto out;
13841381
}
13851382
out_text = out_map + req->assoclen;

0 commit comments

Comments
 (0)