• Eric Biggers's avatar
    KEYS: asymmetric: enforce that sig algo matches key algo · 2abc9c24
    Eric Biggers authored
    Most callers of public_key_verify_signature(), including most indirect
    callers via verify_signature() as well as pkcs7_verify_sig_chain(),
    don't check that public_key_signature::pkey_algo matches
    public_key::pkey_algo.  These should always match.  However, a malicious
    signature could intentionally declare an unintended algorithm.  It is
    essential that such signatures be rejected outright, or that the
    algorithm of the *key* be used -- not the algorithm of the signature as
    that would allow attackers to choose the algorithm used.
    
    Currently, public_key_verify_signature() correctly uses the key's
    algorithm when deciding which akcipher to allocate.  That's good.
    However, it uses the signature's algorithm when deciding whether to do
    the first step of SM2, which is incorrect.  Also, v4.19 and older
    kernels used the signature's algorithm for the entire process.
    
    Prevent such errors by making public_key_verify_signature() enforce that
    the signature's algorithm (if given) matches the key's algorithm.
    
    Also remove two checks of this done by callers, which are now redundant.
    
    Cc: stable@vger.kernel.org
    Tested-by: default avatarStefan Berger <stefanb@linux.ibm.com>
    Tested-by: default avatarTianjia Zhang <tianjia.zhang@linux.alibaba.com>
    Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
    Reviewed-by: default avatarVitaly Chikunov <vt@altlinux.org>
    Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
    Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
    2abc9c24
pkcs7_verify.c 12.9 KB