Fix out-of-bounds reading in sctp_asoc_get_hmac()
Subsystems (3)
PATCH 1/1 Fix out-of-bounds reading in sctp_asoc_get_hmac()
The sctp_asoc_get_hmac() function iterates through a peer's hmac_ids array and attempts to ensure that only a supported hmac entry is returned. The current code fails to do this properly - if the last id in the array is out of range (greater than SCTP_AUTH_HMAC_ID_MAX), the id integer remains set after exiting the loop, and the address of an out-of-bounds entry will be returned and subsequently used in the parent function, causing potentially ugly memory corruption. This patch resets the id integer to 0 on encountering an invalid id so that NULL will be returned after finishing the loop if no valid ids are found.
net/sctp/auth.c +6 -2
@@ -543,16 +543,20 @@ struct sctp_hmac *sctp_auth_asoc_get_hma id =ntohs (hmacs->hmac_ids[i]);/* Check the id is in the supported range */ -if (id >SCTP_AUTH_HMAC_ID_MAX ) +if (id >SCTP_AUTH_HMAC_ID_MAX ) { + id =0 ;continue ; + }/* See is we support the id. Supported IDs have name and * length fields set, so that we can allocated and use * them. We can safely just check for name, for without the * name, we can't allocate the TFM. */ -if (!sctp_hmac_list[id].hmac_name) +if (!sctp_hmac_list[id].hmac_name) { + id =0 ;continue ; + }break ; }
Quoted 11 lines · Dan Rosenberg
The
sctp_asoc_get_hmac()function iterates through a peer'shmac_idsarray and attempts to ensure that only a supported hmac entry is returned. The current code fails to do this properly - if the last id in the array is out of range (greater thanSCTP_AUTH_HMAC_ID_MAX), the id integer remains set after exiting the loop, and the address of an out-of-bounds entry will be returned and subsequently used in the parent function, causing potentially ugly memory corruption. This patch resets the id integer to 0 on encountering an invalid id so that NULL will be returned after finishing the loop if no valid ids are found.Signed-off-by Dan Rosenberg<[email protected]>
Good catch.
-vlad
Quoted 28 lines
net/sctp/auth.c +6
-2@@ -543,16 +543,20 @@ struct sctp_hmac *sctp_auth_asoc_get_hma id =ntohs (hmacs->hmac_ids[i]);/* Check the id is in the supported range */ -if (id>SCTP_AUTH_HMAC_ID_MAX ) +if (id>SCTP_AUTH_HMAC_ID_MAX ) { + id =0 ;continue ; + }/* See is we support the id. Supported IDs have name and * length fields set, so that we can allocated and use * them. We can safely just check for name, for without the * name, we can't allocate the TFM. */ -if (!sctp_hmac_list[id].hmac_name) +if (!sctp_hmac_list[id].hmac_name) { + id =0 ;continue ; + }break ; }
From: Vlad Yasevich <[email protected]>
Date: Fri, 01 Oct 2010 18:13:34 -0400
Quoted 13 lines · Dan Rosenberg
Quoted 12 lines
The
sctp_asoc_get_hmac()function iterates through a peer'shmac_idsarray and attempts to ensure that only a supported hmac entry is returned. The current code fails to do this properly - if the last id in the array is out of range (greater thanSCTP_AUTH_HMAC_ID_MAX), the id integer remains set after exiting the loop, and the address of an out-of-bounds entry will be returned and subsequently used in the parent
function, causing potentially ugly memory corruption. This patch resets
the id integer to 0 on encountering an invalid id so that NULL will be returned after finishing the loop if no valid ids are found.
Quoted 5 lines
Quoted 1 line
Signed-off-by Dan Rosenberg<[email protected]>Good catch.
Acked-by Vlad Yasevich <[email protected]>
Applied.