[GH-ISSUE #1309] AddressSanitizer: global-buffer-overflow for gpg2john #830

Closed
opened 2026-10-14 03:25:31 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @loverszhaokai on GitHub (May 14, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1309

Originally assigned to: @loverszhaokai on GitHub.

#1. Reproduce

$ ./configure --enable-asan && make -sj8
$ ../gpg2john failed_gpg

=================================================================
==50106==ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000013b6380 at pc 0x7a6c05 bp 0x7fff82141060 sp 0x7fff82141058
WRITE of size 1 at 0x0000013b6380 thread T0
    #0 0x7a6c04 in encrypted_Secret_Key /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:2462
    #1 0x7a824e in Secret_Key_Packet /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:2233
    #2 0x7a8619 in parse_packet /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:1462
    #3 0x7a8bf5 in gpg2john /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:348
    #4 0x73e2ce in main /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/john.c:1664
    #5 0x7f2d5d979ec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
    #6 0x406b32 (/home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/run/john+0x406b32)

0x0000013b6380 is located 32 bytes to the left of global variable 'd_bits' from 'gpg2john.c' (0x13b63a0) of size 4
0x0000013b6380 is located 28 bytes to the right of global variable 'p_bits' from 'gpg2john.c' (0x13b6360) of size 4
SUMMARY: AddressSanitizer: global-buffer-overflow /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:2462 encrypted_Secret_Key
Shadow bytes around the buggy address:
  0x00008026ec20: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ec30: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ec40: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ec50: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ec60: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
=>0x00008026ec70:[f9]f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ec80: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ec90: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026eca0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x00008026ecb0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 f9 f9
  0x00008026ecc0: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Contiguous container OOB:fc
  ASan internal:           fe
==50106==ABORTING
Aborted

$ cat failed_gpg

-----BEGIN PGP P

lQHpBFJ0PVIRBADhjnqRa7AYQIGerrlrti+lGb6oetURRTM6kYoJJrBO83q9bgjD
eYDmZqDh4j5UIkqjeMbSo0mKuTR9spAFQ3L8jRAxVgE5FQcRiPYOePQN3mo1R+cF
KmY3Fw9Q6S5Y+Rdwa1QUaqljsLgaEi88TI9EGu/2gW5aV1dqB5Eyu9uV5wCg1AfC
uIsPh/FtPxNKVhUWjbHk9RUE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ruz2w5yEYSF3wry+i2THfN38f3cvvBr3nw9rgNrrtXdyReICN432djz2ZpyyDOU
sb2a98fjjYhJBBgRAgAJBQJSdD1SAhsMAAoJEDukhDdqKEJhsakAniEVBUtkoAK8
3gXMFIB7G8GeoREFAKDTRvQhNIBdaADNGGAsZOvBuQcQFw==

#2. Analysis

// len=-458
encrypted_Secret_Key(int len, int sha1)
{
                                ...

                                cp = last_hash;
                                cp += sprintf(cp, "$gpg$*%d*%d*%d*", m_algorithm, len, key_bits);
                                // cp += -458 * 2
                                cp += print_hex(m_data, len, cp);
                                cp += sprintf(cp, "*%d*%d*%d*%d*%d*", m_spec, m_usage, m_hashAlgorithm, m_cipherAlgorithm, bs);
                                cp += print_hex(iv, bs, cp);
                                cp += sprintf(cp, "*%d*", m_count);
                                cp += print_hex(m_salt, 8, cp);
                                if (m_usage == 255) { /* handle 2 byte checksum */
                                        cp += sprintf(cp, "*%d*", (key_bits + 7) / 8);

                                        cp += print_hex(p, (key_bits + 7) / 8, cp);
                                        cp += sprintf(cp, "*%d*", (q_bits + 7) / 8);
                                        cp += print_hex(q, (q_bits + 7) / 8, cp);
                                        cp += sprintf(cp, "*%d*", (g_bits + 7) / 8);
                                        cp += print_hex(g, (g_bits + 7) / 8, cp);
                                        cp += sprintf(cp, "*%d*", (y_bits + 7) / 8);
                                        cp += print_hex(y, (y_bits + 7) / 8, cp);
                                }
                                *cp = 0;

                                ...
}

The encrypted_Secret_Key() first parameter len can not be negative.

So could here add a check for len?

Originally created by @loverszhaokai on GitHub (May 14, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1309 Originally assigned to: @loverszhaokai on GitHub. #1. Reproduce $ ./configure --enable-asan && make -sj8 $ ../gpg2john failed_gpg ``` C ================================================================= ==50106==ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000013b6380 at pc 0x7a6c05 bp 0x7fff82141060 sp 0x7fff82141058 WRITE of size 1 at 0x0000013b6380 thread T0 #0 0x7a6c04 in encrypted_Secret_Key /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:2462 #1 0x7a824e in Secret_Key_Packet /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:2233 #2 0x7a8619 in parse_packet /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:1462 #3 0x7a8bf5 in gpg2john /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:348 #4 0x73e2ce in main /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/john.c:1664 #5 0x7f2d5d979ec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4) #6 0x406b32 (/home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/run/john+0x406b32) 0x0000013b6380 is located 32 bytes to the left of global variable 'd_bits' from 'gpg2john.c' (0x13b63a0) of size 4 0x0000013b6380 is located 28 bytes to the right of global variable 'p_bits' from 'gpg2john.c' (0x13b6360) of size 4 SUMMARY: AddressSanitizer: global-buffer-overflow /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_kai/src/gpg2john.c:2462 encrypted_Secret_Key Shadow bytes around the buggy address: 0x00008026ec20: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ec30: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ec40: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ec50: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ec60: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 =>0x00008026ec70:[f9]f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ec80: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ec90: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026eca0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x00008026ecb0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 f9 f9 0x00008026ecc0: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Contiguous container OOB:fc ASan internal: fe ==50106==ABORTING Aborted ``` $ cat failed_gpg ``` -----BEGIN PGP P lQHpBFJ0PVIRBADhjnqRa7AYQIGerrlrti+lGb6oetURRTM6kYoJJrBO83q9bgjD eYDmZqDh4j5UIkqjeMbSo0mKuTR9spAFQ3L8jRAxVgE5FQcRiPYOePQN3mo1R+cF KmY3Fw9Q6S5Y+Rdwa1QUaqljsLgaEi88TI9EGu/2gW5aV1dqB5Eyu9uV5wCg1AfC uIsPh/FtPxNKVhUWjbHk9RUEANi6IkwlhKBD11knjdtcBPS61vvYNYJhoPXVkurI TpCJ0gOo2U5JJVb+WeJLIYe78XrY5itcb5P6JIWV0iM8WQlIHxVx48VdSHjnHfSS kT6UNH10/maXGpnQx9JLkwi4lGjecLDDI2vvcFfB+qRbI2w623TpDyllQDBNPQEO 4L8rFACqbDXTM1OmbuANKcir7CNSu6TbJ4hR1ctlbPRyedkUdCZmTEczaGeGqhm8 +DK4TzHkU+HJznZE0JhgiVIcqGn9eSx+x5WlqmZ2dDJ62gDBUB+mdQzkVT67viDh XncWZee2UTmMCrKDrYwU/MSEF28j7INs4edK3HsDNkM/FEu3rf4NAwIAsY7pUEEc bWDRvzwrhYy6J/fTqnWqrfVKTJiVZ0MgrGpsVjyjNXLnth0lrlIdTAhFJIWNFjse +zSds7CkbAjst1HstEJKdFIgKHBhc3MgaXMgU0hBMS1DQU1FTExJQTI1Ni1vcGVu d2FsbCkgPFNIQTEtQ0FNRUxMSUEyNTZAZm9vLmJhcj6IYgQTEQIAIgUCUnQ9UgIb IwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQO6SEN2ooQmHxXgCdE2df3Exr Q3XvGw8zFzSg675j0wEAoJcaXReCOqQ69t4pIimVQdvfIW0unQFgBFJ0PVIQBADR 1Zykqay99zmIGM841/HuwZAboZz44UQS3q7LIoI1urrcrQvRcvtEI2D8cTv14jyg VFXchPwPKL7kjBukUds5cwdywrDkVGZVi7YHlFosQDveiP7uPPjaGB6oAiv6yFji qPxYIbi/hEbyFM1dU/Ak9Qwb5hAyDuLGrmNuBlT/YwADBgP/SH8zO55u+Nq2If/Q Dqga/sSH7nibEd+7mmrSWxapvY+YXEtQ4tGkaLwilU+p6TR0NUUijgBmx57Dd6Ap LyyJnfZ7znX8mgQV/ZVszwpXThNCh704pj/V0KwoNM0wB08n0Ix7FazjRmUF7E31 /n6cMSdLn/oXEIyDFT2eFi3DMNn+DQMCALGO6VBBHG1gDaBxogXngCDx56cYuH9t /ruz2w5yEYSF3wry+i2THfN38f3cvvBr3nw9rgNrrtXdyReICN432djz2ZpyyDOU sb2a98fjjYhJBBgRAgAJBQJSdD1SAhsMAAoJEDukhDdqKEJhsakAniEVBUtkoAK8 3gXMFIB7G8GeoREFAKDTRvQhNIBdaADNGGAsZOvBuQcQFw== ``` #2. Analysis ``` C // len=-458 encrypted_Secret_Key(int len, int sha1) { ... cp = last_hash; cp += sprintf(cp, "$gpg$*%d*%d*%d*", m_algorithm, len, key_bits); // cp += -458 * 2 cp += print_hex(m_data, len, cp); cp += sprintf(cp, "*%d*%d*%d*%d*%d*", m_spec, m_usage, m_hashAlgorithm, m_cipherAlgorithm, bs); cp += print_hex(iv, bs, cp); cp += sprintf(cp, "*%d*", m_count); cp += print_hex(m_salt, 8, cp); if (m_usage == 255) { /* handle 2 byte checksum */ cp += sprintf(cp, "*%d*", (key_bits + 7) / 8); cp += print_hex(p, (key_bits + 7) / 8, cp); cp += sprintf(cp, "*%d*", (q_bits + 7) / 8); cp += print_hex(q, (q_bits + 7) / 8, cp); cp += sprintf(cp, "*%d*", (g_bits + 7) / 8); cp += print_hex(g, (g_bits + 7) / 8, cp); cp += sprintf(cp, "*%d*", (y_bits + 7) / 8); cp += print_hex(y, (y_bits + 7) / 8, cp); } *cp = 0; ... } ``` The encrypted_Secret_Key() first parameter len **can not be negative**. #### So could here add a check for **len**?
bsakaguchi 2026-10-14 03:25:31 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@magnumripper commented on GitHub (May 14, 2015):

Yeah it seems that would be sensible.

<!-- gh-comment-id:102152277 --> @magnumripper commented on GitHub (May 14, 2015): Yeah it seems that would be sensible.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#830
No description provided.