Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1913878pxb; Thu, 16 Sep 2021 20:05:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSOzPL0koyOMDpHQ7w1LDtdKcL8R3Y4otIbOxhignIDFOIWREQJhZqKEz88UUn0IcNpgNS X-Received: by 2002:a05:6402:358f:: with SMTP id y15mr9745926edc.67.1631847941447; Thu, 16 Sep 2021 20:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631847941; cv=none; d=google.com; s=arc-20160816; b=Lsj2T0eqtLCcm/ktNY6wonznR1ZjAKhFkcm43CzmH268+z0Fkv8ehXg+kkqNt+eMEm WSD82xmZg4uoksPGB7uo7NTPI0PuwktdfEsrDstv9GHdlUDGER1ciEUkuGQ8chDgdzZH Pu0JnUA6c2ep2feYZvsrQMCYAP5lTv+zgrgXef4zudGICG1ptBa2n4KrUCuTdUq6yT6O 9p+4gWNoA3Yy1/YPuEyGfyGqac/3kbxOB/JeW6LQHDG0epWsnzmS5KTlvbsxJRfRvqXv NDu5j3UMwKGgqa1iD2uOdIALVCAXYX72GnuFawif2uWV7J4lgYaXB4Q2F4BLYpyboehy bK4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cbEQeVnWWt8B+ILEpKM0/GGrCPLxUvH57wB01AFdxYA=; b=HOfFtsIEZARMcrUolJTT6PeymsNjrAPJ8lUBtIBVqj4YfaS0R5eQEPsvCoGQXcuLBV bpQEl+joHMBrqZNJHO9LUWSIhoR6ugGqUsrU1hBeuOL/DRU4FtUqJkOGGYsa6bGYbBrE 9VwckfY1MjJn0wWf7Iy6UJZCBeeY9YumDdg2Yr3iZR5MPfsF2pcpxGWz/qioAaVJOTBB zgcaXKSbcwFifXTq/gsCwcsRd3dABPk7hiocTLaB9gntbOvwILPKkxxJ7p4/otRUxfWw oHMNrN/BcDSsK93jv46B4uWZ0AikBIVWnQOTwFs29hrK3CcwB1f1h0ZjnJB9XFAvNp9S D5UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dxOVzmxV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si5876474edm.141.2021.09.16.20.05.17; Thu, 16 Sep 2021 20:05:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dxOVzmxV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352088AbhIPRUe (ORCPT + 99 others); Thu, 16 Sep 2021 13:20:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:37134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344809AbhIPRHU (ORCPT ); Thu, 16 Sep 2021 13:07:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CD700619E5; Thu, 16 Sep 2021 16:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810172; bh=PALLLA4cNsd3d3iksZIZjOimC2VkR4FqFNZeNO2n+SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dxOVzmxVzzZyEO4speZmgi5Z163zWfdCV+ENPDzmyrj/0909+2aNGRpI19PVTU5Bt wdIYBZEhFBsRxq65NybLHlu8o0VzUiNtEnOBAV9coR9lTvD4N+TMSPg0paoDuP4IFz lzs97Eb3N7i8jDYADHfjfoiEd6rWAD1M1C7n4l0w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, zhenwei pi , Jarkko Sakkinen Subject: [PATCH 5.14 043/432] crypto: public_key: fix overflow during implicit conversion Date: Thu, 16 Sep 2021 17:56:32 +0200 Message-Id: <20210916155812.273597593@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: zhenwei pi commit f985911b7bc75d5c98ed24d8aaa8b94c590f7c6a upstream. Hit kernel warning like this, it can be reproduced by verifying 256 bytes datafile by keyctl command, run script: RAWDATA=rawdata SIGDATA=sigdata modprobe pkcs8_key_parser rm -rf *.der *.pem *.pfx rm -rf $RAWDATA dd if=/dev/random of=$RAWDATA bs=256 count=1 openssl req -nodes -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem \ -subj "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=xx.com/emailAddress=yy@xx.com" KEY_ID=`openssl pkcs8 -in key.pem -topk8 -nocrypt -outform DER | keyctl \ padd asymmetric 123 @s` keyctl pkey_sign $KEY_ID 0 $RAWDATA enc=pkcs1 hash=sha1 > $SIGDATA keyctl pkey_verify $KEY_ID 0 $RAWDATA $SIGDATA enc=pkcs1 hash=sha1 Then the kernel reports: WARNING: CPU: 5 PID: 344556 at crypto/rsa-pkcs1pad.c:540 pkcs1pad_verify+0x160/0x190 ... Call Trace: public_key_verify_signature+0x282/0x380 ? software_key_query+0x12d/0x180 ? keyctl_pkey_params_get+0xd6/0x130 asymmetric_key_verify_signature+0x66/0x80 keyctl_pkey_verify+0xa5/0x100 do_syscall_64+0x35/0xb0 entry_SYSCALL_64_after_hwframe+0x44/0xae The reason of this issue, in function 'asymmetric_key_verify_signature': '.digest_size(u8) = params->in_len(u32)' leads overflow of an u8 value, so use u32 instead of u8 for digest_size field. And reorder struct public_key_signature, it saves 8 bytes on a 64-bit machine. Cc: stable@vger.kernel.org Signed-off-by: zhenwei pi Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- include/crypto/public_key.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -38,9 +38,9 @@ extern void public_key_free(struct publi struct public_key_signature { struct asymmetric_key_id *auth_ids[2]; u8 *s; /* Signature */ - u32 s_size; /* Number of bytes in signature */ u8 *digest; - u8 digest_size; /* Number of bytes in digest */ + u32 s_size; /* Number of bytes in signature */ + u32 digest_size; /* Number of bytes in digest */ const char *pkey_algo; const char *hash_algo; const char *encoding;