zhenwei pi
aab312696d
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:47:59 +02:00
..
2021-07-20 16:15:44 +02:00
2021-05-22 10:59:14 +02:00
2021-05-22 10:59:14 +02:00
2017-11-02 11:10:55 +01:00
2021-05-22 10:59:14 +02:00
2018-04-21 00:58:32 +08:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2016-11-28 21:23:21 +08:00
2019-11-20 18:47:11 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2018-07-09 00:26:22 +08:00
2018-08-03 18:05:48 +08:00
2017-10-12 22:55:00 +08:00
2018-02-15 23:26:50 +08:00
2017-09-22 17:43:08 +08:00
2017-11-03 21:50:43 +08:00
2017-11-02 11:10:55 +01:00
2015-12-20 15:27:12 +02:00
2021-05-22 10:59:14 +02:00
2017-11-02 11:10:55 +01:00
2020-07-09 09:37:10 +02:00
2021-05-22 10:59:14 +02:00
2017-12-11 22:29:54 +11:00
2017-11-02 11:10:55 +01:00
2018-05-19 00:15:18 +08:00
2018-05-19 00:15:18 +08:00
2018-05-19 00:15:00 +08:00
2017-12-22 19:29:08 +11:00
2016-04-06 16:14:24 +01:00
2018-01-12 23:03:14 +11:00
2021-09-22 11:47:59 +02:00
2021-05-22 10:59:14 +02:00
2018-08-03 18:06:04 +08:00
2017-11-02 11:10:55 +01:00
2018-01-26 01:10:34 +11:00
2018-06-22 23:03:05 +08:00
2021-05-22 10:59:14 +02:00
2017-09-22 17:43:07 +08:00
2017-09-22 17:43:07 +08:00
2018-05-05 14:52:51 +08:00
2017-11-02 11:10:55 +01:00
2018-03-03 00:03:33 +08:00