Skip to content
  • Eric Biggers's avatar
    crypto: authenc - fix parsing key with misaligned rta_len · b9119fd2
    Eric Biggers authored
    commit 8f9c4693 upstream.
    
    Keys for "authenc" AEADs are formatted as an rtattr containing a 4-byte
    'enckeylen', followed by an authentication key and an encryption key.
    crypto_authenc_extractkeys() parses the key to find the inner keys.
    
    However, it fails to consider the case where the rtattr's payload is
    longer than 4 bytes but not 4-byte aligned, and where the key ends
    before the next 4-byte aligned boundary.  In this case, 'keylen -=
    RTA_ALIGN(rta->rta_len);' underflows to a value near UINT_MAX.  This
    causes a buffer overread and crash during crypto_ahash_setkey().
    
    Fix it by restricting the rtattr payload to the expected size.
    
    Reproducer using AF_ALG:
    
    	#include <linux/if_alg.h>
    	#include <linux/rtnetlink.h>
    	#include <sys/socket.h>
    
    	int main()
    	{
    		int fd;
    		struct sockaddr_alg addr = {
    			.salg_type = "aead",
    			.salg_name = "authenc(hmac(sha256),cbc(aes))",
    		};
    		struct {
    			struct rtattr attr;
    			__be32 en...
    b9119fd2