crypto: rsa-pkcs1pad: Don't WARN on an empty digest
Subsystems (2)
PATCH 1/1 crypto: rsa-pkcs1pad: Don't WARN on an empty digest
KEYCTL_PKEY_VERIFY lets an unprivileged caller supply a zero-length digest (in_len == 0). keyctl_pkey_params_get_2() accepts the zero length and the request reaches pkcs1pad_verify(), where the empty digest is rejected but only after being passed through WARN_ON(!req->dst_len). The warning is therefore directly user-triggerable, and on kernels built with panic_on_warn=1 an unprivileged process can panic the machine -- a local denial of service. Reproduced as UID 65534 in a setuid sandbox.
Keep rejecting the invalid request with -EINVAL, but do not emit a warning for the user-controlled length.
This is the 5.10.y/5.15.y form of the fix, where the length is read directly from req->dst_len rather than cached in a digest_size local. Mainline does not contain this code path; commit 1e562deacecc ("crypto: rsassa-pkcs1 - Migrate to sig_alg backend") removed pkcs1pad_verify() in v6.13-rc1. This is a minimal fix for the affected stable branches. The 6.1.y/6.6.y/6.12.y form (WARN_ON(!digest_size)) is sent as a separate patch.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- crypto/rsa-pkcs1pad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/rsa-pkcs1pad.c +1 -1
@@ -535,7 +535,7 @@ static int pkcs1pad_verify(struct akcipher_request *req)int err;if (WARN_ON (req->dst) || -WARN_ON (!req->dst_len) || + !req->dst_len || !ctx->key_size || req->src_len != ctx->key_size)return -EINVAL ;
Signature · 1 line
2.43.0
Quoted 20 lines · Doruk Tan Ozturk
KEYCTL_PKEY_VERIFYlets an unprivileged caller supply a zero-length digest (in_len== 0).keyctl_pkey_params_get_2()accepts the zero length and the request reachespkcs1pad_verify(), where the empty digest is rejected but only after being passed throughWARN_ON(!req->dst_len). The warning is therefore directly user-triggerable, and on kernels built with panic_on_warn=1 an unprivileged process can panic the machine -- a local denial of service. Reproduced as UID 65534 in a setuid sandbox.Keep rejecting the invalid request with
-EINVAL, but do not emit a warning for the user-controlled length.This is the 5.10.y/5.15.y form of the fix, where the length is read directly from
req->dst_lenrather than cached in adigest_sizelocal. Mainline does not contain this code path; commit1e562deacecc("crypto: rsassa-pkcs1 - Migrate tosig_algbackend") removedpkcs1pad_verify()in v6.13-rc1. This is a minimal fix for the affected stable branches. The 6.1.y/6.6.y/6.12.y form (WARN_ON(!digest_size)) is sent as a separate patch.
Quoted 6 lines
Found by 0sec automated security-research tooling (https://0sec.ai).
Fixes c7381b012872 ("crypto: akcipher - new verify API for public key algorithms")Assisted-by 0sec:multi-modelSigned-off-by Doruk Tan Ozturk <[email protected]>
Quoted 1 line · Lukas Wunner
Reviewed-by Lukas Wunner <[email protected]>
Queued for 5.10 and 5.15, thanks.
Signature · 2 lines
Thanks, Sasha