CVE-2024-42132 - Release of Invalid Pointer or Reference

Severity

71%

Complexity

18%

Confidentiality

86%

In the Linux kernel, the following vulnerability has been resolved: bluetooth/hci: disallow setting handle bigger than HCI_CONN_HANDLE_MAX Syzbot hit warning in hci_conn_del() caused by freeing handle that was not allocated using ida allocator. This is caused by handle bigger than HCI_CONN_HANDLE_MAX passed by hci_le_big_sync_established_evt(), which makes code think it's unset connection. Add same check for handle upper bound as in hci_conn_set_handle() to prevent warning.

CVSS 3.1 Base Score 7.1. CVSS Attack Vector: local. CVSS Attack Complexity: low. CVSS Vector: (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H).

Demo Examples

Release of Invalid Pointer or Reference

CWE-763

This code attempts to tokenize a string and place it into an array using the strsep function, which inserts a \0 byte in place of whitespace or a tab character. After finishing the loop, each string in the AP array points to a location within the input string.


               
free(ap[4]);
break;

Since strsep is not allocating any new memory, freeing an element in the middle of the array is equivalent to free a pointer in the middle of inputstring.

Release of Invalid Pointer or Reference

CWE-763

This example allocates a BarObj object using the new operator in C++, however, the programmer then deallocates the object using free(), which may lead to unexpected behavior.


               
}
free(ptr);/* do some work with ptr here */

Instead, the programmer should have either created the object with one of the malloc family functions, or else deleted the object with the delete operator.


               
}
delete ptr;/* do some work with ptr here */

Release of Invalid Pointer or Reference

CWE-763

In this example, the programmer dynamically allocates a buffer to hold a string and then searches for a specific character. After completing the search, the programmer attempts to release the allocated memory and return SUCCESS or FAILURE to the caller. Note: for simplification, this example uses a hard-coded "Search Me!" string and a constant string length of 20.


               
}
return FAILURE;
str = str + 1;
return SUCCESS;/* matched char, free string and return success */
/* didn't match yet, increment pointer and try next char */
/* we did not match the char in the string, free mem and return failure */

However, if the character is not at the beginning of the string, or if it is not in the string at all, then the pointer will not be at the start of the buffer when the programmer frees it.

Instead of freeing the pointer in the middle of the buffer, the programmer can use an indexing pointer to step through the memory or abstract the memory calculations by using array indexing.


               
}
return FAILURE;
i = i + 1;
return SUCCESS;/* matched char, free string and return success */
/* didn't match yet, increment pointer and try next char */
/* we did not match the char in the string, free mem and return failure */

Release of Invalid Pointer or Reference

CWE-763

Consider the following code in the context of a parsing application to extract commands out of user data. The intent is to parse each command and add it to a queue of commands to be executed, discarding each malformed entry.


               
}//hardcode input length for simplicity/* The following loop will parse and process each token in the input string */
tok = strtok( NULL, sep));
free( tok );/* ignore and discard bad data */
add_to_command_queue( tok );

While the above code attempts to free memory associated with bad commands, since the memory was all allocated in one chunk, it must all be freed together.

One way to fix this problem would be to copy the commands into a new memory location before placing them in the queue. Then, after all commands have been processed, the memory can safely be freed.


               
free( input )//hardcode input length for simplicity/* The following loop will parse and process each token in the input string */
tok = strtok( NULL, sep));
add_to_command_queue( command );/* copy and enqueue good data */

Stay updated

ExploitPedia is constantly evolving. Sign up to receive a notification when we release additional functionality.

Get in touch

If you'd like to report a bug or have any suggestions for improvements then please do get in touch with us using this form. We will get back to you as soon as we can.