Revision 624f5ab8720b3371367327a822c267699c1823b8 authored by Eric Biggers on 07 November 2017, 22:29:02 UTC, committed by James Morris on 08 November 2017, 13:38:21 UTC
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> Cc: <stable@vger.kernel.org> # v3.7+ 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>
1 parent fbc3edf
File | Mode | Size |
---|---|---|
caching | ||
cifs | ||
configfs | ||
nfs | ||
pohmelfs | ||
00-INDEX | -rw-r--r-- | 4.9 KB |
9p.txt | -rw-r--r-- | 5.7 KB |
Locking | -rw-r--r-- | 23.7 KB |
adfs.txt | -rw-r--r-- | 2.6 KB |
affs.txt | -rw-r--r-- | 8.1 KB |
afs.txt | -rw-r--r-- | 6.7 KB |
autofs4-mount-control.txt | -rw-r--r-- | 17.8 KB |
autofs4.txt | -rw-r--r-- | 23.4 KB |
automount-support.txt | -rw-r--r-- | 3.5 KB |
befs.txt | -rw-r--r-- | 3.5 KB |
bfs.txt | -rw-r--r-- | 2.1 KB |
btrfs.txt | -rw-r--r-- | 1.1 KB |
ceph.txt | -rw-r--r-- | 5.7 KB |
coda.txt | -rw-r--r-- | 48.6 KB |
conf.py | -rw-r--r-- | 214 bytes |
cramfs.txt | -rw-r--r-- | 2.5 KB |
dax.txt | -rw-r--r-- | 5.9 KB |
debugfs.txt | -rw-r--r-- | 9.5 KB |
devpts.txt | -rw-r--r-- | 1.3 KB |
directory-locking | -rw-r--r-- | 6.3 KB |
dlmfs.txt | -rw-r--r-- | 4.2 KB |
dnotify.txt | -rw-r--r-- | 2.9 KB |
ecryptfs.txt | -rw-r--r-- | 2.3 KB |
efivarfs.txt | -rw-r--r-- | 975 bytes |
exofs.txt | -rw-r--r-- | 8.5 KB |
ext2.txt | -rw-r--r-- | 18.0 KB |
ext3.txt | -rw-r--r-- | 415 bytes |
ext4.txt | -rw-r--r-- | 27.1 KB |
f2fs.txt | -rw-r--r-- | 28.9 KB |
fiemap.txt | -rw-r--r-- | 9.5 KB |
files.txt | -rw-r--r-- | 4.1 KB |
fuse.txt | -rw-r--r-- | 15.8 KB |
gfs2-glocks.txt | -rw-r--r-- | 10.5 KB |
gfs2-uevents.txt | -rw-r--r-- | 3.7 KB |
gfs2.txt | -rw-r--r-- | 1.8 KB |
hfs.txt | -rw-r--r-- | 2.9 KB |
hfsplus.txt | -rw-r--r-- | 1.7 KB |
hpfs.txt | -rw-r--r-- | 14.8 KB |
index.rst | -rw-r--r-- | 10.0 KB |
inotify.txt | -rw-r--r-- | 3.8 KB |
isofs.txt | -rw-r--r-- | 2.5 KB |
jfs.txt | -rw-r--r-- | 2.3 KB |
locks.txt | -rw-r--r-- | 2.7 KB |
mandatory-locking.txt | -rw-r--r-- | 8.0 KB |
ncpfs.txt | -rw-r--r-- | 574 bytes |
nilfs2.txt | -rw-r--r-- | 10.8 KB |
ntfs.txt | -rw-r--r-- | 19.7 KB |
ocfs2-online-filecheck.txt | -rw-r--r-- | 3.8 KB |
ocfs2.txt | -rw-r--r-- | 4.5 KB |
omfs.txt | -rw-r--r-- | 4.0 KB |
orangefs.txt | -rw-r--r-- | 17.2 KB |
overlayfs.txt | -rw-r--r-- | 11.5 KB |
path-lookup.md | -rw-r--r-- | 64.2 KB |
path-lookup.txt | -rw-r--r-- | 18.5 KB |
porting | -rw-r--r-- | 23.0 KB |
proc.txt | -rw-r--r-- | 88.4 KB |
qnx6.txt | -rw-r--r-- | 7.1 KB |
quota.txt | -rw-r--r-- | 3.2 KB |
ramfs-rootfs-initramfs.txt | -rw-r--r-- | 15.9 KB |
relay.txt | -rw-r--r-- | 21.1 KB |
romfs.txt | -rw-r--r-- | 8.3 KB |
seq_file.txt | -rw-r--r-- | 13.3 KB |
sharedsubtree.txt | -rw-r--r-- | 29.0 KB |
spufs.txt | -rw-r--r-- | 20.3 KB |
squashfs.txt | -rw-r--r-- | 10.4 KB |
sysfs-pci.txt | -rw-r--r-- | 5.7 KB |
sysfs-tagging.txt | -rw-r--r-- | 1.8 KB |
sysfs.txt | -rw-r--r-- | 11.8 KB |
sysv-fs.txt | -rw-r--r-- | 7.4 KB |
tmpfs.txt | -rw-r--r-- | 6.5 KB |
ubifs.txt | -rw-r--r-- | 5.1 KB |
udf.txt | -rw-r--r-- | 3.4 KB |
ufs.txt | -rw-r--r-- | 1.2 KB |
vfat.txt | -rw-r--r-- | 15.7 KB |
vfs.txt | -rw-r--r-- | 53.1 KB |
xfs-delayed-logging-design.txt | -rw-r--r-- | 40.5 KB |
xfs-self-describing-metadata.txt | -rw-r--r-- | 16.5 KB |
xfs.txt | -rw-r--r-- | 17.3 KB |
Computing file changes ...