buffer overflow in libsecure/get_default_type.c
In the slinux-200012181053-release.tgz distribution, the find_default_type function in libsecure/get_default_type.c attempts to extract a type field from the file /etc/security/default_type and copy it to a result buffer (specifically, to the argument "char **type"). Memory for this result buffer is allocated using malloc, but the argument to malloc is always one character too small.
For example, the role argument might typically be "sysadm_r" and the len argument would then be 8. With the initial installation, the first value of buf would be "sysadm_r:sysadm_t\n". There are no leading spaces, so i is 0. In the statement
(*type) = (char*) malloc (sizeof(char) * (strlen(buf)-i-len-1));
the argument to malloc is 18 - 0 - 8 - 1, which is 9. Then,
strcpy ((*type), &buf[i]+len+1);
attempts to copy the 10 characters "sysadm_t\n\0" into the 9-character buffer.
This patch should address the issue:
*** get_default_type.c.old Thu Nov 30 11:32:58 2000
--- get_default_type.c Tue Dec 26 00:19:04 2000
***************
*** 72,74 ****
/* malloc space for the type */
! (*type) = (char*) malloc (sizeof(char) * (strlen(buf)-i-len-1));
if ((*type) == NULL)
--- 72,74 ----
/* malloc space for the type */
! (*type) = (char*) malloc (sizeof(char) * (strlen(buf)-i-len));
if ((*type) == NULL)Matt Power
BindView Corporation, RAZOR Team
[email protected]
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Thanks for finding and fixing this bug. Our apologies for not catching it ourselves.
--
Stephen D. Smalley, NAI Labs
[email protected]
Quoted 35 lines · Matt Power
In the slinux-200012181053-release.tgz distribution, the
find_default_typefunction inlibsecure/get_default_type.cattempts to extract a type field from the file/etc/security/default_typeand copy it to a result buffer (specifically, to the argument "char **type"). Memory for this result buffer is allocated using malloc, but the argument to malloc is always one character too small.For example, the role argument might typically be "
sysadm_r" and the len argument would then be 8. With the initial installation, the first value of buf would be "sysadm_r:sysadm_t\n". There are no leading spaces, so i is 0. In the statement(*type) = (char*) malloc (sizeof(char) * (strlen(buf)-i-len-1));the argument to malloc is 18 - 0 - 8 - 1, which is 9. Then,
strcpy ((*type), &buf[i]+len+1);attempts to copy the 10 characters "sysadm_t\n\0" into the 9-character buffer.
This patch should address the issue:
*** get_default_type.c.old Thu Nov 30 11:32:58 2000
---get_default_type.cTue Dec 26 00:19:04 2000
***************
*** 72,74 ****/* malloc space for the type */ ! (*type) = (char*) malloc (sizeof(char) * (strlen(buf)-i-len-1)); if ((*type) == NULL) --- 72,74 ---- /* malloc space for the type */ ! (*type) = (char*) malloc (sizeof(char) * (strlen(buf)-i-len)); if ((*type) == NULL)
Quoted 9 lines
Matt Power
BindView Corporation, RAZOR Team
[email protected]You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.