Thread View: news.software.nntp
2 messages
2 total messages
Started by Yar Tikhiy
Fri, 25 Jul 1997 00:00
INN 1.5.1: Strcpy() considered harmful?
Author: Yar Tikhiy
Date: Fri, 25 Jul 1997 00:00
Date: Fri, 25 Jul 1997 00:00
171 lines
5964 bytes
5964 bytes
Hello everybody,
The following text is just my humble opinion and I'd appreciate
any corrections, comments and criticisms.
As I've got sick of my uncertainty about the security holes
I greped INN 1.5.1 sources for "strcpy" and "sprintf.*%s"
(as I do not remember INN sources by heart yet) and then RTFS.
Let strcpy() or sprintf() be considered harmful if and only if
it gets _unpredictable_ (unrestricted by other code, in another
words) data supplied by a user. I've managed to find such harmful
calls only in nnrpd/post.c (innlib seems not to have suspicious calls
at all and innd has a protection against artifically oversized strings
by means of MaxLength() call). The calls fall into 2 groups:
a) Calls of "sprintf(Error,...)" group. They are not
actually harmful in spite of the above definition :) as "Error" is
a static variable and nnrpd bails out very soon after the variable
is set, so it's quite hard to make an exploit of its overflow.
However, I'd feel myself more comfortably if the overflows did not
take place at all, so the harmful calls are in lines 217, 241, 604,
620 and 627 of nnrpd/post.c. Other sprintf(Error,...) calls does not
seem harmful as theis arguments' maximum size can be predicted and
will not exceed SMBUF.
b) strcpy() calls. There is a really nasty one noticed by
everybody (line 801):
strcpy(frombuf, HDR(_from));
and another (line 911) that looks nasty, but IMHO is actually
unexploitable:
(void)strcpy(idbuff, HDR(_messageid));
as the strcpy() take place only if the post was successful, and
innd has it's own Message-ID check that restricts its length to
DBZMAXKEY bytes (255). As the 'idbuff' is SMBUF bytes long (256
by default), either article's Message-ID will fit into 'idbuff'
or the article will be rejected by innd. However, the piece of
nnrpd is harmful by the definition :)
So, that's the patch.
*** post.c.orig Tue Dec 17 17:40:40 1996
--- post.c Fri Jul 25 21:27:27 1997
***************
*** 214,220 ****
/* SUPPRESS 530 *//* Empty body for statement */
;
else {
! (void)sprintf(Error, "\"%s\" is not a valid control message",
ctrl);
return Error;
}
--- 214,220 ----
/* SUPPRESS 530 *//* Empty body for statement */
;
else {
! (void)snprintf(Error, sizeof(Error), "\"%s\" is not a valid control message",
ctrl);
return Error;
}
***************
*** 238,244 ****
do {
for (dp = BadDistribs; *dp; dp++)
if (wildmat(p, *dp)) {
! (void)sprintf(Error, "Illegal distribution \"%s\"", p);
return Error;
}
} while ((p = strtok((char *)NULL, SEPS)) != NULL);
--- 238,244 ----
do {
for (dp = BadDistribs; *dp; dp++)
if (wildmat(p, *dp)) {
! (void)snprintf(Error, sizeof(Error), "Illegal distribution \"%s\"", p);
return Error;
}
} while ((p = strtok((char *)NULL, SEPS)) != NULL);
***************
*** 601,607 ****
break;
case NF_FLAG_IGNORE:
case NF_FLAG_NOLOCAL:
! (void)sprintf(Error, "Postings to \"%s\" are not allowed here.",
gp->Name);
break;
case NF_FLAG_EXCLUDED:
--- 601,607 ----
break;
case NF_FLAG_IGNORE:
case NF_FLAG_NOLOCAL:
! (void)snprintf(Error, sizeof(Error), "Postings to \"%s\" are not allowed here.",
gp->Name);
break;
case NF_FLAG_EXCLUDED:
***************
*** 617,630 ****
grplist[0] = p;
grplist[1] = NULL;
if (!PERMmatch(PERMdefault, PERMlist, grplist)) {
! sprintf(Error,"%s: %s\r\n", NNTP_NOSUCHGROUP,p);
}
}
} while ((p = strtok((char *)NULL, NGSEPS)) != NULL);
DISPOSE(groups);
if (!FoundOne && !IsNewgroup)
! (void)sprintf(Error, "No valid newsgroups in \"%s\"", hdr);
if (Error[0]) {
DISPOSE(DDend(h));
return Error;
--- 617,630 ----
grplist[0] = p;
grplist[1] = NULL;
if (!PERMmatch(PERMdefault, PERMlist, grplist)) {
! snprintf(Error,sizeof(Error),"%s: %s\r\n", NNTP_NOSUCHGROUP,p);
}
}
} while ((p = strtok((char *)NULL, NGSEPS)) != NULL);
DISPOSE(groups);
if (!FoundOne && !IsNewgroup)
! (void)snprintf(Error, sizeof(Error), "No valid newsgroups in \"%s\"", hdr);
if (Error[0]) {
DISPOSE(DDend(h));
return Error;
***************
*** 798,804 ****
if (idbuff != NULL)
idbuff [0] = '\0' ;
! strcpy(frombuf, HDR(_from));
HeaderCleanFrom(frombuf);
p = strchr(frombuf, '@');
if (p) {
--- 798,805 ----
if (idbuff != NULL)
idbuff [0] = '\0' ;
! strncpy(frombuf, HDR(_from), sizeof(frombuf)-1);
! frombuf[sizeof(frombuf)-1]='\0';
HeaderCleanFrom(frombuf);
p = strchr(frombuf, '@');
if (p) {
***************
*** 908,913 ****
/* Send a quit and close down */
SendQuit(FromServer, ToServer);
if (idbuff)
! (void)strcpy(idbuff, HDR(_messageid));
return NULL;
}
--- 909,922 ----
/* Send a quit and close down */
SendQuit(FromServer, ToServer);
if (idbuff)
! {
! /*
! * XXX A lame hack:
! * the knowledge about idbuff size is external to the current
! * function. However, the function is called only once.
! */
! (void)strncpy(idbuff, HDR(_messageid), SMBUF-1);
! idbuff[SMBUF-1]='\0';
! }
return NULL;
}
SY, Yar
Re: INN 1.5.1: Strcpy() considered harmful?
Author: Miquel van Smoorenburg
Date: Fri, 25 Jul 1997 00:00
Date: Fri, 25 Jul 1997 00:00
51 lines
2163 bytes
2163 bytes
In article <5rap3k$6ac$1@comp.chem.msu.su>,
Yar Tikhiy <yar@comp.chem.msu.su> wrote:
>Hello everybody,
>
>The following text is just my humble opinion and I'd appreciate
>any corrections, comments and criticisms.
>
>As I've got sick of my uncertainty about the security holes
>I greped INN 1.5.1 sources for "strcpy" and "sprintf.*%s"
>(as I do not remember INN sources by heart yet) and then RTFS.
I did the same, but patched almost all of INN. Please check out my results at
http://miquels.www.cistron.nl/inn/
However I see one case in your patch that I overlooked (not sure if it
is a serious one) :
>***************
>*** 908,913 ****
> /* Send a quit and close down */
> SendQuit(FromServer, ToServer);
> if (idbuff)
>! (void)strcpy(idbuff, HDR(_messageid));
> return NULL;
> }
>--- 909,922 ----
> /* Send a quit and close down */
> SendQuit(FromServer, ToServer);
> if (idbuff)
>! {
>! /*
>! * XXX A lame hack:
>! * the knowledge about idbuff size is external to the current
>! * function. However, the function is called only once.
>! */
>! (void)strncpy(idbuff, HDR(_messageid), SMBUF-1);
>! idbuff[SMBUF-1]='\0';
>! }
> return NULL;
> }
I'll add this to my patch now. Thanks.
Mike.
--
| Miquel van Smoorenburg | |
| miquels@cistron.nl | RAM DISK is NOT an installation procedure!!! |
| PGP fingerprint: FE 66 52 4F CD 59 A5 36 7F 39 8B 20 F1 D6 74 02 |
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads