zhenwei pi
a67d0cfe1a
crypto: public_key: fix overflow during implicit conversion
...
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 <pizhenwei@bytedance.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-09-22 11:43:03 +02:00
..
2021-07-20 16:20:59 +02:00
2013-09-24 06:02:24 +10:00
2016-07-18 17:35:38 +08:00
2016-02-17 04:07:53 +08:00
2016-09-07 21:08:26 +08:00
2013-10-16 20:56:25 +08:00
2011-09-22 21:25:25 +10:00
2012-12-06 17:16:26 +08:00
2012-12-06 17:16:26 +08:00
2012-12-06 17:16:26 +08:00
2016-07-03 00:57:23 -04:00
2016-06-23 18:29:52 +08:00
2014-06-20 21:27:58 +08:00
2016-06-23 18:29:56 +08:00
2016-11-30 19:46:44 +08:00
2016-06-23 18:29:57 +08:00
2016-09-07 21:08:27 +08:00
2016-10-02 22:26:40 +08:00
2015-12-20 15:27:12 +02:00
2018-02-25 11:05:44 +01:00
2020-07-09 09:35:55 +02:00
2016-06-23 18:29:57 +08:00
2011-11-09 11:50:31 +08:00
2017-12-29 17:42:58 +01:00
2015-12-22 20:43:35 +08:00
2016-07-18 17:35:44 +08:00
2016-04-06 16:14:24 +01:00
2018-02-17 13:21:15 +01:00
2021-09-22 11:43:03 +02:00
2015-06-04 15:05:08 +08:00
2016-07-18 17:35:50 +08:00
2011-11-21 16:13:24 +08:00
2015-04-10 21:39:39 +08:00
2016-06-20 19:25:01 +08:00
2015-04-10 21:39:39 +08:00
2015-04-10 21:39:39 +08:00
2015-12-22 20:43:35 +08:00
2016-07-19 15:42:42 +08:00
2011-11-09 11:53:32 +08:00
2016-02-17 04:07:51 +08:00