🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #20386

Re: Fix for core dumps in INN-1.6b3 (innd/art.c)

#20386
From: Forrest J. Cavalier III
Date: Mon, 11 Aug 1997 00:00
153 lines
7253 bytes
In article <5smo7a$lkp$1@zeus.fw.cuci.nl>, srb@zeus.fw.cuci.nl wrote...
>
>J. Porter Clark <jpc@drum.msfc.nasa.gov> wrote:
>>As Forrest Cavalier has noted here and elsewhere, there is a bug in INN
>>1.6b3's innd/art.c that may cause innd to dump core as the indirect
>>result of receiving a control message without a Control header.  The
>>fix is below.  Basically, it reverts to the 1.5.1 code, which turns out
>>to have been correct and safe after all.
>
>>*** innd/art.c.orig    Thu Jul 31 15:08:57 1997
>>--- innd/art.c Fri Aug  8 20:51:20 1997
>>               p++;
>>!          if (*p)
>>               (void)strcpy(in, p);                            /* safe -of */
>
>You mean, there is never any danger in overflowing the available bufferspace
>here?
>
>And even if that is true, then I wonder why the original code (with the >= fix)
>is causing problems at all (it shouldn't be triggered then at all).

....All the gory details, from my post to inn-workers.

BTW, J. Porter Clark is being a bit modest.  He replied to my
message saying that he had it all figured out that morning, but
was unable to respond because of his schedule that day.  When
he returned in the evening, it turns out that I had posted
independently.  But it was important that he confirmed my thinking
on the subject.  I'm glad he responded.

Here it is....


From:             "Forrest J. Cavalier III" <mibsoft@epix.net>
To:               "J. Porter Clark" <jpc@drum.msfc.nasa.gov>, inn-bugs@isc.org,
        inn-workers@vix.com
Date sent:        Fri, 8 Aug 1997 12:21:02 -0400
Subject:          Something rotten in art.c-- Revisited
Send reply to:    mibsoft@epix.net
Copies to:        inn-workers@vix.com
Priority:         normal

And when you thought it was over.....

I was looking at this section of code again.  And I think
there are still some major problems with it.  Here is what
I think, does anyone agree?

To refresh your memories....

This code is handling the case when there is no control header, but
the Subject header starts with "cmsg".  The action taken is to copy
the tail part of the subject line into the buffer holding the 
contents of the control field.  A test ensures the destination is 
large enough.  The error reported by jpc is that strcpy() actually
needs strlen(p)+1 bytes.

As it appears in 1.6b3, and 1.5.1sec2/innd/art.c  ARTclean()

    /* If there is no control header, see if the article starts with
     * "cmsg ". */
    in = HDR(_control);
    if (*in == '\0') {
       p = HDR(_subject);
       if (*p == 'c' && EQn(p, "cmsg ", 5)) {
         for (p += 5; *p && ISWHITE(*p); )
           p++;
         if (*p) {
           if (strlen(p) > ARTheaders[_control].Length) {
              ARTheaders[_control].Length = strlen(p) + 1;
              ARTheaders[_control].Value =
              RENEW(ARTheaders[_control].Value,
                 char, ARTheaders[_control].Length);
              in = HDR(_control);
           }
           (void)strcpy(in, p);
        }
   ...

And in 1.5.1, there is simply a strcpy(), without the test
and conditional RENEW().

After inspecting every single strcpy ->strncpy, and sprintf->snprintf code
change, and finding most of them to be unnecessary (Rich Salz had it right)
I got to thinking about this some more: Why did the code NOT fail in 1.5.1?

The answer is that p points into HDR(_subject) which is a buffer of MAXHEADERSIZE,
and HDR(_control), (a.k.a. ARTheaders[_control].Value) is a buffer of MAXHEADERSIZE.
The code to prevent strings longer than MAXHEADERSIZE appears in ARTparseheader().

And you look in ARTparseheader() and find that it makes assumptions that ARTheaders[].Value
points to MAXHEADERSIZE bytes! So
               RENEW(ARTheaders[_control].Value,
                 char, ARTheaders[_control].Length);
is a VERY BAD thing to do, since the next time ARTparseheader() tries to store something
bigger, it isn't going to RENEW().

Philosophically, I think ARTheaders[_control].Length is invalid at that point anyway:
it is the Length of the previous message's header, which is gone.  Using it at
all is not right.  (ARTclean(), which does article processing, sets *(hp->Value) = '\0'
and does not initialize .Length)


If that isn't bad enough....
ARTheaders[].Length is supposed to be the length of the string at ARTheaders[].Value.
So the 1.6b3/1.5.1sec2 code which sets:
              ARTheaders[_control].Length = strlen(p) + 1;
is wrong, I think.  Compare to the code in ARTparseheader() which does:
             (void)memcpy((POINTER)hp->Value, (POINTER)p, (SIZE_T)i);
              hp->Value[i] = '\0';

I think setting .Length high by 1, is going to send out the null terminator.
-----------------------------------------------------------------------------
Back to the first problem:
 Why didn't jpc find the problem of RENEW() with less than MAXHEADERSIZE?

I'm not sure he was looking for it.  I think the sequence which causes
failure would have to be this:
    A message with Control: with a .Value of X bytes.
    A later message with "Subject: cmsg", with the part after the cmsg of Y bytes,
      where Y is greater than X.  This triggers the RENEW()
    A later message with "Control: ", with the .Value of Z bytes,
      where Z is greater than Y.  This causes ARTparseheaders() to store Z bytes
      at the place of the previous RENEW()
    
Whereas jpc was probably testing this sequence:
    A message with Control: with a .Value of X bytes.
    A later message with "Subject: cmsg", with the part after the cmsg of Y bytes,
      where Y is greater than X.  This triggers the RENEW()
    Another later message with "Subject: cmsg ", with the .Value of Z bytes,
      where Z is greater than Y.  This causes ARTparseheaders() to store Z bytes
      at the place of the previous RENEW()

IOW, jpc was testing with cmsg messages WITHOUT a control header, but the bug
needs a Control: header BIGGER than the last cmsg subject to trigger it.

Fortunately, most Control messages HAVE both a Subject: and a Control: header, so
the RENEW is not ever triggered.  If I am right about it, this would be a simple
one-two punch DoS attack -- just delay the second message by an hour or so.

I vote for going back to the 1.5.1 code in this section: do the strcpy() which
was completely safe.  RENEW() on any ARTheaders[] is bad.


Forrest Cavalier, Mib Software, INN customization and consulting.

BTW, All my work on inn-1.5.1corr is available to the ISC.  Just pay for my time, and you 
can do with it what you wish.



Technical Details
Message-ID: <5smr88$9ai$1@news1.epix.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <5slt04$c65$1@hammer.msfc.nasa.gov> <5smo7a$lkp$1@zeus.fw.cuci.nl>

Show Full Headers
Complete Article Headers
Message-ID: <5smr88$9ai$1@news1.epix.net>
Subject: Re: Fix for core dumps in INN-1.6b3 (innd/art.c)
Date: Mon, 11 Aug 1997 00:00:00 +0000
From: mibsoft@epix.net (Forrest J. Cavalier III)
References: <5slt04$c65$1@hammer.msfc.nasa.gov> <5smo7a$lkp$1@zeus.fw.cuci.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 263516324
Organization: Mib Software
Newsgroups: news.software.nntp