Eric Biggers
8ea52a683f
KEYS: fix NULL pointer dereference during ASN.1 parsing [ver #2 ]
...
commit 624f5ab8720b3371367327a822c267699c1823b8 upstream.
syzkaller reported a NULL pointer dereference in asn1_ber_decoder(). It
can be reproduced by the following command, assuming
CONFIG_PKCS7_TEST_KEY=y:
keyctl add pkcs7_test desc '' @s
The bug is that if the data buffer is empty, an integer underflow occurs
in the following check:
if (unlikely(dp >= datalen - 1))
goto data_overrun_error;
This results in the NULL data pointer being dereferenced.
Fix it by checking for 'datalen - dp < 2' instead.
Also fix the similar check for 'dp >= datalen - n' later in the same
function. That one possibly could result in a buffer overread.
The NULL pointer dereference was reproducible using the "pkcs7_test" key
type but not the "asymmetric" key type because the "asymmetric" key type
checks for a 0-length payload before calling into the ASN.1 decoder but
the "pkcs7_test" key type does not.
The bug report was:
BUG: unable to handle kernel NULL pointer dereference at (null)
IP: asn1_ber_decoder+0x17f/0xe60 lib/asn1_decoder.c:233
PGD 7b708067 P4D 7b708067 PUD 7b6ee067 PMD 0
Oops: 0000 [#1 ] SMP
Modules linked in:
CPU: 0 PID: 522 Comm: syz-executor1 Not tainted 4.14.0-rc8 #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.3-20171021_125229-anatol 04/01/2014
task: ffff9b6b3798c040 task.stack: ffff9b6b37970000
RIP: 0010:asn1_ber_decoder+0x17f/0xe60 lib/asn1_decoder.c:233
RSP: 0018:ffff9b6b37973c78 EFLAGS: 00010216
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 000000000000021c
RDX: ffffffff814a04ed RSI: ffffb1524066e000 RDI: ffffffff910759e0
RBP: ffff9b6b37973d60 R08: 0000000000000001 R09: ffff9b6b3caa4180
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000002
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
FS: 00007f10ed1f2700(0000) GS:ffff9b6b3ea00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000007b6f3000 CR4: 00000000000006f0
Call Trace:
pkcs7_parse_message+0xee/0x240 crypto/asymmetric_keys/pkcs7_parser.c:139
verify_pkcs7_signature+0x33/0x180 certs/system_keyring.c:216
pkcs7_preparse+0x41/0x70 crypto/asymmetric_keys/pkcs7_key_type.c:63
key_create_or_update+0x180/0x530 security/keys/key.c:855
SYSC_add_key security/keys/keyctl.c:122 [inline]
SyS_add_key+0xbf/0x250 security/keys/keyctl.c:62
entry_SYSCALL_64_fastpath+0x1f/0xbe
RIP: 0033:0x4585c9
RSP: 002b:00007f10ed1f1bd8 EFLAGS: 00000216 ORIG_RAX: 00000000000000f8
RAX: ffffffffffffffda RBX: 00007f10ed1f2700 RCX: 00000000004585c9
RDX: 0000000020000000 RSI: 0000000020008ffb RDI: 0000000020008000
RBP: 0000000000000000 R08: ffffffffffffffff R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000216 R12: 00007fff1b2260ae
R13: 00007fff1b2260af R14: 00007f10ed1f2700 R15: 0000000000000000
Code: dd ca ff 48 8b 45 88 48 83 e8 01 4c 39 f0 0f 86 a8 07 00 00 e8 53 dd ca ff 49 8d 46 01 48 89 85 58 ff ff ff 48 8b 85 60 ff ff ff <42> 0f b6 0c 30 89 c8 88 8d 75 ff ff ff 83 e0 1f 89 8d 28 ff ff
RIP: asn1_ber_decoder+0x17f/0xe60 lib/asn1_decoder.c:233 RSP: ffff9b6b37973c78
CR2: 0000000000000000
Fixes: 42d5ec27f873 ("X.509: Add an ASN.1 decoder")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-15 15:53:18 +01:00
..
2016-03-17 21:38:27 -07:00
2014-10-09 11:35:48 +03:00
2017-09-02 07:07:54 +02:00
2014-09-28 11:08:01 +02:00
2017-09-07 08:35:40 +02:00
2016-10-07 09:45:43 -07:00
2014-06-04 16:54:18 -07:00
2015-09-10 13:29:01 -07:00
2014-08-06 18:01:24 -07:00
2017-11-15 15:53:18 +01:00
2017-11-02 09:49:14 +01:00
2016-10-07 18:46:30 -07:00
locking/atomic: Implement atomic{,64,_long}_fetch_{add,sub,and,andnot,or,xor}{,_relaxed,_acquire,_release}()
2016-06-16 10:48:32 +02:00
2014-12-13 12:42:51 -08:00
2016-10-11 15:06:30 -07:00
2014-12-22 16:43:06 +00:00
2015-11-23 09:44:58 +01:00
2016-03-17 15:09:34 -07:00
2016-07-03 00:57:23 -04:00
2016-03-13 23:55:13 -04:00
2014-04-03 16:21:12 -07:00
2017-06-29 13:00:28 +02:00
2014-03-20 10:11:35 -04:00
2015-05-27 15:22:15 +02:00
2016-09-19 21:44:31 +02:00
2017-07-21 07:42:23 +02:00
2014-05-16 14:26:52 -04:00
2016-08-02 19:35:08 -04:00
2015-05-26 15:26:43 +02:00
2015-05-30 22:42:24 -07:00
2015-06-11 15:08:32 +02:00
2016-11-30 16:32:52 -08:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-09-10 13:29:01 -07:00
2015-07-17 16:39:54 -07:00
2016-02-07 23:17:59 -08:00
2017-10-27 10:38:08 +02:00
2015-11-16 14:42:12 -05:00
2016-10-06 17:13:54 -07:00
2016-08-04 08:50:07 -04:00
2016-02-05 18:10:40 -08:00
2016-08-04 08:50:07 -04:00
2015-02-12 18:54:15 -08:00
2016-06-08 11:04:19 +02:00
2016-02-24 14:57:26 +00:00
2015-10-23 17:55:10 +09:00
2014-04-30 19:49:37 +01:00
2015-04-17 09:03:54 -04:00
2014-01-21 23:17:20 -08:00
2016-02-15 11:18:23 +01:00
2016-05-20 17:58:30 -07:00
2015-02-13 21:21:35 -08:00
2016-10-27 18:43:43 -07:00
2014-08-06 18:01:25 -07:00
2015-11-06 17:50:42 -08:00
2015-11-06 17:50:42 -08:00
2016-06-08 15:01:02 +02:00
2015-11-06 17:50:42 -08:00
2014-05-05 09:09:14 +02:00
2015-02-12 18:54:15 -08:00
2016-01-20 17:09:18 -08:00
2014-04-07 16:36:11 -07:00
2015-11-05 16:34:48 -08:00
2016-08-02 19:35:07 -04:00
2015-04-14 16:49:04 -07:00
2017-04-21 09:31:21 +02:00
2016-10-15 10:03:15 -07:00
2015-11-06 17:50:42 -08:00
2016-01-16 11:17:27 -08:00
2016-10-07 21:38:00 -07:00
2017-08-11 08:49:36 -07:00
2016-07-28 16:07:41 -07:00
2016-05-23 17:04:14 -07:00
2016-09-20 14:26:08 +02:00
2014-08-08 15:57:25 -07:00
2016-02-07 22:18:47 -08:00
2015-02-12 18:54:15 -08:00
2016-02-09 17:36:34 -08:00
2016-10-11 15:06:30 -07:00
2015-03-31 09:45:50 -06:00
2017-06-24 07:11:17 +02:00
2016-03-09 15:43:42 -08:00
2015-06-16 14:12:35 -04:00
2015-11-06 17:50:42 -08:00
2016-11-25 07:12:19 +01:00
2015-08-12 11:59:04 +02:00
2015-11-25 09:22:02 -07:00
2016-10-11 15:06:32 -07:00
2015-02-12 18:54:15 -08:00
2014-06-25 17:45:43 -07:00
2015-12-03 11:49:23 -05:00
2016-04-23 20:13:24 -04:00
2016-10-07 18:46:30 -07:00
2016-05-19 19:12:14 -07:00
2015-10-08 05:26:36 -07:00
2014-01-23 16:36:55 -08:00
2015-09-08 14:35:59 -07:00
2016-05-19 19:12:14 -07:00
2015-11-06 17:50:42 -08:00
2013-11-13 12:09:11 +09:00
2016-08-11 13:52:23 -04:00
2015-02-12 18:54:16 -08:00
2016-12-09 10:41:42 -08:00
2016-10-15 10:03:15 -07:00
2017-10-12 11:51:19 +02:00
2014-01-23 16:37:03 -08:00
2016-07-06 10:51:14 +01:00
2014-01-21 23:17:20 -08:00
2016-09-20 04:43:36 -04:00
2016-09-19 08:19:40 -06:00
2016-02-08 10:15:17 -08:00
2015-12-23 14:27:20 -05:00
2016-04-15 16:53:14 -04:00
2015-08-24 14:28:01 -06:00
2015-03-23 22:12:08 -04:00
2015-09-08 15:35:28 -07:00
2014-04-07 16:36:14 -07:00
2015-06-25 17:00:40 -07:00
2016-11-11 08:12:37 -08:00
2015-02-12 18:54:16 -08:00
2016-04-21 10:47:26 +10:00
2016-03-17 15:09:34 -07:00
2016-10-11 15:06:30 -07:00
2016-08-08 13:02:01 -07:00
2017-07-05 14:40:26 +02:00
2017-04-08 09:30:35 +02:00
2016-02-19 22:54:09 -05:00
2017-05-14 14:00:21 +02:00
2016-01-07 13:44:22 -07:00
2016-09-01 17:52:01 -07:00
2016-01-20 17:09:18 -08:00
2016-11-30 16:32:52 -08:00
2014-01-23 16:36:57 -08:00
2016-03-15 16:55:16 -07:00
2016-08-08 12:52:42 -07:00
2015-08-03 11:51:12 +02:00
2016-02-09 10:27:29 +01:00
2017-06-14 15:06:05 +02:00
2016-05-30 15:26:57 -07:00
2015-09-10 13:29:01 -07:00
2016-02-03 08:28:43 -08:00
2014-10-14 02:18:14 +02:00
2015-04-22 17:06:49 +02:00
2016-08-02 17:31:41 -04:00
2016-01-20 17:09:18 -08:00
2016-09-09 16:08:46 +01:00
2016-05-30 15:26:57 -07:00
2016-05-20 17:58:30 -07:00
2016-09-21 00:22:59 -04:00