Likely write beyond bounds in sctp_load_addresses_from_init()
The function sctp_load_addresses_from_init() calculates a key length assuming an SCTP_RANDOM parameter is present, but if that parameter is missing, the length is not reset before copying other parameters, leading to out-of-bounds writes. An attacker sending a crafted SCTP INIT packet without a RANDOM parameter could cause memory corruption.
Originally disclosed on Mozilla
- Fixed in 52 days
- Paid in 56 days
- Disclosed after 52 days
sctp_load_addresses_from_init() (netwerk\sctp\src\netinet\sctp_pcb.c) is likely to write beyond bounds if the INIT argument it parses does not include an |SCTP_RANDOM| parameter. The argument comes from a (presumably untrusted) network source.
The bug is in the calculation of |keylen|. Lines 7740-44 calculate |keylen| and allocate |sizeof (sctp_key_t) + keylen| bytes. But if there is no |SCTP_RANDOM| parameter in the INIT, control skips lines 7562-82, and |p_random| is NULL (its initial value, set by line 7120) when control reaches line 7739:
7100: int
7101: sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
7102: int offset, int limit,
7103: struct sockaddr *src, struct sockaddr *dst,
7104: struct sockaddr *altsa, uint16_t port)
7105: {
7106: /*
7107: * grub through the INIT pulling addresses and loading them to the
7108: * nets structure in the asoc. The from address in the mbuf should
7109: * also be loaded (if it is not already). This routine can be called
7110: * with either INIT or INIT-ACK's as long as the m points to the IP
7111: * packet and the offset points to the beginning of the parameters.
7112: */
...
7120: struct sctp_auth_random *p_random = NULL;
7121: uint16_t random_len = 0;
...
7131: uint32_t keylen;
7132: int got_random = 0, got_hmacs = 0, got_chklist = 0;
...
7237: /* now we must go through each of the params. */
7238: phdr = sctp_get_next_param(m, offset, ¶m_buf, sizeof(param_buf));
7239: while (phdr) {
7240: ptype = ntohs(phdr->param_type);
7241: plen = ntohs(phdr->param_length);
...
7562: } else if (ptype == SCTP_RANDOM) {
7563: if (plen > sizeof(random_store))
7564: break;
7565: if (got_random) {
7566: /* already processed a RANDOM */
7567: goto next_param;
7568: }
7569: phdr = sctp_get_next_param(m, offset,
7570: (struct sctp_paramhdr *)random_store,
7571: plen);
7572: if (phdr == NULL)
7573: return (-26);
7574: p_random = (struct sctp_auth_random *)phdr;
7575: random_len = plen - sizeof(*p_random);
7576: /* enforce the random length */
7577: if (random_len != SCTP_AUTH_RANDOM_SIZE_REQUIRED) {
7578: SCTPDBG(SCTP_DEBUG_AUTH1, "SCTP: invalid RANDOM len\n");
7579: return (-27);
7580: }
7581: got_random = 1;
7582: } ...
...
7668: next_param:
7669: offset += SCTP_SIZE32(plen);
7670: if (offset >= limit) {
7671: break;
7672: }
7673: phdr = sctp_get_next_param(m, offset, ¶m_buf,
7674: sizeof(param_buf));
7675: }
...
...This, in turn, means that line 7748...
7739: /* concatenate the full random key */
7740: keylen = sizeof(*p_random) + random_len + sizeof(*hmacs) + hmacs_len;
7741: if (chunks != NULL) {
7742: keylen += sizeof(*chunks) + num_chunks;
7743: }
7744: new_key = sctp_alloc_key(keylen);
7745: if (new_key != NULL) {
7746: /* copy in the RANDOM */
7747: if (p_random != NULL) {
...which resets |keylen| to properly index into |new_key->key|, will not be executed...
7748: keylen = sizeof(*p_random) + random_len;
7749: memcpy(new_key->key, p_random, keylen);
7750: }
And that means that lines 7752-61 use the old value of |keylen| for addressing the destinations of the memcpy()s on lines 7753-54 and 7759-60. But this value is actually the length, in bytes, of |new_key->key|, so both memcpy()s will write beyond bounds:
7751: /* append in the AUTH chunks */
7752: if (chunks != NULL) {
7753: memcpy(new_key->key + keylen, chunks,
7754: sizeof(*chunks) + num_chunks);
7755: keylen += sizeof(*chunks) + num_chunks;
7756: }
7757: /* append in the HMACs */
7758: if (hmacs != NULL) {
7759: memcpy(new_key->key + keylen, hmacs,
7760: sizeof(*hmacs) + hmacs_len);
7761: }
7762: } else {
7763: /* failed to get memory for the key */
7764: return (-34);
7765: }
...
7772: return (0);
7773: }
Nothing in the function prevents control from reaching lines 7740 et seq if a |SCTP_RANDOM| parameter is not present.
I'll try to produce a POC.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the key length variable is not reset when the SCTP_RANDOM parameter is absent, so subsequent memcpy operations use an incorrect offset.
What the attacker needed
Send crafted SCTP INIT packet; no SCTP_RANDOM parameter
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a bug in code that handles network packets for a protocol called SCTP. When a packet arrives without a certain expected piece of data, the code still uses a size value that was meant for that missing data, so it writes past the end of a buffer. An attacker could send a specially crafted packet to corrupt memory.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.